tickets
All repositories: gitoria
6.4 KB
# CommentsA comment thread (layouts#2; shape of hybriel's demo-social-network): **"1 comment" / "n comments"**, then every comment — anavatar (the initial of the name), 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** (Delete asksfirst) — and the **form below**, typed in the Markdown editor. Live demo: https://components.hybriel.worldapi.org/comments## FilesCopy `components/comments/` (`comments.hl`) **and** `components/md-editor/` (`md-editor.hl`, mission 006 or later — it needs its`readonly` attribute): `comments.hl` imports `../md-editor/md-editor.hl`. Both carry their own `Style`; every colour is a semantictoken with a black/white/grey fallback (root README "Look").## Use it in an appThe block is generic: no app data, no storage. **The host passes the comments and the current user, hears what the user did throughfour functions it hands (hybriel#87), decides what is stored, and gives a new list back** — the block shows the list it is given.```import Comments from './comments/comments.hl'Hybrid thread = commentsOf(ticketId, me) // the app's own records, in the shape belowString me = session != null ? session.user.name : ''posted = (text) => { thread = emit server commentPost(ticketId, text) } // the face stores it and answers the new listedited = (id, text) => { thread = emit server commentEdit(ticketId, id, text) }deleted = (id) => { thread = emit server commentDelete(ticketId, id) }liked = (id) => { thread = emit server commentLike(ticketId, id) }View { Comments { comments = thread user = me onPost = posted onEdit = edited onDelete = deleted onLike = liked } }```### Data in| Member | Meaning ||---|---|| `comments` | the list, oldest first: `{ id, author, when, text, likes, liked, history }` (below) || `user` | the current user's name (compared with `author`); `''` = nobody: no form, no Edit / Delete, the like does nothing |A comment: `id` (any text or number, unique in the list — the rows are keyed by it), `author` (the name shown, and who may edit),`when` (the time as the app writes it, e.g. "Oct 17, 09:12"), `text` (Markdown), `likes` (a number), `liked` (`true` when `user`likes it), `history` (the earlier versions, oldest first: `[{ when, text }]`; empty or missing = never edited). The app checksthe rights again on the server — the block only hides what the user may not do.### Data out — the four functions| Function | Called when | With ||---|---|---|| `onPost(text)` | the form is sent (the Comment button, or Ctrl+Enter in the editor); empty text sends nothing | the Markdown typed || `onEdit(id, text)` | Save of an edit with a changed, non-empty text | the comment's id, the new Markdown || `onDelete(id)` | Delete, then Delete again in "Delete this comment?" (Keep takes it back) | the comment's id || `onLike(id)` | the like is pressed (only with a `user`) | the comment's id — the host switches `liked` and the count |With `attach = "true"` (below) it is `onPost(text, files)`: `files` are the browser Files waiting in the form (a post may be files only).`onPost` may answer `false` to keep the text in the editor (e.g. the server refused it); anything else empties the form. Edit / Deleteshow only where `author == user`.### Attachments (`attach = "true"`, optional)Without `attach` nothing changes (`onPost(text)`, no files). With it the form sits inside the shared FilesUpload (pick mode, importedfrom `../files-upload/files-upload.hl` — copy that folder too): choose / camera / drop / paste files, they wait as thumbnails, and`onPost(text, files)` gets the text and the browser Files; the host stores them. Answering `false` keeps text and files. Members:`maxFileSize` (bytes per file), `accept`, `attachText`, `chooseText`, `cameraText`, `filesLabel`. The editor in the form has`files = "off"` (no File button; pasted / dropped files go to the FilesUpload).**Files per comment:** a comment record may carry `files: [{ name, url, image, size }]`. Pictures (`image`) show as 6 rem thumbnails(`a.comment-thumb`, opens the full picture in a new tab); other files are rows (`a.comment-file`: kind, name, size). A file without`url` shows as a row without link (`span.comment-file`) — e.g. for users who may not fetch it. Sizes are written by integer maths.### Texts`oneLabel` ("comment"), `manyLabel` ("comments"), `emptyText` ("No comments yet."), `placeholder` ("Write a comment…"), `postLabel`("Comment"), `editLabel`, `deleteLabel`, `saveLabel`, `cancelLabel`, `askText` ("Delete this comment?"), `keepLabel`, `editedLabel`("edited"), `likeLabel` (the like's title), `signInText` (shown instead of the form when there is no user; empty = nothing).## How it is built- Every text is drawn by MdEditor's own renderer: `MdEditor { value = text readonly = "true" }` — the same Markdown subset the formmakes, so a comment looks as it was typed. MdEditor builds its content in the browser once per element; hl:web builds a composedchild anew when a value bound into it changes, so a changed text — an edit here, or a new list the host got from a push — is drawnanew (gate: "bob edits his comment elsewhere"), and a deleted comment takes its row with it (the rows are keyed by `id`).- The text is drawn in the browser: the server's HTML carries each comment's Markdown in the editor's hidden field, not formatted.- The form is an MdEditor in a one-row list too: after a post its key changes and an empty editor takes its place.- Which comment is being edited / asked about is one member each (`editingId`, `askingId`): **one block per page** (a composedcomponent's members are the page's state).- "edited" is a `<details>` with the earlier versions as their Markdown source (oldest first, "Edited once" / "Edited n times").- Pure Hybriel: no `.js`, no network calls of its own.## Markup`<comments-block>`: `h2.comments-count`, `p.comments-empty`, `ol.comment-list` > `li.comment[data-id]` > `<comment-avatar>` +`<comment-main>` (`<comment-bubble>` with `<comment-meta>` — `strong.comment-author`, `time`, `details.comment-history` — and thetext `md-editor[data-readonly="true"]` or `form.comment-edit`; `<comment-actions>` with `button.comment-like[aria-pressed]`,`button.comment-edit-start`, `button.comment-delete`, `<comment-ask>`), then `form.comment-form` (MdEditor + `button.comment-post`)or `p.comments-sign-in`.
Branches
Latest commits
- 31cabfccmission 021: E2E script, report, LOG, STATUSmre
- 6aea8683editor look: .empty rule only for p.empty, files off where tickets has no upload, state note one line, events test scrolls the editor into view; synced md-editor (components d702d76+6f27ad3); gate 377/0, events 52/0mre
- dce6ffa6Merge branch 'w28-deflake'mre
- 536092a1tickets (mission 019): de-flake the m016 comment clicks (B: unliked) — calmClick waits until the button stops moving; test only, no app changemre
- 9c5fd42amission 020: attachments E2E proof (lisbeth Chrome, real-data copy), reportmre
- 1206404fREADME attachments, report 018, LOG/STATUSmre
- 3d9e7f3ctests: m017 gate fixes (list count, waits before delete clicks); gate 373/0mre
- dd41d5bcre-sync components 15be2ac; mission 018mre
- 420ad1bbtickets (mission 017 WIP, tickets#27): comment attachments — lib/attachments.hl (storage/attachments, limits, type by content, members-only GET /api/attachments/:id, delete drops, edit keeps), multipart POST …/comments (lib/multipart.hl), Respond block in FilesUpload (blocks verbatim from components w27c 1f8d79d), gate m017 checks written (not yet run); report, LOG, STATUSmre
- a7a1380dmission brief 017mre
- f83d9c0dtickets (mission 016): report reports/016-comments-block.md, LOG, STATUS, README gate countmre
- 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