diff --git a/pages/kusa/[username].tsx b/pages/kusa/[username].tsx index 22123f0b..366d33a2 100644 --- a/pages/kusa/[username].tsx +++ b/pages/kusa/[username].tsx @@ -1,14 +1,14 @@ -import Head from 'next/head'; import { GetServerSidePropsContext, GetServerSidePropsResult } from 'next'; import { FetchProvider, useFetch } from 'react-hooks-fetch'; import { Suspense } from 'react'; +import Head from '../../src/components/kusa/head'; +import Title from '../../src/components/kusa/title'; import Contributions from '../../src/components/kusa/contributions/contributions'; +import { toGrassGraphImageUrl } from '../../src/lib/to-grass-graph-image-url'; type Props = { username: string; - todayContributionCount: number; - yesterdayContributionCount: number; - currentStreak: number; + description: string; }; export const getServerSideProps = async ( @@ -30,8 +30,9 @@ export const getServerSideProps = async ( const [todayContributionCount, yesterdayContributionCount] = contributions; const currentStreak = todayContributionCount > 0 ? contributions.indexOf(0) : contributions.slice(1).indexOf(0); + const description = `Today: ${todayContributionCount}, Yesterday: ${yesterdayContributionCount}, Streak: ${currentStreak}`; - return { props: { username, todayContributionCount, yesterdayContributionCount, currentStreak } }; + return { props: { username, description } }; }; const fetchFunc = async (username: string) => { @@ -49,37 +50,15 @@ const Detail = ({ username }: { username: string }) => { const Kusa = (props: Props) => { const username = props.username; - const imgUrl = `https://grass-graph.appspot.com/images/${username}.png?${Date.now()}`; - const siteUrl = `https://tools.swfz.io/kusa/${username}`; - const title = `GitHub Contributions(kusa) in ${username}`; - const desc = `Today: ${props.todayContributionCount}, Yesterday: ${props.yesterdayContributionCount}, Streak: ${props.currentStreak}`; - const toGitHub = `https://github.com/${username}`; return ( <> - - Kusa - - - - - - - - - - - +
- - - {username} - - 's kusa - + - <img src={imgUrl} alt="GitHub Contribution" /> - <span>{desc}</span> + <img src={toGrassGraphImageUrl(username)} alt="GitHub Contribution" /> + <span>{props.description}</span> {/* @ts-ignore */} <FetchProvider initialInputs={[[fetchFunc, username]]}> <Suspense fallback={<span>Loading...</span>}> diff --git a/src/components/kusa/head.tsx b/src/components/kusa/head.tsx new file mode 100644 index 00000000..e9be80a9 --- /dev/null +++ b/src/components/kusa/head.tsx @@ -0,0 +1,26 @@ +import NextHead from 'next/head'; +import { toGrassGraphImageUrl } from '../../lib/to-grass-graph-image-url'; + +const Head = ({ username, description }: { username: string; description: string }) => { + const imageUrl = toGrassGraphImageUrl(username); + const siteUrl = `https://tools.swfz.io/kusa/${username}`; + const title = `GitHub Contributions(kusa) in ${username}`; + + return ( + <NextHead> + <title>Kusa + + + + + + + + + + + + ); +}; + +export default Head; diff --git a/src/components/kusa/title.tsx b/src/components/kusa/title.tsx new file mode 100644 index 00000000..70c78785 --- /dev/null +++ b/src/components/kusa/title.tsx @@ -0,0 +1,18 @@ +type Props = { + username: string; +}; + +const Title = ({ username }: Props) => { + const toGitHub = `https://github.com/${username}`; + + return ( + + + {username} + + 's kusa + + ); +}; + +export default Title; diff --git a/src/lib/__tests__/to-grass-graph-image-url.spec.tsx b/src/lib/__tests__/to-grass-graph-image-url.spec.tsx new file mode 100644 index 00000000..b7f50013 --- /dev/null +++ b/src/lib/__tests__/to-grass-graph-image-url.spec.tsx @@ -0,0 +1,7 @@ +import { toGrassGraphImageUrl } from '../to-grass-graph-image-url'; + +describe('toGrassGraphImageUrl', () => { + test('check to convert to grass graph image url', () => { + expect(toGrassGraphImageUrl('swfz')).toBe('https://grass-graph.appspot.com/images/swfz.png'); + }); +}); diff --git a/src/lib/to-grass-graph-image-url.ts b/src/lib/to-grass-graph-image-url.ts new file mode 100644 index 00000000..0ee616c7 --- /dev/null +++ b/src/lib/to-grass-graph-image-url.ts @@ -0,0 +1,3 @@ +export const toGrassGraphImageUrl = (username: string) => { + return `https://grass-graph.appspot.com/images/${username}.png`; +};