add image-overlay

This commit is contained in:
Swrup 2025-04-15 08:39:45 +02:00
parent cd4fc18585
commit 26b17f57cd
10 changed files with 132 additions and 77 deletions

View file

@ -154,54 +154,20 @@ let backlinks t_s post =
let l = List.map (post_id_quote t_s) post.backlinks in
El.div ~at:[ class' "post-replies" ] l
let image t_s ?(is_vignette = false) post =
let image _t_s ?(is_vignette = false) post =
match post.image_info with
| None -> None
| Some image -> (
(* TODO show image dimension/name *)
let mk is_small =
let class_small =
if is_small then [ class' "post-image-small" ] else []
in
let sizes =
[ mk_at "width"
(string_of_int (if is_small then image.thumb_w else image.w))
; mk_at "height"
(string_of_int (if is_small then image.thumb_h else image.h))
]
in
let url =
src
@@
if is_small then Fmt.str "/img/s/%d" post.id
else Fmt.str "/img/%d" post.id
in
let at =
class_small @ sizes
@ url
:: [ class' "post-image"
; alt image.alt
; title image.alt
; mk_at "data-id" (string_of_int post.id)
; mk_at "loading" "lazy"
]
in
El.img ~at ()
let img_small =
Html_util.mk_image ~is_small:true (Img_info.Post (post.id, image))
in
let img_small, img_big = (mk true, mk false) in
let el = El.div ~at:[ class' "post-image-div" ] [ img_small ] in
match is_vignette with
| true -> Some el
| false ->
(* swap img_(small/big) on click *)
hold_on el Ev.click (fun _ev -> Events.send_action (Image_click post.id));
let img_s =
S.map (fun t -> t.Model.opened_image) t_s
|> S.map (function
| Some id when Int.equal id post.id -> [ img_big ]
| Some _ | None -> [ img_small ] )
in
Elr.def_children el img_s;
hold_on el Ev.click (fun _ev ->
let v = Img_info.Post (post.id, image) in
Events.send_action (Image_change (Some v)) );
Some el )
let comment =