make preview a link, remove js click event on preview

This commit is contained in:
Swrup 2022-02-22 01:48:37 +01:00
parent cc6a4e46dc
commit bb5fb41c2b
3 changed files with 34 additions and 36 deletions

View file

@ -110,6 +110,14 @@ blockquote.blockquote {
display:none; display:none;
} }
a.preview-link {
display: block;
height: 100;
width: 100;
text-decoration: none;
color: unset;
}
.thread-subject { .thread-subject {
margin: auto; margin: auto;
width: 50%; width: 50%;

View file

@ -44,14 +44,6 @@ let render_time date_span =
in in
ignore @@ Jv.set date_span "innerHTML" (Jv.of_string date) ignore @@ Jv.set date_span "innerHTML" (Jv.of_string date)
(* make threads preview clickable to get to thread *)
let preview_click thread_id _event =
log "preview_click@\n";
let url = Format.sprintf "/thread/%s" thread_id in
let window = Jv.get Jv.global "window" in
let location = Jv.get window "location" in
ignore @@ Jv.set location "href" (Jv.of_string url)
let make_pretty _event = let make_pretty _event =
log "make pretty@\n"; log "make pretty@\n";
let document = Jv.get Jv.global "document" in let document = Jv.get Jv.global "document" in
@ -72,23 +64,7 @@ let make_pretty _event =
@@ Jv.call el "addEventListener" @@ Jv.call el "addEventListener"
[| Jv.of_string "click"; Jv.repr (image_click el) |] [| Jv.of_string "click"; Jv.repr (image_click el) |]
in in
List.iter add_click post_images; List.iter add_click post_images
log "make_pretty_catalog@\n";
let previews =
Jv.to_jv_list
@@ Jv.call document "getElementsByClassName"
[| Jv.of_string "thread-preview" |]
in
let add_preview_click el =
let thread_id =
Jv.to_string @@ Jv.call el "getAttribute" [| Jv.of_string "data-id" |]
in
ignore
@@ Jv.call el "addEventListener"
[| Jv.of_string "click"; Jv.repr (preview_click thread_id) |]
in
List.iter add_preview_click previews
(*make pretty after page load*) (*make pretty after page load*)
let () = let () =

View file

@ -103,11 +103,10 @@ let pp_post fmt t =
~some:(fun thread_data -> thread_data.subject) ~some:(fun thread_data -> thread_data.subject)
thread_data_opt thread_data_opt
in in
let pp = (* put inside a link if its a preview *)
let pp_inner_post fmt () =
Format.fprintf fmt Format.fprintf fmt
{| {|
<div class="container">
<div class="post" id="%s">
<div class="thread-subject"> <div class="thread-subject">
%s %s
</div> </div>
@ -115,12 +114,27 @@ let pp_post fmt t =
%a %a
<blockquote class="post-comment">%s</blockquote> <blockquote class="post-comment">%s</blockquote>
%a %a
</div> |}
subject post_info_view () image_view () comment tags_view ()
in
if Option.is_some thread_data_opt then
Format.fprintf fmt
{|
<div class="post" id="%s">
<a class="preview-link" href="/thread/%s">
%a
</a>
</div> </div>
|} |}
id subject post_info_view () image_view () comment tags_view () id id pp_inner_post ()
in else
pp Format.fprintf fmt
{|
<div class="post" id="%s">
%a
</div>
|}
id pp_inner_post ()
let view_post id = let view_post id =
let* post = get_post id in let* post = get_post id in
@ -131,11 +145,11 @@ let pp_thread_preview fmt op =
let thread_preview = let thread_preview =
Format.fprintf fmt Format.fprintf fmt
{| {|
<div class="thread-preview" data-id="%s" > <div class="thread-preview">
%a %a
</div> </div>
|} |}
post.id pp_post pp_post
(Op (thread_data, post)) (Op (thread_data, post))
in in
thread_preview thread_preview