tickets
All repositories: gitoria
11.6 KB
// comments.hl — THE COMMENTS BLOCK (layouts#2; shape of hybriel's demo-social-network), pure Hybriel: "1 comment" / "n comments",// then every comment — an avatar (the initial), a bubble with the name, the time, "edited" (the earlier versions fold out) and the// text as formatted Markdown; under it a like (♥ and the count) and, for the comment's author, Edit / Delete — and the form below,// typed in the Markdown editor (components/md-editor). `Comments { comments = list user = me onPost = posted onEdit = edited// onDelete = deleted onLike = liked }`.// GENERIC: no app data, no storage. The host passes the comments (a list of records, below) and the current user's name, and// hands four functions (hybriel#87: a child talks upward by calling a function its host gives it); the host decides what is// stored and gives a new list back — the block shows what it is given. A comment record:// { id, author, when, text (Markdown), likes (a number), liked (true when `user` likes it), history ([{ when, text }], the// earlier versions, oldest first; empty = never edited) }// Edit / Delete show where `author == user`; with `user` empty there is no form and the like does nothing.// The text is drawn by MdEditor's own renderer (`readonly = "true"`). The editor builds its content in the browser once per element;// hl:web builds a composed child anew when a value bound into it changes, so a changed text (an edit here, or a new list from a push)// is drawn anew, and the rows are keyed by `id`, so a deleted comment takes its own editor with it.// The per-comment state (which one is being edited / asked to be deleted) is one member each: one block per page (a composed// component's members are the page's state).import MdEditor from '../md-editor/md-editor.hl'Hybrid comments = []String user = ''onPost = nullonEdit = nullonDelete = nullonLike = nullString oneLabel = 'comment'String manyLabel = 'comments'String emptyText = 'No comments yet.'String placeholder = 'Write a comment…'String postLabel = 'Comment'String editLabel = 'Edit'String deleteLabel = 'Delete'String saveLabel = 'Save'String cancelLabel = 'Cancel'String askText = 'Delete this comment?'String keepLabel = 'Keep'String editedLabel = 'edited'String likeLabel = 'Like'String signInText = ''String editingId = ''String askingId = ''Number formSeq = 0Hybrid shown = rowsOf(comments, user, editingId, askingId)String countText = countOf(comments)Boolean hasNone = comments.length == 0Boolean canWrite = user != ''Boolean cannotWrite = user == '' && signInText != ''Hybrid forms = [{ id = 'new-' + formSeq }]// "1 comment", "n comments"countOf(list) { return list.length == 1 ? '1 ' + oneLabel : list.length + ' ' + manyLabel }initialOf(name) {t = ('' + name).trim()return t == '' ? '?' : t.slice(0, 1).toUpperCase()}// what one comment shows: the host's record, and what this block works out for the user lookingrowsOf(list, me, editing, asking) {out = []for (c of list) {let mine = me != '' && c.author == melet past = c.history != null ? c.history : []let count = c.likes != null ? c.likes : 0let isEditing = mine && '' + c.id == editinglet isAsking = mine && '' + c.id == asking && !isEditingout.push({id = '' + c.idauthor = c.authorinitial = initialOf(c.author)when = c.when != null ? c.when : ''text = c.textlikes = countlikeText = (c.liked == true ? '♥ ' : '♡ ') + countpressed = c.liked == true ? 'true' : 'false'edited = past.length > 0history = pasteditedTitle = past.length == 1 ? 'Edited once' : 'Edited ' + past.length + ' times'mine = mineediting = isEditingnotEditing = !isEditingasking = isAskingoffering = mine && !isEditing && !isAsking})}return out}View {commentsBlock {h2 { class = "comments-count" countText }if (hasNone) { p { class = "comments-empty" emptyText } }ol { class = "comment-list"for (c of shown) {li { class = "comment" 'data-id' = c.idcommentAvatar { 'aria-hidden' = "true" c.initial }commentMain {commentBubble {commentMeta {strong { class = "comment-author" c.author }time { c.when }if (c.edited) { details { class = "comment-history"summary { editedLabel }p { class = "comment-history-title" c.editedTitle }ol { for (h of c.history) { li { time { h.when } pre { h.text } } } }} }}if (c.notEditing) { MdEditor { name = "comment-text" value = c.text readonly = "true" } }if (c.editing) { form { class = "comment-edit" 'data-id' = c.id on submit(e) { emit commentsSave(e) }MdEditor { name = "comment-edit" value = c.text }commentButtons {button { type = "button" class = "comment-cancel" cancelLabel on click(e) { emit commentsCancel(e) } }button { type = "submit" class = "comment-save" saveLabel }}} }}commentActions {button { type = "button" class = "comment-like" 'data-id' = c.id 'aria-pressed' = c.pressed title = likeLabel c.likeText on click(e) { emit commentsLike(e) } }if (c.offering) {button { type = "button" class = "comment-edit-start" 'data-id' = c.id editLabel on click(e) { emit commentsEdit(e) } }button { type = "button" class = "comment-delete" 'data-id' = c.id deleteLabel on click(e) { emit commentsAsk(e) } }}if (c.asking) { commentAsk {span { askText }button { type = "button" class = "comment-delete-yes" 'data-id' = c.id deleteLabel on click(e) { emit commentsDelete(e) } }button { type = "button" class = "comment-delete-keep" keepLabel on click(e) { emit commentsKeep(e) } }} }}}}}}if (canWrite) { for (f of forms) { form { class = "comment-form" on submit(e) { emit commentsPost(e) }MdEditor { name = "comment-new" value = "" placeholder = placeholder rows = 4 }commentButtons { button { type = "submit" class = "comment-post" postLabel } }} } }if (cannotWrite) { p { class = "comments-sign-in" signInText } }}}idOf(e) {el = e.target.closest('[data-id]')return el == null ? '' : el.getAttribute('data-id')}// the Markdown the editor of a form holds now (its hidden field, kept up to date by every keystroke)typedIn(form) {f = form.querySelector('md-editor input.value')return f == null ? '' : f.value}// post: the host is told the text; answering false keeps it in the editor (e.g. the server refused), else the form starts emptyon commentsPost(e) {e.preventDefault()text = typedIn(e.target)if (text.trim() == '' || onPost == null) { return null }ok = onPost(text)if (ok != false) { formSeq = formSeq + 1 }}on commentsEdit(e) {askingId = ''editingId = idOf(e)}on commentsCancel(e) { editingId = '' }on commentsSave(e) {e.preventDefault()id = idOf(e)text = typedIn(e.target)let old = ''for (c of comments) { if ('' + c.id == id) { old = c.text } }if (text.trim() != '' && text != old && onEdit != null) { onEdit(id, text) }editingId = ''}on commentsAsk(e) {editingId = ''askingId = idOf(e)}on commentsKeep(e) { askingId = '' }on commentsDelete(e) {id = idOf(e)askingId = ''if (onDelete != null) { onDelete(id) }}on commentsLike(e) {if (user == '' || onLike == null) { return null }onLike(idOf(e))}// ---- look: the component's own Style; the base look is black, white and the greys #555 #999 #ddd #f2f2f2 (shared/base.hl names them;// root README "Look"); every colour is a semantic token with its base value as fallback, so an app that declares the tokens// (layouts.worldapi.org's theme) restyles it. No frames: the bubble is a grey field on the page, the avatar a grey disc.Style {'comments-block' { display = 'block' color = 'var(--color-text, #000)' }'comments-block h2.comments-count' { margin = '0 0 .8rem' fontSize = '1.05rem' }'comments-block .comments-empty, comments-block .comments-sign-in' { margin = '0 0 .8rem' color = 'var(--color-text-muted, #555)' }'comments-block ol.comment-list' { display = 'flex' flexDirection = 'column' gap = '.9rem' margin = '0 0 1rem' padding = '0' listStyle = 'none' }'comments-block li.comment' { display = 'flex' gap = '.6rem' alignItems = 'flex-start' }'comments-block comment-avatar' { flex = 'none' display = 'grid' placeItems = 'center' width = '2.2rem' height = '2.2rem' borderRadius = '50%' fontWeight = '700' color = 'var(--color-text, #000)' background = 'var(--color-surface, #ddd)' }'comments-block comment-main' { display = 'block' flex = '1' minWidth = '0' }'comments-block comment-bubble' { display = 'block' padding = '.5rem .8rem .6rem' background = 'var(--color-background-sunken, #f2f2f2)' borderRadius = 'var(--radius-small, 5px) var(--radius-large, 10px) var(--radius-large, 10px) var(--radius-large, 10px)' }'comments-block comment-meta' { display = 'flex' flexWrap = 'wrap' alignItems = 'baseline' gap = '.2rem .6rem' marginBottom = '.2rem' }'comments-block .comment-author' { fontSize = '.95rem' color = 'var(--color-text-strong, #000)' overflowWrap = 'anywhere' }'comments-block comment-meta time' { fontSize = '.8rem' color = 'var(--color-text-muted, #555)' }'comments-block details.comment-history' { marginLeft = 'auto' fontSize = '.8rem' color = 'var(--color-text-muted, #555)' }'comments-block details.comment-history[open]' { flexBasis = '100%' marginLeft = '0' }'comments-block details.comment-history summary' { cursor = 'pointer' textDecoration = 'underline' textUnderlineOffset = '.15em' textAlign = 'right' }'comments-block .comment-history-title' { margin = '.3rem 0' fontWeight = '600' }'comments-block details.comment-history ol' { margin = '0' padding = '0' listStyle = 'none' }'comments-block details.comment-history li' { margin = '0 0 .4rem' }'comments-block details.comment-history pre' { margin = '.15rem 0 0' padding = '.4rem .6rem' fontFamily = 'inherit' fontSize = '.85rem' whiteSpace = 'pre-wrap' overflowWrap = 'anywhere' color = 'var(--color-text, #000)' background = 'var(--color-background, #fff)' borderRadius = 'var(--radius-small, 5px)' }'comments-block comment-actions' { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.1rem .3rem' marginTop = '.2rem' fontSize = '.85rem' }'comments-block button' { font = 'inherit' fontWeight = '600' padding = '.25rem .6rem' color = 'var(--color-text-muted, #555)' background = 'transparent' border = '0' borderRadius = 'var(--radius-small, 5px)' cursor = 'pointer' }'comments-block button:hover' { color = 'var(--color-text, #000)' background = 'var(--color-surface, #f2f2f2)' }'comments-block button:focus-visible' { outline = '2px solid var(--color-accent, #555)' outlineOffset = '1px' }'comments-block button.comment-like[aria-pressed="true"]' { color = 'var(--color-text-strong, #000)' }'comments-block comment-ask' { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.3rem' }'comments-block button.comment-delete-yes, comments-block button.comment-save, comments-block button.comment-post' { color = 'var(--color-accent-text, #fff)' background = 'var(--color-accent, #000)' }'comments-block button.comment-delete-yes:hover, comments-block button.comment-save:hover, comments-block button.comment-post:hover' { color = 'var(--color-accent-text, #fff)' background = 'var(--color-accent, #000)' filter = 'brightness(1.3)' }'comments-block form.comment-edit' { display = 'block' marginTop = '.3rem' }'comments-block form.comment-edit md-editor' { background = 'var(--color-background, #fff)' }'comments-block form.comment-form' { display = 'block' }'comments-block comment-buttons' { display = 'flex' justifyContent = 'flex-end' gap = '.4rem' marginTop = '.4rem' }}
Branches
Latest commits
- eef80f55tickets (mission 016): comments through the shared Comments block (layouts#2) — edit (author, earlier versions kept), delete (author, asks; leaves one line in the history), like (members, toggle) on the server (lib/comments.hl, append-only tables), faces + API …/comments/:comment/{edit,delete,like}, push commentChanged; every run of comments is a block in place in the history; Markdown fields on the Hybriel MdEditor (shared/md-editor.js retired: it took over the block's <md-editor>); blocks copied verbatim from components.hybriel 9db927d (tools/sync-components.sh); gates browser 351/0 (old 326/0), events 52/0 (old 52/0)mre
- eb7aeeb9mission brief 016mre
- e4c34759paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
- 26efb23freport w6-events (events test)mre
- c6bfab04mission 015: re-vendor Hybriel 0f396652 (static build), reportmre
- b7ec5981mission brief 015mre
- 5dc68731docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
- 8a460b16mission 014: Apollo's 'stream opened right after the start gets no live events' is not a tickets bug — events.mjs checks early streamsmre
- 6309ca81mission brief 014mre
- c1161469mission 013: GitHub pipe tables on ticket pages (lib/markdown.hl + View + CSS) and re-vendor hybriel master a832f73bmre
- a30b5d12mission brief (w13)mre
- b50a6f93w9 (tickets): re-vendor hybriel 9f912f3b (#146 emit in a lib static, #147) — the 12 live-push emits in lib/api.hl compile as they are; cold start (#148): tests wait TICKETS_COLD_MS for every start, deploy.sh gates browser + events and waits up to 120 s for the URL, container /tmp tmpfs + hybriel-cache volume; events-client stops at EVENTS_MAX inside a chunk; connect.mjs ports by env. bin/hybriel sha256 7421907868ac07d8a7d08296b083c6f8b20407d0e099ce4bebbf7ae053d9060a. Gates (8720–8739): browser 315/0 (+ all-cold 315/0), events 48/0 cold, connect 60/0, short-id 19/0; real-data copy old 0e8a41c vs new: 2,425 reads + 72 writes identical after masking ?v hashes, offline at, route order; event stream on the copy delivers. Not deployed.mre
- 43be6578w9: re-vendor hybriel master edfd400a; event stream imports sseStart/sseSend/sseAlive from hl:http1 (hybriel#144), useTransport gone; tools/import.hl plain declarations. BLOCKED: hybriel-native refuses `emit client` in a static (lib/api.hl) — the server does not compile on edfd400a, gates fail at start; scratch copy without those emits: events 48/0, gate 254 ok up to the first live pushmre
- 0e8a41caw6 (ticket #26): event stream for programs — GET /api/events (Server-Sent Events)mre
- bb64d57cmission 012 (ticket #25 API part): every /api/projects/<x>/… route takes the project's id (12-char record id) as well as its slug, same answers byte for byte; tickets stay under their project, no global /api/tickets/<x>. gate 315/0 (old code: the 13 id checks fail), connect 60/0, live-data copy old vs new 1,484 identical, slug vs id 772 identicalmre
- 7538b034mission 011 (ticket #25 web part): short page URLs /<slug> and /<slug>/<number>; /projects/<slug>, /projects/<slug>/<n>, /projects/<slug>/tickets/<n> and /tickets/<ref> answer 301 (current slug); slug pages moved behind hl:web's own routes after construction (they answered /__hl/* and /components/*.hl); reserved slugs refused; API paths unchanged. gate 293/0, connect 60/0, live-data copy 187/0, API old vs new: only page links differmre
- 0369106emission 010 (code order) 4/4: README file map + import order + 'Same output' test, STATUS (entry, lessons, how to verify), LOG, report; tests/realdata-baseline.mjs + realdata-compare*.py (a cleanup answers the same on live data), tests/letcount.pymre
- a75e0279mission 010 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (456 lets → plain declarations; Hybriel refuses a plain declaration inside a loop on its 2nd pass). gate 249/0, connect 60/0, real-data reads identical, a 50-step write sequence (API + faces) identical to the old codemre
- e9d5c618mission 010 (code order) 2/4: one lib/ file per topic — store.hl split into projects / tickets (+ relations) / events / tickets-helpers, util.hl shared helpers (env, storage dir, URLs, sorts, Vienna time), the function routes out of project.hl into lib/api.hl (thin; auth/filters/Accept in api-helpers.hl), invite + member-removal logic out of the faces/routes into invites.hl / tickets.hl; project.hl is the map. /login/callback gets req + the session store by reference. gate 249/0, connect 60/0, real-data reads identicalmre
- 97e269b5mission 010 (code order) 1/4: .hl files out of the root — lib/ (store, users, connections, invites, migrate, markdown, mdview, import = ticketfile, util = localtime, jsoncheck, api-helpers = api), tools/import.hl, components/styles.hl; import paths only. gate 249/0, connect 60/0, real-data reads identicalmre