From 67262949310e8cb4f46544bdd601048c79fb87de Mon Sep 17 00:00:00 2001 From: Steven Tey Date: Mon, 4 Sep 2023 20:47:56 -0700 Subject: [PATCH] sort by last clicked beta --- app/ui/number.tsx | 24 +++++++++++++++++++-- components/app/links/link-card.tsx | 3 ++- components/app/links/link-sort.tsx | 34 ++++++++++++++++++++++++++---- lib/api/links.ts | 4 ++-- prisma/schema.prisma | 1 + 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/app/ui/number.tsx b/app/ui/number.tsx index 58c7150438..962a2a0ca7 100644 --- a/app/ui/number.tsx +++ b/app/ui/number.tsx @@ -8,16 +8,36 @@ export default function Number({ value, unit = "clicks", children, + lastClicked, }: { value?: number | null; unit?: string; children: ReactNode; + lastClicked?: Date | null; }) { - if (!value || value < 1000) { + if ((!value || value < 1000) && !lastClicked) { return children; } return ( - + +

+ {nFormatter(value || 0, { full: true })} {unit} +

+ {lastClicked && ( +

+ Last clicked on{" "} + {new Date(lastClicked).toLocaleDateString("en-us", { + month: "short", + day: "numeric", + year: "numeric", + })} +

+ )} + + } + > {children}
); diff --git a/components/app/links/link-card.tsx b/components/app/links/link-card.tsx index c17c8385a9..d46a6371b3 100644 --- a/components/app/links/link-card.tsx +++ b/components/app/links/link-card.tsx @@ -55,6 +55,7 @@ export default function LinkCard({ url, rewrite, createdAt, + lastClicked, archived, tagId, comments, @@ -364,7 +365,7 @@ export default function LinkCard({
- + { e.stopPropagation(); diff --git a/components/app/links/link-sort.tsx b/components/app/links/link-sort.tsx index 71409d7689..fca1b6e034 100644 --- a/components/app/links/link-sort.tsx +++ b/components/app/links/link-sort.tsx @@ -2,18 +2,25 @@ import { useRouter } from "next/router"; import { useMemo, useState } from "react"; import IconMenu from "@/components/shared/icon-menu"; import { Sort, Tick } from "@/components/shared/icons"; -import { ChevronDown, SortDesc } from "lucide-react"; +import { ChevronDown, SortAsc, SortDesc } from "lucide-react"; import Popover from "#/ui/popover"; const sortOptions = [ { display: "Date Added", slug: "createdAt", + order: "desc", }, { display: "Number of Clicks", slug: "clicks", + order: "desc", }, + // { + // display: "Last Clicked", + // slug: "lastClicked", + // order: "asc", + // }, ]; export default function LinkSort() { @@ -29,7 +36,7 @@ export default function LinkSort() { - {sortOptions.map(({ display, slug }) => ( + {sortOptions.map(({ display, slug, order }) => (