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/client/main.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/view/client/main.ts (limited to 'src/view/client/main.ts') diff --git a/src/view/client/main.ts b/src/view/client/main.ts new file mode 100644 index 0000000..5885871 --- /dev/null +++ b/src/view/client/main.ts @@ -0,0 +1,46 @@ +import { h, withVar, mount, Html } from 'lib/rx' +import * as Search from 'lib/search' +import * as Functions from 'lib/functions' +import * as I18n from 'lib/i18n' +import * as Filters from 'view/filters' +import * as Books from 'view/books' +import * as Book from 'book' + +// @ts-ignore +const sortedBookLibrary: Array = (bookLibrary as Array).sort((a, b) => + a.authorsSort == b.authorsSort + ? a.date > b.date + : a.authorsSort > b.authorsSort) + +mount(withVar({}, (filters, updateFilters) => + withVar('', (search, updateSearch) => { + const filteredBooks = filters.flatMap(f => search.map(s => + sortedBookLibrary.filter(book => + (f.read === undefined || book.read === f.read) + && (s === '' || matchSearch(book, s)) + ) + )) + + return [ + h('aside', Filters.view({ filteredBooks, filters, updateFilters })), + h('main', + h('header', + h('input', + { className: 'g-Search', + oninput: Functions.debounce( + (event: Event) => updateSearch(_ => (event.target as HTMLInputElement).value), + 500 + ) + } + ), + filteredBooks.map(fb => I18n.unit(fb.length, 'livre', 'livres')) + ), + Books.view(filteredBooks) + ) + ] + }) +)) + +function matchSearch(book: Book.Book, search: string): boolean { + return Search.match(search, book.title, book.subtitle, ...book.authors) +} -- cgit v1.2.3