gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit29f63d0129f63d01md-editor: Style in the language's form (nested like the View, one declaration per line, bare @media)mre29f63d01/components/comments/demo.hl

3.9 KB

  1. // demo.hl — `/comments`: the comments block on a page with the mock thread of lib/comments.hl. WHAT IS STORED IS THE APP'S DECISION:
  2. // the block tells this page (post, edit, delete, like) through the four functions it is handed; the page makes a new list and hands it
  3. // back. "You are" switches the current user, so Edit / Delete show only on that user's comments; "nobody" reads only.
  4. // ATTACHMENTS (attach = "true", mission 009): files dropped, chosen or pasted into the form go with the post — the page's face stores
  5. // them (one day, lib/uploads.hl) and the new comment shows them: pictures as thumbnails, other files as rows. Up to 2 MB per file.
  6. parent '../main.hl'
  7. import Comments from './comments.hl'
  8. import { demoComments, withNew, withEdit, without, withLike, attachedOf } from '../../lib/comments.hl'
  9. import { storeMdFiles } from '../../lib/uploads.hl'
  10. __title = 'Comments · Hybriel components'
  11. Hybrid thread = demoComments
  12. String me = 'alice'
  13. // who is chosen: its button is filled and pressed, the others quiet (a View attribute cannot hold an expression, so each is a member)
  14. String aliceClass = ''
  15. String bobClass = 'quiet'
  16. String nobodyClass = 'quiet'
  17. String alicePressed = 'true'
  18. String bobPressed = 'false'
  19. String nobodyPressed = 'false'
  20. String meText = 'now alice'
  21. String told = 'nothing yet'
  22. Number seq = 0
  23. posted = (text, files) => {
  24. let stored = []
  25. if (files.length > 0) {
  26. stored = emit server demoAttach(files)
  27. if (stored == null) {
  28. told = 'post refused'
  29. return false
  30. }
  31. }
  32. seq = seq + 1
  33. thread = withNew(thread, me, text, seq, stored)
  34. told = files.length > 0 ? 'post with ' + files.length + ' files' : 'post'
  35. }
  36. edited = (id, text) => {
  37. thread = withEdit(thread, id, text)
  38. told = 'edit ' + id
  39. }
  40. deleted = (id) => {
  41. thread = without(thread, id)
  42. told = 'delete ' + id
  43. }
  44. // what a push from elsewhere does in an app (another user edits): the page gets a new list, nobody pressed anything in this block
  45. on demoElsewhere(e) { thread = withEdit(thread, 'c2', 'Changed **elsewhere**: bob edited it in another tab.') }
  46. liked = (id) => {
  47. thread = withLike(thread, id)
  48. told = 'like ' + id
  49. }
  50. View {
  51. commentsDemo {
  52. h1 { "Comments" }
  53. p { class = "muted" "A thread: avatar, name, time, “edited” with the earlier versions, the text as Markdown, a like, and Edit / Delete on your own comments. Type a new one below in the Markdown editor." }
  54. p { class = "comments-who" role = "group" 'aria-label' = "Act as" "You are:"
  55. button { type = "button" id = "as-alice" class = aliceClass 'aria-pressed' = alicePressed "alice" on click(e) { emit demoAs('alice') } }
  56. button { type = "button" id = "as-bob" class = bobClass 'aria-pressed' = bobPressed "bob" on click(e) { emit demoAs('bob') } }
  57. button { type = "button" id = "as-nobody" class = nobodyClass 'aria-pressed' = nobodyPressed "nobody" on click(e) { emit demoAs('') } }
  58. output { id = "comments-me" class = "muted" meText }
  59. }
  60. p { button { type = "button" id = "elsewhere" "bob edits his comment elsewhere (a push)" on click(e) { emit demoElsewhere(e) } } }
  61. Comments { comments = thread user = me onPost = posted onEdit = edited onDelete = deleted onLike = liked signInText = "Choose a user above to comment." attach = "true" maxFileSize = 2097152 }
  62. p { class = "muted" "The page was told: " output { id = "comments-told" told } }
  63. p { a { id = "readme" href = "/comments/README.md" "README (how to use it)" } }
  64. }
  65. }
  66. on demoAs(who) {
  67. me = who
  68. aliceClass = who == 'alice' ? '' : 'quiet'
  69. bobClass = who == 'bob' ? '' : 'quiet'
  70. nobodyClass = who == '' ? '' : 'quiet'
  71. alicePressed = who == 'alice' ? 'true' : 'false'
  72. bobPressed = who == 'bob' ? 'true' : 'false'
  73. nobodyPressed = who == '' ? 'true' : 'false'
  74. meText = 'now ' + (who == '' ? 'nobody' : who)
  75. }
  76. // the files of a new comment: stored for a day, what the block shows of each back (the demo's decision: lib/uploads.hl)
  77. on server demoAttach(files) { return attachedOf(files, storeMdFiles(files)) }

Branches

Latest commits

  • 29f63d01md-editor: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
  • 869f49c7files-upload: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
  • f60dab20month-view: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
  • 5b3c349aRe-vendor to Hybriel set day35 (cb9e480d): plugins core and web sources, README vendoring notemre
  • 3449b117components: a startup error prints its message before exit 1 (hybriel#247)mre
  • 59704ce1Merge branch 'n5b-pipes'mre
  • 23b9164aMdEditor: a clipboard whose text is only the names or file:// paths of its files (a file manager copy) is about the files, as before; any other text wins (tickets#49); gate casesmre
  • b0f1ec28MdEditor: a clipboard with text always pastes the text, also when a picture is on it too (a spreadsheet or office app), files on or off; a picture alone still goes to the files; real Ctrl+V gate tests/md-paste-files.mjs (tickets#49)mre
  • ad4e929bMdEditor: pipe rows without a delimiter row are a table (first row = header, short rows padded, written back without an invented | --- | line) (notes#5)mre
  • 4bd11128MdEditor: the Table button's empty table is written as a real pipe table (empty cells), so it survives the source switch, a save and a reload (notes#7)mre
  • 7437e32bMdEditor draws its surface at once when claimed from server HTML: 1 ms mount animation, the first editor mounts all editors of the pagemre
  • 5de0264cRe-vendor onto Hybriel master acaceaf3 (set-day27b): binary, lib and plugins; exit 1 on a startup fault; .gitignore binmre
  • 79c77e7dMerge sb3-standby: components deploys through its standbymre
  • c5442043components: no jobs switch needed in the standbymre
  • 8d2fb24ccomponents: a standby container (port 45016, profile standby); deploy hands over through standby-swap.sh without a gapmre
  • c2834dd3Merge mr-fixes: media player state after a queue pick, Range handling, cover-less audio, accessibility labelsmre
  • 354fe3c6Media player: audio without a cover starts and shows its time (the mount tick sits on the seek bar, which every item has); the speed button names the current speed, the seek slider says its time in words; a gate page for the first render on cover-less audio and a fourth demo queue item without a covermre
  • ee4aee1eMedia player: a new queue item shows its own speed, mute, play state and time and starts when asked, also for two videos in a row; the media route reads suffix ranges and ignores range lists and garbage instead of answering 500; stronger gate checks (the 10 percent drag, the played bar, the queue tap)mre
  • 9a4f9b31Merge mp-player: media served from the committed filesmre
  • ab96e686Media route: serve the demo's media from the committed files in components/media-player (storage/ is not in git, the deploy gate found no files)mre