Add gists page

This commit is contained in:
DefectingCat
2023-03-22 15:32:33 +08:00
parent 45209b7a5c
commit b47519256f
4 changed files with 52 additions and 13 deletions

41
app/gists/page.tsx Normal file
View File

@ -0,0 +1,41 @@
import { getGists } from 'lib/fetcher';
import { notFound } from 'next/navigation';
import UserInfo from './user-info';
import { Suspense } from 'react';
import FileContent from 'components/gists/file-content';
import Pagination from 'components/rua/rua-pagination';
export default async function Page() {
const gists = await getGists();
if (!gists) notFound();
const prev = Number(gists.pageSize.prev);
const next = Number(gists.pageSize.next);
const total = Number(gists.pageSize.last);
return (
<>
<main className="max-w-5xl px-4 mx-auto lg:px-0">
<div className="md:flex">
<Suspense fallback>
{/* @ts-expect-error Async Server Component */}
<UserInfo />
</Suspense>
<div className="flex-1 px-1 py-4 overflow-hidden md:pl-8">
<FileContent gists={gists.gists} />
<Pagination
className="mt-4"
hasPrev={!!prev}
hasNext={!!next}
prevLink={prev === 1 ? `/gists/` : `/gists/${prev}`}
nextLink={`/gists/${next}`}
current={prev == null ? next - 1 : prev + 1}
total={total}
/>
</div>
</div>
</main>
</>
);
}

View File

@ -1,15 +1,12 @@
import clsx from 'clsx';
import { GetUser } from 'lib/fetcher';
import { getUser } from 'lib/fetcher';
import Image from 'next/image';
import avatar from 'public/images/img/avatar.svg';
import { memo } from 'react';
import { FiLink, FiMail, FiTwitter } from 'react-icons/fi';
type Props = {
user: GetUser;
};
const UserInfo = async () => {
const user = await getUser();
const UserInfo = ({ user }: Props) => {
return (
<>
<div
@ -80,4 +77,4 @@ const UserInfo = ({ user }: Props) => {
);
};
export default memo(UserInfo);
export default UserInfo;

View File

@ -1,5 +1,8 @@
import 'styles/globals.css';
import '@docsearch/css/dist/style.css';
import 'styles/prism-one-dark.css';
import 'styles/prism-one-light.css';
import 'styles/rua.css';
import RUAThemeProvider from './theme-provider';
import HeadBar from './nav-bar';
import Footer from './footer';

View File

@ -5,10 +5,10 @@ import { GistData } from 'lib/fetcher';
import dynamic from 'next/dynamic';
import Link from 'next/link';
import { memo, Suspense } from 'react';
import GistsCode from './gists-code';
import relativeTime from 'dayjs/plugin/relativeTime';
const GistsCode = dynamic(() => import('components/gists/gists-code'), {
suspense: true,
});
dayjs.extend(relativeTime);
type Props = {
gists: GistData[];
@ -38,9 +38,7 @@ const FileContent = ({ gists }: Props) => {
{/* Description */}
<p className="text-gray-500">{g.description}</p>
<Suspense fallback={<Loading className="h-[300px]" />}>
<GistsCode file={g.files[f]} />
</Suspense>
<GistsCode file={g.files[f]} />
</div>
))}
</div>