mirror of
https://github.com/r-freeman/portfolio.git
synced 2024-11-22 18:15: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}>
|
<time dateTime={date}>
|
||||||
<span>{formatDate(date)}</span>
|
<span>{formatDate(date)}</span>
|
||||||
</time>
|
</time>
|
||||||
{' '}·{' '}<Views slug={slug}/>
|
<Views slug={slug}/>
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
<Prose className="mt-8">{children}</Prose>
|
<Prose className="mt-8">{children}</Prose>
|
||||||
|
@ -13,7 +13,9 @@ type ViewsType = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Views({as: Component = 'span', slug}: { as?: ElementType, slug: string }) {
|
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)
|
const views = Number(data?.views)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -27,7 +29,7 @@ export function Views({as: Component = 'span', slug}: { as?: ElementType, slug:
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Component>
|
<Component>
|
||||||
{views > 0 ? `${numberFormat(views)} views` : ''}
|
{views > 0 ? ` · ${numberFormat(views)} views` : ''}
|
||||||
</Component>
|
</Component>
|
||||||
)
|
)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user