diff --git a/app/favicon.ico b/app/favicon.ico index 718d6fe..73ef88d 100644 Binary files a/app/favicon.ico and b/app/favicon.ico differ diff --git a/app/page.tsx b/app/page.tsx index d7a8f68..40b1583 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -11,8 +11,6 @@ export default async function Home() { const session = await auth(); if (!session?.user) return null; - console.log(session); - return (
@@ -49,6 +47,7 @@ export default async function Home() { width={20} height={20} className="dark:hidden" + priority /> 振り返りを見る @@ -69,6 +69,7 @@ export default async function Home() { width={700} height={800} className="w-full h-auto mx-auto rounded-md" + priority />
diff --git a/app/recap/components/calculate-change-rate.ts b/app/recap/components/calculate-change-rate.ts new file mode 100644 index 0000000..8abd8a0 --- /dev/null +++ b/app/recap/components/calculate-change-rate.ts @@ -0,0 +1,28 @@ +/** + * 去年の数値(prevYear) と 今年の数値(currentYear)を引数に取り、 + * 数値(小数第2位まで) か "-" を返す関数 + * + * @param {number} prevYear - 去年のコミット数や指標となる数値 + * @param {number} currentYear - 今年のコミット数や指標となる数値 + * @returns {number|"-"} - 有効な場合は数値型、無効の場合は "-" + */ +export function calculateChangeRate( + prevYear: number, + currentYear: number, +): number | "-" { + if (typeof prevYear !== "number" || typeof currentYear !== "number") { + return "-"; + } + + if (prevYear === 0) { + return "-"; + } + + const ratio = ((currentYear - prevYear) / prevYear) * 100; + + if (!Number.isFinite(ratio)) { + return "-"; + } + + return Number.parseFloat(ratio.toFixed(2)); +} diff --git a/app/recap/components/overview.tsx b/app/recap/components/overview.tsx index 6d8cc70..03f48e4 100644 --- a/app/recap/components/overview.tsx +++ b/app/recap/components/overview.tsx @@ -18,6 +18,7 @@ import { UsersRound, } from "lucide-react"; import type { FC } from "react"; +import { calculateChangeRate } from "./calculate-change-rate"; import { LanguagesUsageGraph } from "./graph/languages"; import { MonthlyContributionsGraph } from "./graph/monthly"; import { WeeklyContributionsGraph } from "./graph/weekly"; @@ -98,12 +99,10 @@ export const OverView: FC = async ({ data }) => {

前年と比較して - {( - ((data.totalCommitCount - - data.previousYearStats.totalCommitCount) / - data.previousYearStats.totalCommitCount) * - 100 - ).toFixed(2)} + {calculateChangeRate( + data.previousYearStats.totalCommitCount, + data.totalCommitCount, + )} % 増加しました。

@@ -123,12 +122,10 @@ export const OverView: FC = async ({ data }) => {

前年と比較して - {( - ((data.closedIssuesAssigned - - data.previousYearStats.closedIssuesAssignedCount) / - data.previousYearStats.closedIssuesAssignedCount) * - 100 - ).toFixed(2)} + {calculateChangeRate( + data.previousYearStats.closedIssuesAssignedCount, + data.closedIssuesAssigned, + )} % 増加しました。

@@ -148,12 +145,10 @@ export const OverView: FC = async ({ data }) => {

前年と比較して - {( - ((data.openedPullRequests - - data.previousYearStats.openedPullRequests) / - data.previousYearStats.openedPullRequests) * - 100 - ).toFixed(2)} + {calculateChangeRate( + data.previousYearStats.openedPullRequests, + data.openedPullRequests, + )} % 増加しました。

@@ -173,12 +168,10 @@ export const OverView: FC = async ({ data }) => {

前年と比較して - {( - ((data.reviewedPullRequests - - data.previousYearStats.reviewedPullRequests) / - data.previousYearStats.reviewedPullRequests) * - 100 - ).toFixed(2)} + {calculateChangeRate( + data.previousYearStats.reviewedPullRequests, + data.reviewedPullRequests, + )} % 増加しました。

diff --git a/lib/auth.ts b/lib/auth.ts index 8e76153..305d4c8 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -7,7 +7,7 @@ export const { handlers, auth, signIn, signOut } = NextAuth({ GitHub({ authorization: { param: { - scope: "repo read:user", + scope: "repo", }, }, }),