Updated views component

This commit is contained in:
r-freeman 2023-01-17 21:42:10 +00:00
parent 7281397fd5
commit a5d262bcf2
2 changed files with 5 additions and 3 deletions

View File

@ -97,7 +97,7 @@ export function ArticleLayout({
<time dateTime={date}>
<span>{formatDate(date)}</span>
</time>
{' '}&middot;{' '}<Views slug={slug}/>
<Views slug={slug}/>
</p>
</header>
<Prose className="mt-8">{children}</Prose>

View File

@ -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>
)
}