aboutsummaryrefslogtreecommitdiff
path: root/src/main.ts
diff options
context:
space:
mode:
authorJoris2023-02-08 10:33:51 +0100
committerJoris2023-02-08 10:33:51 +0100
commit0aa9ef160fe3362a85a6e9b678d1b65756c8e3a0 (patch)
tree7ebbc0ce06ab4c644e1a4045c5cdb6232735a7fc /src/main.ts
parent959c28f52e2ac1038f27110c88344fb321ed8e0e (diff)
Filter on read status
Diffstat (limited to 'src/main.ts')
-rw-r--r--src/main.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main.ts b/src/main.ts
new file mode 100644
index 0000000..7033690
--- /dev/null
+++ b/src/main.ts
@@ -0,0 +1,48 @@
+import { h, withVar, mount } from 'lib/rx'
+
+interface Book {
+ title: string
+ authors: Array<string>
+ authorsSort: string
+ genres: Array<string>
+ date: string
+ read: boolean
+ cover: string
+}
+
+// @ts-ignore
+const sortedBooks: Array<Book> = (books as Array<Book>).sort((a, b) =>
+ a.authorsSort == b.authorsSort
+ ? a.date > b.date
+ : a.authorsSort > b.authorsSort)
+
+enum Filter {
+ All,
+ Read,
+ Unread
+}
+
+const view = withVar(Filter.All, (filter, updateFilter) => [
+ h('aside',
+ { className: 'g-Aside' },
+ h('select',
+ { name: 'filter',
+ id: 'filter',
+ onchange: (event: Event) => updateFilter(_ => (event.target as HTMLSelectElement).value as any)
+ },
+ h('option', { value: Filter.All }, 'Tous les livres'),
+ h('option', { value: Filter.Read }, 'Livres lus'),
+ h('option', { value: Filter.Unread }, 'Livres non lus')
+ )
+ ),
+ h('main',
+ { className: 'g-Main' },
+ filter.map(f =>
+ sortedBooks
+ .filter(b => f == Filter.All || b.read == (f == Filter.Read))
+ .map(book => h('img', { className: 'g-Book', src: book.cover }))
+ )
+ )
+])
+
+mount(view)