From c0eeb62165a55b5bb7b4067b8216bf92336c324f Mon Sep 17 00:00:00 2001 From: Shoaibdev7 Date: Sat, 10 Aug 2024 01:06:01 +0500 Subject: [PATCH] fix(home-button): ensure home button is always clickable --- src/components/App/MainToolbar/index.tsx | 6 +++++- src/components/App/SideBar/AiView/index.tsx | 10 +++++++--- src/stores/useDataStore/index.ts | 8 ++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/components/App/MainToolbar/index.tsx b/src/components/App/MainToolbar/index.tsx index eced349b6..986ac8094 100644 --- a/src/components/App/MainToolbar/index.tsx +++ b/src/components/App/MainToolbar/index.tsx @@ -9,6 +9,7 @@ import SourcesTableIcon from '~/components/Icons/SourcesTableIcon' import { Flex } from '~/components/common/Flex' import { Text } from '~/components/common/Text' import { useAiSummaryStore } from '~/stores/useAiSummaryStore' +import { useDataStore } from '~/stores/useDataStore' import { useFeatureFlagStore } from '~/stores/useFeatureFlagStore' import { useModal } from '~/stores/useModalStore' import { useUserStore } from '~/stores/useUserStore' @@ -24,7 +25,8 @@ export const MainToolbar = () => { const { open: openFeedbackModal } = useModal('feedback') const navigate = useNavigate() - const { resetAiSummaryAnswer } = useAiSummaryStore() + const { resetAiSummaryAnswer, setNewLoading } = useAiSummaryStore() + const { abortFetchData } = useDataStore((s) => s) const customSchemaFeatureFlag = useFeatureFlagStore((s) => s.customSchemaFeatureFlag) const userFeedbackFeatureFlag = useFeatureFlagStore((s) => s.userFeedbackFeatureFlag) @@ -32,6 +34,8 @@ export const MainToolbar = () => { const sphinxEnabled = isSphinx() const handleLogoClick = () => { + setNewLoading(null) + abortFetchData() resetAiSummaryAnswer() navigate('/') } diff --git a/src/components/App/SideBar/AiView/index.tsx b/src/components/App/SideBar/AiView/index.tsx index 7cc35a7e2..8f9df15f8 100644 --- a/src/components/App/SideBar/AiView/index.tsx +++ b/src/components/App/SideBar/AiView/index.tsx @@ -4,6 +4,7 @@ import styled from 'styled-components' import ArrowBackIcon from '~/components/Icons/ArrowBackIcon' import { Flex } from '~/components/common/Flex' import { useAiSummaryStore } from '~/stores/useAiSummaryStore' +import { useDataStore } from '~/stores/useDataStore' import { colors } from '~/utils/colors' import { AiSearch } from '../AiSearch' import { AiSummary } from '../AiSummary' @@ -12,15 +13,18 @@ export const MENU_WIDTH = 390 // eslint-disable-next-line react/display-name export const AiView = () => { - const { aiSummaryAnswers, resetAiSummaryAnswer, newLoading } = useAiSummaryStore((s) => s) + const { aiSummaryAnswers, resetAiSummaryAnswer, newLoading, setNewLoading } = useAiSummaryStore((s) => s) + const { abortFetchData } = useDataStore((s) => s) + + const navigate = useNavigate() const handleCloseAi = () => { + setNewLoading(null) + abortFetchData() resetAiSummaryAnswer() navigate('/') } - const navigate = useNavigate() - return ( diff --git a/src/stores/useDataStore/index.ts b/src/stores/useDataStore/index.ts index 869b48a8d..46fddd476 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -72,6 +72,7 @@ export type DataStore = { nextPage: () => void setFilters: (filters: Partial) => void setSeedQuestions: (questions: string[]) => void + abortFetchData: () => void } const defaultData: Omit< @@ -244,6 +245,13 @@ export const useDataStore = create()( } } }, + + abortFetchData: () => { + if (abortController) { + abortController.abort('abort') + } + }, + setPage: (page: number) => set({ currentPage: page }), nextPage: () => { const { currentPage, fetchData } = get()