commit 9aa93b3c5b1cc80372b068ef8065f1c962d0ef2a
parent 0a463c4eca0502530ed799f1090f1d5803ec23ff
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Fri, 22 May 2026 18:58:43 +0000
post-fragment function is refactored
Diffstat:
| M | src/cgi.scm | | | 68 | ++++++++++++++++++++++---------------------------------------------- |
1 file changed, 22 insertions(+), 46 deletions(-)
diff --git a/src/cgi.scm b/src/cgi.scm
@@ -488,56 +488,32 @@ END-OF-CSS
(loop (- tid 1))))))
id))
-(define (bad-post-fragment id ptime section title url comm-url tags mark)
- `(form (@ (method "POST") (action "do-undelete")
- (id ,(conc "post-" id)) (class "bad-post")
- (hx-swap "outerHTML") (hx-post "xdo-undelete"))
- (input (@ (type "submit") (name "submit") (class lsub) (value "Restore")))
+(define (post-fragment id mark ptime section title url comm-url tags)
+ (let* ((data (case mark
+ ((0) '("unmarked" "unmarked" "Mark" "Delete"))
+ ((1) '("marked" "marked" "Edit" "Unmark"))
+ ((2) '("locked" "locked" "Push" "Unlock"))
+ ((3) '("locked" "protected" "Push" "Unlock"))
+ (else '("undelete" "bad" "Restore" "Hide"))))
+ (action (car data))
+ (class (cadr data))
+ (llabel (caddr data))
+ (rlabel (cadddr data)))
+ `(form (@ (method "POST") (action ,(conc "do-" action))
+ (id ,(if (positive? id) (conc "post-" id) (conc "entry" id)))
+ (class ,(conc class "-post"))
+ (hx-swap "outerHTML") (hx-post ,(conc "xdo-" action)))
+ (input (@ (type "submit") (name "submit") (class lsub) (value ,llabel)))
(div (@ (class "form-body"))
,(post-p-fragment id ptime section title url comm-url tags))
(input (@ (type "hidden") (name "id") (value ,id)))
,@(if (<= -5 mark -1)
- `((input (@ (type "hidden") (name "from") (value ,mark)))
- (input (@ (type "submit") (name "submit") (class rsub) (value "Hide"))))
- '())))
-
-(define (locked-post-fragment id ptime section title url comm-url tags mark)
- `(form (@ (method "POST") (action "do-locked")
- (id ,(conc "post-" id))
- (class ,(if (> mark 2) "protected-post" "locked-post"))
- (hx-swap "outerHTML") (hx-post "xdo-locked"))
- (input (@ (type "submit") (name "submit") (class lsub) (value "Push")))
- (div (@ (class "form-body"))
- ,(post-p-fragment id ptime section title url comm-url tags))
- (input (@ (type "hidden") (name "id") (value ,id)))
- (input (@ (type "submit") (name "submit") (class rsub) (value "Unlock")))))
-
-(define (marked-post-fragment id ptime section title url comm-url tags)
- `(form (@ (method "POST") (action "do-marked")
- (id ,(conc "post-" id)) (class "marked-post")
- (hx-swap "outerHTML") (hx-post "xdo-marked"))
- (input (@ (type "submit") (name "submit") (class lsub) (value "Edit")))
- (div (@ (class "form-body"))
- ,(post-p-fragment id ptime section title url comm-url tags))
- (input (@ (type "hidden") (name "id") (value ,id)))
- (input (@ (type "submit") (name "submit") (class rsub) (value "Unmark")))))
-
-(define (unmarked-post-fragment id ptime section title url comm-url tags)
- `(form (@ (method "POST") (action "do-unmarked")
- (id ,(conc "post-" id)) (class "unmarked-post")
- (hx-swap "outerHTML") (hx-post "xdo-unmarked"))
- (input (@ (type "submit") (name "submit") (class lsub) (value "Mark")))
- (div (@ (class "form-body"))
- ,(post-p-fragment id ptime section title url comm-url tags))
- (input (@ (type "hidden") (name "id") (value ,id)))
- (input (@ (type "submit") (name "submit") (class rsub) (value "Delete")))))
-
-(define (post-fragment id mark ptime section title url comm-url tags)
- (case mark
- ((0) (unmarked-post-fragment id ptime section title url comm-url tags))
- ((1) (marked-post-fragment id ptime section title url comm-url tags))
- ((2 3) (locked-post-fragment id ptime section title url comm-url tags mark))
- (else (bad-post-fragment id ptime section title url comm-url tags mark))))
+ `((input (@ (type "hidden") (name "from") (value ,mark))))
+ '())
+ ,@(if (<= -5 mark 3)
+ `((input (@ (type "submit") (name "submit")
+ (class rsub) (value ,rlabel))))
+ '()))))
(define (post-htmx id)
(htmx-output