-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fallacy.view.ts
114 lines (84 loc) · 2.09 KB
/
fallacy.view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
namespace $.$$ {
export class $hyoo_fallacy extends $.$hyoo_fallacy {
@ $mol_mem
pages() {
return [
this.Menu(),
this.Content( this.filter() ),
]
}
filter() {
return this.$.$mol_state_arg.value( 'filter' ) ?? ''
}
search( next? : string ) {
return this.$.$mol_state_arg.value( 'search' , next ) ?? ''
}
selected( next? : string[] ) {
const str = next && ( next.join('~') || null )
return this.$.$mol_state_arg.value( 'selected' , str )?.split( '~' ) ?? []
}
@ $mol_mem
filters() {
return [
this.All(),
... Object.keys( this.tags() ).map( tag => this.Filter( tag ) ),
this.Selected(),
]
}
filter_arg( tag : string ) {
return { filter : tag }
}
filter_title( tag : string ) {
return this.tags()[ tag ].title
}
fallacy( id : string ) {
return this.fallacies()[ id ]
}
fallacy_selected( id : string, next?: boolean ) {
let selected = this.selected()
if( next === undefined ) {
return selected.includes( id )
} else {
selected = selected.filter( id2 => id2 !== id )
if( next ) selected = [ ... selected , id ]
this.selected( selected )
return next
}
}
@ $mol_mem
fallacies_filtered() {
const all = this.fallacies()
const filter = this.filter()
const search = this.search()
let ids: string[]
if( filter === 'selected' ) {
ids = this.selected()
} else {
ids = Object.keys( all ) as ( keyof typeof all )[]
ids = ids.filter( id => {
const fallacy = all[ id ]
if( filter ) {
if( !fallacy.tags.includes( filter ) ) return false
}
return true
} )
}
ids = ids.filter( $mol_match_text( search , id => [
all[id].title,
all[id].descr,
all[id].sample,
] ) )
return ids
}
cards() {
return this.fallacies_filtered().map( id => this.Card( id ) )
}
content_title( filter : string ) {
return this.tags()[ filter ]?.title ?? super.title()
}
search_focus( event : KeyboardEvent ) {
const el = this.Search().Query().focused( true )
event.preventDefault()
}
}
}