From af62d59cc4e47df2a86ebea55cdabbef6fd542ae Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Wed, 29 Nov 2023 15:24:14 +0400 Subject: [PATCH] update last common from feed usage in layout tabs --- .../components/LayoutTabs/LayoutTabs.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/shared/layouts/CommonSidenavLayout/components/LayoutTabs/LayoutTabs.tsx b/src/shared/layouts/CommonSidenavLayout/components/LayoutTabs/LayoutTabs.tsx index 1931bd7a57..dec0d59f1a 100644 --- a/src/shared/layouts/CommonSidenavLayout/components/LayoutTabs/LayoutTabs.tsx +++ b/src/shared/layouts/CommonSidenavLayout/components/LayoutTabs/LayoutTabs.tsx @@ -1,5 +1,5 @@ import React, { CSSProperties, FC, ReactNode } from "react"; -import { useSelector } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { useHistory } from "react-router-dom"; import classNames from "classnames"; import { @@ -13,7 +13,10 @@ import { useModal } from "@/shared/hooks"; import { useUserActivity, useUserCommonIds } from "@/shared/hooks/useCases"; import { Avatar2Icon, Blocks2Icon, InboxIcon } from "@/shared/icons"; import { CreateCommonPrompt } from "@/shared/layouts/MultipleSpacesLayout/components/Header/components/Navigation/components"; -import { selectCommonLayoutLastCommonFromFeed } from "@/store/states"; +import { + commonLayoutActions, + selectCommonLayoutLastCommonFromFeed, +} from "@/store/states"; import { LayoutTab } from "../../constants"; import { getActiveLayoutTab, getLayoutTabName } from "./utils"; import styles from "./LayoutTabs.module.scss"; @@ -32,6 +35,7 @@ interface TabConfiguration { const LayoutTabs: FC = (props) => { const { className } = props; + const dispatch = useDispatch(); const history = useHistory(); const { getCommonPagePath, getInboxPagePath, getProfilePagePath } = useRoutesContext(); @@ -85,10 +89,15 @@ const LayoutTabs: FC = (props) => { } as CSSProperties; const handleSpacesClick = () => { + if ( + lastCommonIdFromFeed && + lastCommonIdFromFeed.id !== userActivity?.lastVisitedCommon + ) { + dispatch(commonLayoutActions.setLastCommonFromFeed(null)); + } + const commonForRedirectId = - lastCommonIdFromFeed?.id || - userActivity?.lastVisitedCommon || - userCommonIds[0]; + userActivity?.lastVisitedCommon || userCommonIds[0]; if (commonForRedirectId) { history.push(getCommonPagePath(commonForRedirectId));