separate non featured articles on quadrant view

This commit is contained in:
dennis.ludwig
2021-06-16 11:53:05 +02:00
parent 61d7fa38f2
commit eff1bcbc2b
14 changed files with 581 additions and 441 deletions

View File

@@ -1,43 +1,46 @@
import { Ring } from "./config"
import { Ring } from "./config";
export type ItemAttributes = {
name: string
ring: Ring
quadrant: string
title: string
featured: boolean
}
name: string;
ring: Ring;
quadrant: string;
title: string;
featured: boolean;
};
export type FlagType = 'new' | 'changed' | 'default'
export type FlagType = "new" | "changed" | "default";
export type Item = ItemAttributes & {
featured: boolean
body: string
info: string
flag: FlagType
revisions: Revision[]
}
featured: boolean;
body: string;
info: string;
flag: FlagType;
revisions: Revision[];
};
export type Revision = ItemAttributes & {
body: string
fileName: string
release: string
}
body: string;
fileName: string;
release: string;
};
export type Quadrant = {
[name: string]: Item[]
}
[name: string]: Item[];
};
export type Radar = {
items: Item[]
releases: string[]
}
items: Item[];
releases: string[];
};
export type Group = {
[quadrant: string]: Quadrant
}
[quadrant: string]: Quadrant;
};
export const featuredOnly = (items: Item[]) => items.filter(item => item.featured);
export const featuredOnly = (items: Item[]) =>
items.filter((item) => item.featured);
export const nonFeaturedOnly = (items: Item[]) =>
items.filter((item) => !item.featured);
export const groupByQuadrants = (items: Item[]): Group =>
items.reduce(
@@ -45,7 +48,7 @@ export const groupByQuadrants = (items: Item[]): Group =>
...quadrants,
[item.quadrant]: addItemToQuadrant(quadrants[item.quadrant], item),
}),
{} as {[k: string]: Quadrant},
{} as { [k: string]: Quadrant }
);
export const groupByFirstLetter = (items: Item[]) => {
@@ -54,15 +57,15 @@ export const groupByFirstLetter = (items: Item[]) => {
...letterIndex,
[getFirstLetter(item)]: addItemToList(
letterIndex[getFirstLetter(item)],
item,
item
),
}),
{} as {[k: string]: Item[]},
{} as { [k: string]: Item[] }
);
return Object.keys(index)
.sort()
.map(letter => ({
.map((letter) => ({
letter,
items: index[letter],
}));
@@ -77,4 +80,5 @@ const addItemToList = (list: Item[] = [], item: Item) => [...list, item];
const addItemToRing = (ring: Item[] = [], item: Item) => [...ring, item];
export const getFirstLetter = (item: Item) => item.title.substr(0, 1).toUpperCase();
export const getFirstLetter = (item: Item) =>
item.title.substr(0, 1).toUpperCase();