-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhabhub.view.ts
142 lines (111 loc) · 3.02 KB
/
habhub.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
namespace $.$$ {
export class $hyoo_habhub extends $.$hyoo_habhub {
search_start( event?: Event ) {
event?.preventDefault()
this.Search().Query().bring()
}
@ $mol_mem
uriSource(){
const search = this.search()
if( search.length < 2 ) return 'hyoo/habhub/data/issues.json?'
this.$.$mol_wait_timeout(500)
const query = `label:HabHub is:open "${search}"`
return `https://api.github.com/search/issues?q=${ encodeURIComponent(query) }&sort=updated&per_page=100`
}
@ $mol_mem
gists() {
return $mol_github_search_issues.item( this.uriSource() ).items()
}
@ $mol_mem
gists_dict() {
const dict = {} as { [ key : string ] : $mol_github_issue }
for( let gist of this.gists() ) {
dict[ gist.uri() ] = gist
}
return dict
}
gist( uri : string ) {
return this.gists_dict()[ uri ]
}
@ $mol_mem
gist_current() {
const uri = this.$.$mol_state_arg.value( 'gist' )
if( uri ) return $mol_github_issue.item( uri)
if( !this.owner() ) return null
if( !this.repo() ) return null
if( !this.article() ) return null
return $mol_github_issue.item( `https://api.github.com/repos/${ this.owner() }/${ this.repo() }/issues/${ this.article() }` )
}
@ $mol_mem
details_link() {
return `https://github.com/${ this.owner() }/${ this.repo() }/issues/${ this.article() }`
}
@ $mol_mem
Details_body() {
const gist = this.gist_current()
return gist ? this.Details( gist ).Body() : null!
}
owner() {
return this.$.$mol_state_arg.value( 'author' )
}
repo() {
return this.$.$mol_state_arg.value( 'repo' )
}
article() {
return this.$.$mol_state_arg.value( 'article' )
}
@ $mol_mem
pages() {
const gist = this.gist_current()
return [
this.Menu_page() ,
... gist ? [
this.Details( gist ),
... this.chat_pages( gist ),
] : []
]
}
@ $mol_mem_key
chat_seed( issue: $mol_github_issue ) {
return issue.uri().replace( /.*\/repos\//, '' )
}
@ $mol_mem
menu_rows() : $mol_view[] {
return this.gists()
// .filter( $mol_match_text( this.search(), gist => [ gist.title(), gist.text() ] ) )
.map( gist => this.Menu_row( gist.uri() ) )
}
@ $mol_mem_key
gist_title( uri : string ) {
return this.gist( uri ).title()
}
@ $mol_mem_key
gist_arg( uri : string ) {
const gist = this.gist( uri )
return {
author: gist.owner().name(),
repo: gist.repository().name(),
article: String( gist.number() ),
gist: null,
}
}
gist_current_title() {
return this.gist_current()!.title()
}
gist_current_content() {
return this.gist_current()!.text()
}
gist_current_issue() {
return this.gist_current()!
}
@ $mol_mem
gist_current_created() {
return this.gist_current()!.moment_created().toString( 'YYYY-MM-DD' )
}
@ $mol_mem
details_scroll_top( next? : number ) {
const current = this.gist_current()!
return $mol_state_session.value( `${ this }.details_scroll_top(${ current.uri() })` , next )
}
}
}