From fa79a0cd5d361810efd98e6e67324704586c0e0e Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 6 Jul 2024 09:24:37 +0300 Subject: [PATCH] localstorage-fix --- src/components/Article/CommentsTree.tsx | 4 +- src/components/Article/FullArticle.tsx | 48 +++++++++---------- .../_shared/DarkModeToggle/DarkModeToggle.tsx | 5 +- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index d8ab01f3..7aeb71bf 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -52,10 +52,10 @@ export const CommentsTree = (props: Props) => { }) const { seen } = useFeed() const shoutLastSeen = createMemo(() => seen()[props.shoutSlug] ?? 0) - const currentDate = new Date() - const setCookie = () => localStorage?.setItem(`${props.shoutSlug}`, `${currentDate}`) onMount(() => { + const currentDate = new Date() + const setCookie = () => localStorage?.setItem(`${props.shoutSlug}`, `${currentDate}`) if (!shoutLastSeen()) { setCookie() } else if (currentDate.getTime() > shoutLastSeen()) { diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index 2ae68a07..5241c6d8 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -91,7 +91,7 @@ export const FullArticle = (props: Props) => { const mainTopic = createMemo(() => { const mainTopicSlug = (props.article?.topics?.length || 0) > 0 ? props.article.main_topic : null - const mt = props.article.topics?.find((tpc: Maybe) => tpc?.slug === mainTopicSlug) + const mt = props.article?.topics?.find((tpc: Maybe) => tpc?.slug === mainTopicSlug) if (mt) { mt.title = lang() === 'en' ? capitalize(mt.slug.replace(/-/, ' ')) : mt.title return mt @@ -107,10 +107,10 @@ export const FullArticle = (props: Props) => { } const body = createMemo(() => { - if (props.article.layout === 'literature') { + if (props.article?.layout === 'literature') { try { if (props.article?.media) { - const media = JSON.parse(props.article.media) + const media = JSON.parse(props.article?.media) if (media.length > 0) { return media[0].body } @@ -119,7 +119,7 @@ export const FullArticle = (props: Props) => { console.error(error) } } - return props.article.body + return props.article?.body || '' }) const imageUrls = createMemo(() => { @@ -362,19 +362,19 @@ export const FullArticle = (props: Props) => { onClick={handleArticleBodyClick} > {/*TODO: Check styles.shoutTopic*/} - +
-

{props.article.title}

- -

{props.article.subtitle}

+

{props.article?.title || ''}

+ +

{props.article?.subtitle || ''}

- + {(a: Maybe, index: () => number) => ( <> 0}>, @@ -385,39 +385,39 @@ export const FullArticle = (props: Props) => {
{props.article.cover_caption -
+
- -
+ +
- + 0}>
- +
- +
{(m: MediaItem) => ( @@ -576,9 +576,9 @@ export const FullArticle = (props: Props) => {
- +