From 4521aeb456636f012ba76fcd9f598afa1a0a486d Mon Sep 17 00:00:00 2001 From: iower Date: Thu, 14 Dec 2023 21:11:50 +0500 Subject: [PATCH] Initial mark as done --- src/components/left/UluInboxChats.tsx | 13 ++++++++++++- src/hooks/useStorage.ts | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/left/UluInboxChats.tsx b/src/components/left/UluInboxChats.tsx index 65d8465981..1bcf20417f 100644 --- a/src/components/left/UluInboxChats.tsx +++ b/src/components/left/UluInboxChats.tsx @@ -1,5 +1,5 @@ import type { FC } from '../../lib/teact/teact'; -import React, { memo } from '../../lib/teact/teact'; +import React, { memo, useEffect } from '../../lib/teact/teact'; import type { GlobalState } from '../../global/types'; import type { FolderEditDispatch } from '../../hooks/reducers/useFoldersReducer'; @@ -9,10 +9,12 @@ import { ANIMATION_END_DELAY, IS_STORIES_ENABLED } from '../../config'; import buildClassName from '../../util/buildClassName'; import { ANIMATION_DURATION } from '../story/helpers/ribbonAnimation'; +import useDone from '../../hooks/useDone'; import useForumPanelRender from '../../hooks/useForumPanelRender'; import useHistoryBack from '../../hooks/useHistoryBack'; import useLang from '../../hooks/useLang'; import useShowTransition from '../../hooks/useShowTransition'; +import { useStorage } from '../../hooks/useStorage'; import useLeftHeaderButtonRtlForumTransition from './main/hooks/useLeftHeaderButtonRtlForumTransition'; import StoryRibbon from '../story/StoryRibbon'; @@ -48,6 +50,15 @@ const UluInboxChats: FC = ({ }) => { const lang = useLang(); + const { doneAllReadChats } = useDone(); + const { isInitialMarkAsDone, setIsInitialMarkAsDone } = useStorage(); + useEffect(() => { + if (!isInitialMarkAsDone) { + setIsInitialMarkAsDone(true); + doneAllReadChats(); + } + }, [isInitialMarkAsDone, setIsInitialMarkAsDone, doneAllReadChats]); + useHistoryBack({ isActive, onBack: onReset, diff --git a/src/hooks/useStorage.ts b/src/hooks/useStorage.ts index 55140cbf73..df9b24184e 100644 --- a/src/hooks/useStorage.ts +++ b/src/hooks/useStorage.ts @@ -17,6 +17,11 @@ export function useStorage() { const [doneChatIds, setDoneChatIds] = useLocalStorage('ulu_done_chat_ids', []); + const [ + isInitialMarkAsDone, + setIsInitialMarkAsDone, + ] = useLocalStorage('ulu_is_initial_mark_as_done', false); + return { isAutoDoneEnabled, setIsAutoDoneEnabled, @@ -28,6 +33,8 @@ export function useStorage() { setIsFoldersTreeEnabled, doneChatIds, setDoneChatIds, + isInitialMarkAsDone, + setIsInitialMarkAsDone, }; }