aboutsummaryrefslogtreecommitdiff
path: root/library/client/main.ts
diff options
context:
space:
mode:
authorJoris2023-09-17 12:23:47 +0200
committerJoris2023-09-17 12:23:47 +0200
commit1ebc55c72a1a17293bbf4ad86e0177a10a794750 (patch)
tree5fce0ea3a011ccbae85b0d3927f8ac33099585fb /library/client/main.ts
parentc236facb4d4c277773c83f1a4ee85b48833d7e67 (diff)
Make app packageable
Diffstat (limited to 'library/client/main.ts')
-rw-r--r--library/client/main.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/library/client/main.ts b/library/client/main.ts
new file mode 100644
index 0000000..5885871
--- /dev/null
+++ b/library/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<Book> = (bookLibrary as Array<Book.Book>).sort((a, b) =>
+ a.authorsSort == b.authorsSort
+ ? a.date > b.date
+ : a.authorsSort > b.authorsSort)
+
+mount(withVar<Filters.Model>({}, (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)
+}