From 06f045e90bb57c36738e58ee6830e2a2391bc6a3 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 16 Sep 2023 18:28:16 +0200 Subject: Migrate CLI to python --- src/view/filters.ts | 90 ----------------------------------------------------- 1 file changed, 90 deletions(-) delete mode 100644 src/view/filters.ts (limited to 'src/view/filters.ts') diff --git a/src/view/filters.ts b/src/view/filters.ts deleted file mode 100644 index efe4115..0000000 --- a/src/view/filters.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { h, Rx, Html } from 'lib/rx' -import * as Book from 'book' -import * as I18n from 'lib/i18n' - -// Model - -export interface Model { - read?: Book.ReadStatus -} - -const init: Model = {} - -// View - -interface ViewFiltersParams { - filteredBooks: Rx> - filters: Rx - updateFilters: (f: (filters: Model) => Model) => void -} - -export function view({ filteredBooks, filters, updateFilters }: ViewFiltersParams): Html { - return h('ul', - h('li', [ - h('div', { className: 'g-FilterTitle' }, 'Lecture'), - readFilter({ - filteredBooks, - readStatus: filters.map(fs => fs.read), - update: (status?: Book.ReadStatus) => updateFilters(fs => { - fs.read = status - return fs - }) - }) - ]) - ) -} - -interface ReadFilterParams { - filteredBooks: Rx> - readStatus: Rx - update: (status?: Book.ReadStatus) => void -} - -function readFilter({ filteredBooks, readStatus, update }: ReadFilterParams): Html { - return h('ul', - { className: 'g-Filters' }, - readStatus.map(currentStatus => { - if (currentStatus !== undefined) { - return h('li', - { className: 'g-Filter g-Filter--Selected' }, - h('button', - { onclick: () => update(undefined) }, - filteredBooks.map(xs => unit(xs.length, readStatusLabels(currentStatus))) - ) - ) - } else { - return Book.readStatuses.map(status => - filteredBooks.map(xs => { - const count = xs.filter(b => b.read === status).length - - return count !== 0 - ? h('li', - { className: 'g-Filter g-Filter--Unselected' }, - h('button', - { onclick: () => update(status) }, - unit(count, readStatusLabels(status)) - ) - ) - : undefined - }) - ) - } - }) - ) -} - -function unit(n: number, labels: Array): string { - return I18n.unit(n, labels[0], labels[1], (n, str) => `${str} (${n})`) -} - -function readStatusLabels(status: Book.ReadStatus): Array { - if (status === 'Read') { - return ['lu', 'lus'] - } else if (status === 'Unread') { - return ['non lu', 'non lus'] - } else if (status === 'Reading') { - return ['en cours', 'en cours'] - } else { - return ['arrêté', 'arrêtés'] - } -} -- cgit v1.2.3