Skip to content

Commit

Permalink
update last common from feed usage in layout tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Nov 29, 2023
1 parent d68f5a9 commit af62d59
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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";
Expand All @@ -32,6 +35,7 @@ interface TabConfiguration {

const LayoutTabs: FC<LayoutTabsProps> = (props) => {
const { className } = props;
const dispatch = useDispatch();
const history = useHistory();
const { getCommonPagePath, getInboxPagePath, getProfilePagePath } =
useRoutesContext();
Expand Down Expand Up @@ -85,10 +89,15 @@ const LayoutTabs: FC<LayoutTabsProps> = (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));
Expand Down

0 comments on commit af62d59

Please sign in to comment.