Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metadata and button loading state #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added www/public/favicon.ico
Binary file not shown.
Binary file added www/public/thumbnail.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions www/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { constructMetadata } from '@/lib/utils'
import Footer from '@/components/Footer'
import Navbar from '@/components/Navbar'
import Providers from '@/components/Providers'
Expand All @@ -8,10 +9,7 @@ import './globals.css'

const recursive = Recursive({ subsets: ['latin'] })

export const metadata: Metadata = {
title: 'Fast, Open-Source Profanity API',
description: 'A project made by JoshTriedCoding',
}
export const metadata = constructMetadata()

export const viewport: Viewport = {
maximumScale: 1, // Disable auto-zoom on mobile Safari, credit to https://github.com/ai-ng
Expand Down
22 changes: 18 additions & 4 deletions www/src/components/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Demo = () => {
</div>
<div className='relative flex flex-col sm:flex-row items-center gap-2 mt-6 h-full sm:h-9'>
<Input
className='bg-white h-9'
className='bg-white h-9 w-full'
value={message}
onKeyDown={(e) => {
if (e.key === 'Enter') mutate({ message })
Expand All @@ -49,9 +49,23 @@ const Demo = () => {
/>
<Button
disabled={isPending}
className='h-9 w-full sm:w-fit'
onClick={() => mutate({ message })}>
Profanity check
className='h-9 w-full sm:w-36 shrink-0'
onClick={() => mutate({ message })}
>
{isPending ? (
<svg
xmlns='http://www.w3.org/2000/svg'
viewBox='0 0 24 24'
fill='none'
stroke='currentColor'
strokeWidth='2'
strokeLinecap='round'
strokeLinejoin='round'
className='animate-spin h-4 w-4'
>
<path d='M21 12a9 9 0 1 1-6.219-8.56' />
</svg>
) : <span>Profanity Check</span>}
</Button>
</div>

Expand Down
45 changes: 45 additions & 0 deletions www/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
import { Metadata } from "next"

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}

export function constructMetadata({
title = 'Fast, Open-Source Profanity API',
description = 'A project made by JoshTriedCoding',
image = '/thumbnail.jpg',
icons = '/favicon.ico',
noIndex = false,
}: {
title?: string
description?: string
image?: string
icons?: string
noIndex?: boolean
} = {}): Metadata {
return {
title,
description,
openGraph: {
title,
description,
images: [
{
url: image,
},
],
},
twitter: {
card: 'summary_large_image',
title,
description,
images: [image],
creator: '@joshtriedcoding',
},
icons,
metadataBase: new URL('https://www.profanity.dev'),
themeColor: '#FFF',
...(noIndex && {
robots: {
index: false,
follow: false,
},
}),
}
}