mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 09:11:38 +00:00
Add gists page
This commit is contained in:
41
app/gists/page.tsx
Normal file
41
app/gists/page.tsx
Normal 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>
|
||||
</>
|
||||
);
|
||||
}
|
@ -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;
|
@ -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';
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user