From 3c2e63e753f1388be3c7f79c540b9f1bcc152df6 Mon Sep 17 00:00:00 2001
From: r-freeman
Date: Thu, 26 Jan 2023 22:07:11 +0000
Subject: [PATCH] Added number formatting to projects
---
components/Views.tsx | 9 ++-------
lib/numberFormat.ts | 5 +++++
pages/projects.tsx | 3 ++-
3 files changed, 9 insertions(+), 8 deletions(-)
create mode 100644 lib/numberFormat.ts
diff --git a/components/Views.tsx b/components/Views.tsx
index 11e19c3..62872cd 100644
--- a/components/Views.tsx
+++ b/components/Views.tsx
@@ -1,17 +1,12 @@
+import useSWR from 'swr'
import {ElementType, useEffect} from 'react'
import fetcher from '@/lib/fetcher'
-import useSWR from 'swr'
+import {numberFormat} from '@/lib/numberFormat'
type ViewsType = {
views: string
}
-function numberFormat(value: number) {
- return new Intl.NumberFormat('en', {
- notation: 'compact'
- }).format(value)
-}
-
const updateViews = (slug: string) => fetcher(`/api/views/${slug}`, {method: 'POST'})
export function Views({as: Component = 'span', slug}: { as?: ElementType, slug: string }) {
diff --git a/lib/numberFormat.ts b/lib/numberFormat.ts
new file mode 100644
index 0000000..9bc36b5
--- /dev/null
+++ b/lib/numberFormat.ts
@@ -0,0 +1,5 @@
+export function numberFormat(value: number) {
+ return new Intl.NumberFormat('en', {
+ notation: 'compact'
+ }).format(value)
+}
\ No newline at end of file
diff --git a/pages/projects.tsx b/pages/projects.tsx
index 08fcb2c..a27e31d 100644
--- a/pages/projects.tsx
+++ b/pages/projects.tsx
@@ -5,6 +5,7 @@ import {SimpleLayout} from '@/components/SimpleLayout'
import {SocialLink} from '@/components/SocialLink'
import {StarIcon} from '@/components/StarIcon'
import {getPinnedRepos} from '@/lib/github'
+import {numberFormat} from '@/lib/numberFormat'
import type {Repo} from '@/types'
export default function Projects({pinnedRepos}: { pinnedRepos: Repo[] }) {
@@ -50,7 +51,7 @@ export default function Projects({pinnedRepos}: { pinnedRepos: Repo[] }) {
style={{backgroundColor: repo.primaryLanguage.color}}/>
- {repo.stargazerCount}
+ {numberFormat(repo.stargazerCount)}