Skip to content

Commit 74e07b4

Browse files
authored
Merge pull request #406 from ytkg/patch-4
refactor: 早期リターンするようにした
2 parents 445ca3b + 4d5946c commit 74e07b4

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

pages/kusa/[user].tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@ export const getServerSideProps = async (
1616
): Promise<GetServerSidePropsResult<Props>> => {
1717
const user = context.params?.user;
1818

19-
if (typeof user === 'string') {
20-
const res = await fetch(`https://github-contributions-api.deno.dev/${user}.json`);
21-
const json = await res.json();
19+
if (typeof user !== 'string') {
20+
return { notFound: true };
21+
}
2222

23-
const contributions = json.contributions
24-
.flat()
25-
.reverse()
26-
.map((c: { contributionCount: number }) => c.contributionCount);
23+
const res = await fetch(`https://github-contributions-api.deno.dev/${user}.json`);
24+
const json = await res.json();
2725

28-
const [todayContributionCount, yesterdayContributionCount] = contributions;
29-
const currentStreak = todayContributionCount > 0 ? contributions.indexOf(0) : contributions.slice(1).indexOf(0);
26+
const contributions = json.contributions
27+
.flat()
28+
.reverse()
29+
.map((c: { contributionCount: number }) => c.contributionCount);
3030

31-
return {
32-
props: { user, todayContributionCount, yesterdayContributionCount, currentStreak },
33-
};
34-
} else {
35-
return {
36-
notFound: true,
37-
};
38-
}
31+
const [todayContributionCount, yesterdayContributionCount] = contributions;
32+
const currentStreak = todayContributionCount > 0 ? contributions.indexOf(0) : contributions.slice(1).indexOf(0);
33+
34+
return { props: { user, todayContributionCount, yesterdayContributionCount, currentStreak } };
3935
};
4036

4137
const fetchFunc = async (userId: string) => {

0 commit comments

Comments
 (0)