From c2cba716976a140114ceccee12e76482c5f261df Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Sun, 28 Jan 2024 02:42:12 +0100 Subject: feat(frontend): rename date formatting utils --- src/frontend/tubo/components/comments.cljs | 2 +- src/frontend/tubo/components/items.cljs | 2 +- src/frontend/tubo/util.cljs | 9 ++++++++- src/frontend/tubo/views/stream.cljs | 6 +----- 4 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/frontend') diff --git a/src/frontend/tubo/components/comments.cljs b/src/frontend/tubo/components/comments.cljs index 4a94e07..8e5e2ec 100644 --- a/src/frontend/tubo/components/comments.cljs +++ b/src/frontend/tubo/components/comments.cljs @@ -34,7 +34,7 @@ [:p.break-words {:dangerouslySetInnerHTML {:__html text}}]] [:div..flex.items-center.my-2 [:div.mr-4 - [:p (util/format-date upload-date)]] + [:p (util/format-date-ago upload-date)]] (when (and like-count (> like-count 0)) [:div.flex.items-center.my-2 [:i.fa-solid.fa-thumbs-up.text-xs] diff --git a/src/frontend/tubo/components/items.cljs b/src/frontend/tubo/components/items.cljs index 3368894..39179e6 100644 --- a/src/frontend/tubo/components/items.cljs +++ b/src/frontend/tubo/components/items.cljs @@ -59,7 +59,7 @@ [:i.fa-solid.fa-video.text-xs] [:p.mx-2 (util/format-quantity stream-count)]]) [:div.flex.my-1.justify-between - [:p (util/format-date upload-date)] + [:p (util/format-date-ago upload-date)] (when view-count [:div.flex.items-center.h-full.pl-2 [:i.fa-solid.fa-eye.text-xs] diff --git a/src/frontend/tubo/util.cljs b/src/frontend/tubo/util.cljs index 9137cbe..ea42ab6 100644 --- a/src/frontend/tubo/util.cljs +++ b/src/frontend/tubo/util.cljs @@ -2,7 +2,14 @@ (:require ["timeago.js" :as timeago])) -(defn format-date +(defn format-date-string + [date] + (-> date + js/Date.parse + js/Date. + .toDateString)) + +(defn format-date-ago [date] (if (-> date js/Date.parse js/isNaN) date diff --git a/src/frontend/tubo/views/stream.cljs b/src/frontend/tubo/views/stream.cljs index dc24ac3..232d134 100644 --- a/src/frontend/tubo/views/stream.cljs +++ b/src/frontend/tubo/views/stream.cljs @@ -97,11 +97,7 @@ (when upload-date [:div.sm:text-base.text-sm.mt-1.whitespace-nowrap [:i.fa-solid.fa-calendar] - [:span.ml-2 - (-> upload-date - js/Date.parse - js/Date. - .toDateString)]])]] + [:span.ml-2 (util/format-date-string upload-date)]])]] (when (and show-description? (not (empty? description))) [:div.py-3.flex.flex-wrap.min-w-full [:div {:dangerouslySetInnerHTML {:__html description} -- cgit v1.2.3