feat: add ItemList

This commit is contained in:
Mathias Schopmans
2024-02-15 10:00:14 +01:00
committed by Mathias Schopmans
parent f910c9e1e5
commit 5603384603
8 changed files with 153 additions and 11 deletions

View File

@@ -1,7 +1,8 @@
import config from "../../data/config.json";
import data from "../../data/data.json";
import messages from "../../data/messages.json";
import { Quadrant, Ring } from "@/lib/types";
import { Flag, Item, Quadrant, Ring } from "@/lib/types";
export function getMessages() {
return messages;
@@ -11,10 +12,22 @@ export function getAppName() {
return messages.radarName;
}
export function getFlag(flag: Exclude<Flag, Flag.Default>) {
return config.flags[flag];
}
export function getRings(): Ring[] {
return config.rings;
}
export function getRing(id: string): Ring | undefined {
return getRings().find((r) => r.id === id);
}
export function getReleases(): string[] {
return data.releases;
}
export function getQuadrants(): Quadrant[] {
return config.quadrants;
}
@@ -22,3 +35,14 @@ export function getQuadrants(): Quadrant[] {
export function getQuadrant(id: string): Quadrant | undefined {
return getQuadrants().find((q) => q.id === id);
}
export function getItems(featured?: boolean): Item[] {
return data.items.filter((item) => !featured || item.featured) as Item[];
}
export function getItem(id: string): Item | undefined {
return data.items.find((item) => item.id === id) as Item;
}
export const sortByFeaturedAndTitle = (a: Item, b: Item) =>
Number(b.featured) - Number(a.featured) || a.title.localeCompare(b.title);

View File

@@ -1,7 +1,15 @@
// Format the title of the page
import { getAppName } from "@/lib/data";
export function formatTitle(title: string = ""): string {
if (!title) return getAppName();
return `${title} | ${getAppName()}`;
// Format the title of the page
export function formatTitle(...title: string[]): string {
return [...title, getAppName()].join(" | ");
}
// Formats a release (2024-02-14) to a date (February 2024)
export function formatRelease(release: string): string {
const date = new Date(release);
return date.toLocaleDateString("en-US", {
month: "long",
year: "numeric",
});
}

View File

@@ -38,5 +38,4 @@ export interface Quadrant {
description: string;
color: string;
position: number;
items?: Item[];
}