generated from theodorusclarence/ts-nextjs-tailwind-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1581daf
commit 8e1e909
Showing
7 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as React from 'react'; | ||
|
||
import clsxm from '@/lib/clsxm'; | ||
|
||
type SkeletonProps = React.ComponentPropsWithoutRef<'div'>; | ||
|
||
export default function Skeleton({ className, ...rest }: SkeletonProps) { | ||
return ( | ||
<div className={clsxm('bg-gray-400 animate-pulse', className)} {...rest} /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as React from 'react'; | ||
import CopyToClipboard from 'react-copy-to-clipboard'; | ||
import toast from 'react-hot-toast'; | ||
import { HiClipboard } from 'react-icons/hi'; | ||
|
||
import clsxm from '@/lib/clsxm'; | ||
import { trimHttps } from '@/lib/helper'; | ||
|
||
import PrimaryLink from '../components/links/PrimaryLink'; | ||
|
||
type CopyBoxProps = { | ||
link: string; | ||
} & React.ComponentPropsWithoutRef<'div'>; | ||
|
||
export default function CopyBox({ className, link, ...rest }: CopyBoxProps) { | ||
return ( | ||
<div | ||
className={clsxm( | ||
'flex gap-2 items-center p-2 pl-4 max-w-sm rounded border border-gray-600', | ||
className | ||
)} | ||
{...rest} | ||
> | ||
<div className='flex-grow text-left'> | ||
<PrimaryLink href={link} className='text-lg'> | ||
{trimHttps(link)} | ||
</PrimaryLink> | ||
</div> | ||
|
||
<CopyToClipboard | ||
text={link} | ||
onCopy={() => toast.success(`${trimHttps(link)} copied to clipboard`)} | ||
> | ||
<button className='p-2 rounded-full hover:text-primary-400 focus:ring focus:ring-primary-400 focus:outline-none'> | ||
<HiClipboard className='text-lg' /> | ||
</button> | ||
</CopyToClipboard> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as React from 'react'; | ||
import ReactQRCode from 'react-qr-code'; | ||
|
||
export default function QRCode({ | ||
link, | ||
className, | ||
}: { | ||
link: string; | ||
className?: string; | ||
}) { | ||
return ( | ||
<div className={className}> | ||
<ReactQRCode | ||
value={link} | ||
className='mx-auto' | ||
bgColor='#222222' | ||
fgColor='var(--clr-primary-400)' | ||
id='QRCode' | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useRouter } from 'next/router'; | ||
import * as React from 'react'; | ||
|
||
import Accent from '@/components/Accent'; | ||
import Layout from '@/components/layout/Layout'; | ||
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 = window.location.origin; | ||
const slug = idParam; | ||
|
||
setLink(origin + '/' + slug); | ||
}, [idParam]); | ||
//#endregion //*======== Link =========== | ||
|
||
return ( | ||
<Layout> | ||
<Seo templateTitle='Detail' /> | ||
|
||
<main> | ||
<section className=''> | ||
<div className='layout flex flex-col items-center py-20 min-h-screen'> | ||
<h1 className='h0'> | ||
<Accent>Shorten New Link</Accent> | ||
</h1> | ||
|
||
{link ? ( | ||
<QRCode link={link} className='mt-8' /> | ||
) : ( | ||
<Skeleton className='mt-8 w-64 h-64' /> | ||
)} | ||
|
||
{link ? ( | ||
<CopyBox link={link} className='mt-8' /> | ||
) : ( | ||
<Skeleton className='mt-8 w-72 h-14 rounded' /> | ||
)} | ||
</div> | ||
</section> | ||
</main> | ||
</Layout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters