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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
/- *boke, cnt=contact, tp=trill-post
/+ ui=trill-ui, kaji, const=constants, wall
/= user /web/components/user
|_ [tt=tags-table =bowl:gall edit=(unit [thread:tp post:tp])]
++ css ^~ %- trip
'''
#error-div{
color: red;
}
#new-thread{
padding: 10px;
margin: auto;
border: 1px solid var(--background-color);
border-radius: 1%;
& fieldset{
border: none;
padding: 0;
margin-top: 1rem;
& label{
display: block;
}
& input{
width: 100%;
line-height: 1.5rem;
}
}
& .board-choice{
display: flex;
align-items: center;
& .left{
width: 20%;
& select{
background-color: var(--background-color);
height: 2rem;
}
}
& .right{
margin-left: 2rem;
flex-grow: 1;
}
}
& .author{
img{
width:30px;
height:30px;
}
& .name{
margin-left: 1rem;
}
}
& #bordered{
border: 1px solid black;
width: 100%;
height: 50vh;
overflow-y: scroll;
& textarea{
resize: none;
width: 100%;
height: 90%;
border: none;
outline: none;
}
}
& #chips{
position: relative;
width: 100%;
border: 1px solid rgb(107, 114, 128);
padding: 0 0.5rem;
& .chip{
display: inline-block;
font-size: 13px;
font-weight: 500;
color: rgba(0, 0, 0, 0.6);
line-height: 26px;
padding: 0 12px;
border-radius: 16px;
background-color: #e4e4e4;
cursor: pointer;
margin: 0 2px;
}
& .selected-chip{
background-color: rgb(100, 100, 100);
}
& .chip:hover{
background-color: rgb(100, 100, 100);
}
& input{
border: 0;
display: inline-block;
font-size: 16px;
height: 2rem;
line-height: 32px;
outline: 0;
margin: 0;
padding: 0 !important;
}
}
}
@media (min-width: 800px){
#new-thread{
width: 70%;
}
}
@media (max-width: 800px){
}
.buttons{
display: flex;
gap: 0.5rem;
justify-content: end;
align-items: center;
}
#poll-button{
border: none;
background: url('https://s3.spandrell.ch/assets/board/ui/poll.svg');
background-size: cover;
width: 30px;
height: 30px;
}
'''
++ script
=/ json-tags=json %- pairs:enjs:format
%+ turn ~(tap by tt) |= [tag=@t p=(list *)]
:+ tag %n (scot %ud (lent p))
=/ json-string %- trip %- en:json:html json-tags
^~ %+ weld
"""
const jsonString = '{json-string}';
const allTags = JSON.parse(jsonString);
"""
%- trip
'''
console.log(allTags, "tags")
const tagInput = document.getElementById("tag-input");
const tagStore = document.getElementById("tag-store");
const chipContainer = document.getElementById("chips");
tagInput.addEventListener("keypress", handleKey);
tagInput.addEventListener("keyup", handleBackspace);
const chipList = new Set();
function init(){
setTimeout(() => {
console.log(tagStore.value, "tagstore")
const initTags = tagStore.value.split(",");
for (let tag of initTags){
if (tag){
chipList.add(tag);
loadChip(tag);
}
}
}, 500)
}
init();
function chipString(){
const string = [...chipList].reduce((acc, i) => `${acc},${i}`);
// const string = JSON.stringify(Array.from(chipList));
tagStore.value = string;
}
function addChip(itag){
const tag = itag.toLowerCase();
if (!chipList.has(tag) && tag.length > 0 && tag.length < 32) {
chipList.add(tag);
this.loadChip(tag)
tagInput.value = "";
chipString();
}
}
function removeChip(e){
chipList.delete(e.target.innerText);
chipContainer.removeChild(e.target);
chipString();
}
function loadChip(tag) {
const c = document.createElement('div');
c.classList.add("chip");
c.id = tag;
c.innerText = tag;
c.addEventListener("click", removeChip)
chipContainer.insertBefore(c, tagInput);
}
function handleBackspace(e){
console.log(e.keyCode, "keyup")
console.log(e.target.selectionStart, "keyup")
if (!(e.keyCode === 8 && e.target.selectionStart == 0)) return
const chips = chipContainer.querySelectorAll('.chip');
if (chips.length === 0) return
const to_delete = chipContainer.querySelector('.selected-chip');
if (to_delete) removeChip({target: to_delete});
else {
const last_chip = chips[chips.length - 1];
last_chip.classList.add("selected-chip");
}
}
function handleKey(e) {
// autocomplete?
console.log(e.keyCode, "keycode")
console.log(e)
if (e.keyIdentifier == 'U+000A' || e.keyIdentifier == 'Enter' || e.keyCode == 13) e.preventDefault();
if (e.keyCode === 13) addChip(e.target.value);
}
'''
++ $ ^- manx
=/ [stitle=tape stags=tape stext=tape] ?~ edit ["" "" ""]
:+ (trip title.-.u.edit)
(tags-to-tape:ui tags.-.u.edit)
(content-to-md:ui contents.+.u.edit)
=/ wal ~(. wall src.bowl)
=/ cats boards:wal
=/ whoms (get-contacts:cnt bowl)
=/ usr (user src.bowl whoms 30)
=/ subscription (subscription-type:wal now.bowl)
;div#new-thread.fsy
;style:"{css}"
;+ ?~ edit
;h1.tc:"New Thread"
;h1.tc:"Edit Thread"
;form
=kaji "poke"
=action "add-thread"
;fieldset
;label:"Title"
;input(type "text", name "title", value stitle);
==
;fieldset.board-choice
;label.left
;div:"Board"
;select
=name "board"
;* %+ turn %- sort :_ aor ~(tap in cats) |= nam=@t
=/ name (trip nam)
?: .=(nam 'public')
;option(value name, selected ""):"{name}"
;option(value name):"{name}"
==
==
;label.right
;div:"Tags"
;div#chips
;input(type "text", placeholder "press enter to input individual tags, click on a tag to delete", enterkeyhint "enter", id "tag-input");
;input(type "hidden", id "tag-store", name "tags", value stags);
==
==
==
;fieldset
;label:"Text"
;div#bordered
;textarea(name "text")
; {stext}
==
==
==
;div.f1
;div.author.flex
;div:"Posting as"
;div.flex.ml1
;+ avatar.usr
;+ name.usr
==
==
;input(type "hidden", name "error-div", value "#error-div");
;span#error-div;
;div.buttons
;* ?~ subscription ~
;= ;button#poll-button(type "button")
=kaji "scry"
=swap "add"
=cont "#bordered"
=path "/board/f/poll/new"
;
==
;input#upload-img@"https://s3.spandrell.ch/assets/board/octicons/image-24.svg"(type "image");
==
;* ?~ edit ;+ ;input(type "submit", value "Submit");
;= ;input(type "submit", value "Edit");
;input(type "hidden", name "editing")
=value (enc:kaji pid.-.u.edit)
;
==
==
==
==
==
;script:"{script}"
==
--
|