web3.news/app/utils.ts

83 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-12-18 03:45:17 +00:00
import { formatDistanceToNow, subDays, subMonths, subYears } from "date-fns";
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
import { SearchResult, SelectOptions } from "@/types.js";
2023-12-05 14:03:21 +00:00
export function cn(...inputs: ClassValue[]) {
2023-12-18 03:45:17 +00:00
return twMerge(clsx(inputs));
2023-12-05 14:03:21 +00:00
}
2023-11-14 15:52:42 +00:00
// Utility function to format dates
export const formatDate = (date: string | Date) => {
2023-12-18 03:45:17 +00:00
const _date = new Date(date);
const distance = formatDistanceToNow(_date, { addSuffix: true });
return distance
.replace(/less than a minute?/, "<1m")
.replace(/ minutes?/, "m")
.replace(/ hours?/, "h")
.replace(/ days?/, "d")
2023-12-18 03:45:17 +00:00
.replace(/ weeks?/, "w");
};
export async function getResults({
2023-12-18 03:45:17 +00:00
query,
}: {
2023-12-18 03:45:17 +00:00
query?: string;
}): Promise<SearchResult[]> {
2023-12-18 03:45:17 +00:00
if (!query) return [];
return [
{
id: 1,
timestamp: new Date(),
title: "Mock Title 1",
description: "Mock Description 1",
2023-12-18 03:45:17 +00:00
slug: "hello-world",
},
{
id: 2,
timestamp: new Date(),
title: "Mock Title 2",
description: "Mock Description 2",
2023-12-18 03:45:17 +00:00
slug: "hello-world-2",
},
];
}
2023-12-05 14:03:21 +00:00
2023-12-18 03:45:17 +00:00
export function getAvailableSites() {
const statuses: SelectOptions[] = [
{
value: "backlog",
2023-12-18 03:45:17 +00:00
label: "Backlog",
},
{
value: "todo",
2023-12-18 03:45:17 +00:00
label: "Todo",
},
{
value: "in progress",
2023-12-18 03:45:17 +00:00
label: "In Progress",
},
{
value: "done",
2023-12-18 03:45:17 +00:00
label: "Done",
},
{
value: "canceled",
2023-12-18 03:45:17 +00:00
label: "Canceled",
},
];
return statuses;
}
export const FILTER_TIMES = [
{ value: 0, label: "All Times" },
{ value: subDays(new Date(), 1), label: "1d ago" },
{ value: subDays(new Date(), 7), label: "7d ago" },
{ value: subDays(new Date(), 15), label: "15d ago" },
{ value: subMonths(new Date(), 1), label: "1m ago" },
{ value: subMonths(new Date(), 6), label: "6m ago" },
2023-12-18 03:45:17 +00:00
{ value: subYears(new Date(), 1), label: "1y ago" },
];