mirror of
https://github.com/r-freeman/portfolio.git
synced 2024-11-22 13:35:41 +00:00
Updated views component
This commit is contained in:
parent
7281397fd5
commit
a5d262bcf2
@ -97,7 +97,7 @@ export function ArticleLayout({
|
||||
<time dateTime={date}>
|
||||
<span>{formatDate(date)}</span>
|
||||
</time>
|
||||
{' '}·{' '}<Views slug={slug}/>
|
||||
<Views slug={slug}/>
|
||||
</p>
|
||||
</header>
|
||||
<Prose className="mt-8">{children}</Prose>
|
||||
|
@ -13,7 +13,9 @@ type ViewsType = {
|
||||
}
|
||||
|
||||
export function Views({as: Component = 'span', slug}: { as?: ElementType, slug: string }) {
|
||||
const {data} = useSWR<ViewsType>(`/api/views/${slug}`, fetcher)
|
||||
const {data} = useSWR<ViewsType>(`/api/views/${slug}`, fetcher, {
|
||||
revalidateOnFocus: false
|
||||
})
|
||||
const views = Number(data?.views)
|
||||
|
||||
useEffect(() => {
|
||||
@ -27,7 +29,7 @@ export function Views({as: Component = 'span', slug}: { as?: ElementType, slug:
|
||||
|
||||
return (
|
||||
<Component>
|
||||
{views > 0 ? `${numberFormat(views)} views` : ''}
|
||||
{views > 0 ? ` · ${numberFormat(views)} views` : ''}
|
||||
</Component>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user