feat: add QuadrantList and RingList to render items on homepage and quadrant page

This commit is contained in:
Mathias Schopmans
2024-02-15 15:09:31 +01:00
committed by Mathias Schopmans
parent 5603384603
commit 86c1d9090b
13 changed files with 277 additions and 15 deletions

View File

@@ -36,8 +36,11 @@ 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 getItems(quadrant?: string, featured?: boolean): Item[] {
return data.items.filter((item) => {
if (quadrant && item.quadrant !== quadrant) return false;
return !(featured && !item.featured);
}) as Item[];
}
export function getItem(id: string): Item | undefined {
@@ -46,3 +49,27 @@ export function getItem(id: string): Item | undefined {
export const sortByFeaturedAndTitle = (a: Item, b: Item) =>
Number(b.featured) - Number(a.featured) || a.title.localeCompare(b.title);
export const groupItemsByRing = (items: Item[]) => {
return getRings().reduce(
(acc, ring) => {
const ringItems = items.filter((item) => item.ring === ring.id);
if (ringItems.length) acc[ring.id] = ringItems;
return acc;
},
{} as { [ringId: string]: Item[] },
);
};
export const groupItemsByQuadrant = (items: Item[]) => {
return getQuadrants().reduce(
(acc, quadrant) => {
const quadrantItems = items.filter(
(item) => item.quadrant === quadrant.id,
);
if (quadrantItems.length) acc[quadrant.id] = quadrantItems;
return acc;
},
{} as { [quadrantId: string]: Item[] },
);
};