diff --git a/src/app/components/like-button.tsx b/src/app/components/like-button.tsx index 5e9cef5..e56f6f8 100644 --- a/src/app/components/like-button.tsx +++ b/src/app/components/like-button.tsx @@ -3,6 +3,7 @@ import { useState } from "react"; import { redirect } from "next/navigation"; import { Icon } from "@iconify/react"; +import { abbreviateNumber } from "@/lib/abbreviation"; interface Props { likes: number; @@ -10,12 +11,13 @@ interface Props { isLiked: boolean; isLoggedIn?: boolean; disabled?: boolean; + abbreviate?: boolean; big?: boolean; } -export default function LikeButton({ likes, isLiked, miiId, isLoggedIn, disabled, big }: Props) { +export default function LikeButton({ likes, isLiked, miiId, isLoggedIn, disabled, abbreviate, big }: Props) { const [isLikedState, setIsLikedState] = useState(isLiked); - const [likesState, setLikesState] = useState(likes); + const [likesState, setLikesState] = useState(10000); const onClick = async () => { if (disabled) return; @@ -39,7 +41,7 @@ export default function LikeButton({ likes, isLiked, miiId, isLoggedIn, disabled return ( ); } diff --git a/src/app/components/mii-list/index.tsx b/src/app/components/mii-list/index.tsx index f7438dd..28bd2ba 100644 --- a/src/app/components/mii-list/index.tsx +++ b/src/app/components/mii-list/index.tsx @@ -101,7 +101,7 @@ export default function MiiList({ isLoggedIn, userId }: Props) {
- + {!userId ? ( diff --git a/src/lib/abbreviation.ts b/src/lib/abbreviation.ts new file mode 100644 index 0000000..99a63f8 --- /dev/null +++ b/src/lib/abbreviation.ts @@ -0,0 +1,10 @@ +export function abbreviateNumber(number: number): string { + if (number < 1000) return number.toString(); + + const units = ["", "K", "M", "B", "T"]; // very unlikely to go into thousands, let alone millions, but you never know + const order = Math.floor(Math.log10(number) / 3); + const unit = units[order] || ""; + const scaled = number / Math.pow(10, order * 3); + + return `${scaled.toFixed(scaled < 10 ? 1 : 0)}${unit}`; +}