Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

sort lastClicked descending

Steven Tey5d519f2ff04d
diff --git a/app/ui/number.tsx b/app/ui/number.tsx
index 962a2a0ca7..6ab2f6bd48 100644
--- a/app/ui/number.tsx
+++ b/app/ui/number.tsx
@@ -1,12 +1,12 @@
"use client";
import { ReactNode } from "react";
-import { nFormatter } from "#/lib/utils";
+import { nFormatter, timeAgo } from "#/lib/utils";
import Tooltip from "#/ui/tooltip";
export default function Number({
value,
- unit = "clicks",
+ unit = "total clicks",
children,
lastClicked,
}: {
@@ -27,12 +27,10 @@ export default function Number({
</p>
{lastClicked && (
<p className="mt-1 text-xs text-gray-500">
- Last clicked on{" "}
- {new Date(lastClicked).toLocaleDateString("en-us", {
- month: "short",
- day: "numeric",
- year: "numeric",
- })}
+ Last clicked {timeAgo(lastClicked)}{" "}
+ {Date.now() - new Date(lastClicked).getTime() < 82800000
+ ? "ago"
+ : ""}
</p>
)}
</div>
diff --git a/components/app/links/link-sort.tsx b/components/app/links/link-sort.tsx
index 5e048c7744..ad8c78fbe1 100644
--- a/components/app/links/link-sort.tsx
+++ b/components/app/links/link-sort.tsx
@@ -9,17 +9,14 @@ const sortOptions = [
{
display: "Date Added",
slug: "createdAt",
- order: "desc",
},
{
display: "Number of Clicks",
slug: "clicks",
- order: "desc",
},
{
display: "Last Clicked",
slug: "lastClicked",
- order: "asc",
},
];
@@ -36,7 +33,7 @@ export default function LinkSort() {
<Popover
content={
<div className="w-full p-2 md:w-48">
- {sortOptions.map(({ display, slug, order }) => (
+ {sortOptions.map(({ display, slug }) => (
<button
key={slug}
onClick={() => {
@@ -59,13 +56,7 @@ export default function LinkSort() {
>
<IconMenu
text={display}
- icon={
- order === "desc" ? (
- <SortDesc className="h-4 w-4" />
- ) : (
- <SortAsc className="h-4 w-4" />
- )
- }
+ icon={<SortDesc className="h-4 w-4" />}
/>
{selectedSort.slug === slug && (
<Tick className="h-4 w-4" aria-hidden="true" />
@@ -85,11 +76,7 @@ export default function LinkSort() {
text={sort ? selectedSort.display : "Sort by"}
icon={
sort ? (
- selectedSort.order === "desc" ? (
- <SortDesc className="h-4 w-4" />
- ) : (
- <SortAsc className="h-4 w-4" />
- )
+ <SortDesc className="h-4 w-4" />
) : (
<Sort className="h-4 w-4 shrink-0" />
)
diff --git a/lib/api/links.ts b/lib/api/links.ts
index cbb90f7ff8..fc2415cc59 100644
--- a/lib/api/links.ts
+++ b/lib/api/links.ts
@@ -22,7 +22,7 @@ export async function getLinksForProject({
domain?: string;
tagId?: string;
search?: string;
- sort?: "createdAt" | "clicks" | "lastClicked"; // descending for "createdAt" and "clicks", ascending for "lastClicked"
+ sort?: "createdAt" | "clicks" | "lastClicked"; // descending for all
page?: string;
userId?: string | null;
showArchived?: boolean;
@@ -52,7 +52,7 @@ export async function getLinksForProject({
user: true,
},
orderBy: {
- [sort]: sort === "lastClicked" ? "asc" : "desc",
+ [sort]: "desc",
},
take: 100,
...(page && {