generated from theodorusclarence/ts-nextjs-tailwind-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
detail.tsx
96 lines (84 loc) · 3.19 KB
/
detail.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { useRouter } from 'next/router';
import * as React from 'react';
import { HiCursorClick } from 'react-icons/hi';
import { useQuery } from 'react-query';
import { trimHttps } from '@/lib/helper';
import { Url } from '@/lib/notion';
import useRQWithToast from '@/hooks/toast/useRQWithToast';
import Accent from '@/components/Accent';
import Favicon from '@/components/Favicon';
import Layout from '@/components/layout/Layout';
import ArrowLink from '@/components/links/ArrowLink';
import PrimaryLink from '@/components/links/PrimaryLink';
import Seo from '@/components/Seo';
import Skeleton from '@/components/Skeleton';
import CopyBox from '@/container/CopyBox';
import QRCode from '@/container/QRCode';
export default function DetailPage() {
//#region //*=========== Get Route Param ===========
const router = useRouter();
const idParam = router.query.slug;
//#endregion //*======== Get Route Param ===========
//#region //*=========== Link ===========
const [link, setLink] = React.useState<string>();
React.useEffect(() => {
const origin = trimHttps(window.location.href).replace('/detail', '');
setLink(origin);
}, [idParam]);
//#endregion //*======== Link ===========
//#region //*=========== Get Url Data ===========
const { data: url } = useRQWithToast(
useQuery<Url, Error>(`/api/link/${idParam}`, { retry: 1 }),
{
loading: 'Fetching url details...',
success: 'Url detail fetched successfully',
}
);
//#endregion //*======== Get Url Data ===========
return (
<Layout>
<Seo templateTitle='Detail' />
<main>
<section className=''>
<div className='layout flex min-h-screen flex-col items-center justify-center py-20'>
<h1 className='h0'>
<Accent>Link Details</Accent>
</h1>
{link ? (
<QRCode link={`https://${link}`} className='mt-8' />
) : (
<Skeleton className='mt-8 h-64 w-64' />
)}
{link ? (
<CopyBox link={link} className='mt-8' />
) : (
<Skeleton className='mt-8 h-14 w-72 rounded' />
)}
<div className='mt-6'>
<h2 className='h4'>Detail</h2>
<div className='mt-2 flex items-center gap-4'>
{url?.link ? (
<Favicon fullUrl={url.link} />
) : (
<Skeleton className='h-5 w-5' />
)}
<div className='w-full max-w-sm break-all font-medium text-gray-600 dark:text-gray-300'>
{url?.link ? url.link : <Skeleton className='h-5 w-64' />}
</div>
</div>
<div className='mt-2 flex items-center gap-4'>
<HiCursorClick className='h-5 w-5' />
<span className='font-medium text-gray-600 dark:text-gray-300'>
{url?.count ?? '—'} click{(url?.count ?? 0) > 1 && 's'}
</span>
</div>
</div>
<ArrowLink href='/new' className='mt-8' as={PrimaryLink}>
<Accent>Shorten another</Accent>
</ArrowLink>
</div>
</section>
</main>
</Layout>
);
}