style: format

This commit is contained in:
Derrick Hammer 2023-12-17 22:45:17 -05:00
parent bb8fd35b49
commit ba5fc45b4a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 27 additions and 28 deletions

View File

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