From 9327e3034e5c78c663168edc66700022764810c7 Mon Sep 17 00:00:00 2001 From: JF-Cozy Date: Tue, 5 Nov 2024 15:27:31 +0100 Subject: [PATCH] feat(Assistant): Move provider from global app to specific places and so give access to router inside the provider. As we lose the context between routes, we have to set the default state to `pending` --- src/assistant/AssistantProvider.jsx | 4 ++-- src/assistant/AssistantWrapperDesktop.jsx | 9 ++++--- src/assistant/Views/AssistantDialog.jsx | 12 ++++++++-- src/assistant/Views/SearchDialog.jsx | 10 ++++---- src/components/AppWrapper.jsx | 29 ++++++++++------------- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/assistant/AssistantProvider.jsx b/src/assistant/AssistantProvider.jsx index ed7728471..b2cc4c255 100644 --- a/src/assistant/AssistantProvider.jsx +++ b/src/assistant/AssistantProvider.jsx @@ -22,7 +22,7 @@ const AssistantProvider = ({ children }) => { const client = useClient() const [assistantState, setAssistantState] = useState({ message: {}, - status: 'idle', + status: 'pending', messagesId: [] }) @@ -82,7 +82,7 @@ const AssistantProvider = ({ children }) => { () => setAssistantState({ message: {}, - status: 'idle', + status: 'pending', messagesId: [] }), [] diff --git a/src/assistant/AssistantWrapperDesktop.jsx b/src/assistant/AssistantWrapperDesktop.jsx index 2b34d7fe1..75af8fd29 100644 --- a/src/assistant/AssistantWrapperDesktop.jsx +++ b/src/assistant/AssistantWrapperDesktop.jsx @@ -2,13 +2,16 @@ import React from 'react' import SearchBar from './Search/SearchBar' import SearchProvider from './Search/SearchProvider' +import AssistantProvider from './AssistantProvider' const AssistantWrapperDesktop = () => { return (
- - - + + + + +
) } diff --git a/src/assistant/Views/AssistantDialog.jsx b/src/assistant/Views/AssistantDialog.jsx index f774a0156..df2d733c2 100644 --- a/src/assistant/Views/AssistantDialog.jsx +++ b/src/assistant/Views/AssistantDialog.jsx @@ -6,7 +6,7 @@ import { useBreakpoints } from 'cozy-ui/transpiled/react/providers/Breakpoints' import Conversation from '../Conversations/Conversation' import ConversationBar from '../Conversations/ConversationBar' -import { useAssistant } from '../AssistantProvider' +import AssistantProvider, { useAssistant } from '../AssistantProvider' const AssistantDialog = () => { const { assistantState } = useAssistant() @@ -36,4 +36,12 @@ const AssistantDialog = () => { ) } -export default AssistantDialog +const AssistantDialogWithProviders = () => { + return ( + + + + ) +} + +export default AssistantDialogWithProviders diff --git a/src/assistant/Views/SearchDialog.jsx b/src/assistant/Views/SearchDialog.jsx index de125b562..4e81f9f5e 100644 --- a/src/assistant/Views/SearchDialog.jsx +++ b/src/assistant/Views/SearchDialog.jsx @@ -5,7 +5,7 @@ import flag from 'cozy-flags' import { FixedDialog } from 'cozy-ui/transpiled/react/CozyDialogs' import SearchProvider from '../Search/SearchProvider' -import { useAssistant } from '../AssistantProvider' +import AssistantProvider, { useAssistant } from '../AssistantProvider' import { makeConversationId } from '../helpers' import ResultMenuContent from '../ResultMenu/ResultMenuContent' import { useSearch } from '../Search/SearchProvider' @@ -54,9 +54,11 @@ const SearchDialog = () => { const SearchDialogWithProviders = () => { return ( - - - + + + + + ) } diff --git a/src/components/AppWrapper.jsx b/src/components/AppWrapper.jsx index cd61aa33b..c03870643 100644 --- a/src/components/AppWrapper.jsx +++ b/src/components/AppWrapper.jsx @@ -21,7 +21,6 @@ import { useWallpaperContext } from 'hooks/useWallpaperContext' import schema from '../schema' import { ConditionalWrapper } from './ConditionalWrapper' -import AssistantProvider from 'assistant/AssistantProvider' import { WallPaperProvider } from 'hooks/useWallpaperContext' import { SectionsProvider } from './Sections/SectionsContext' const dictRequire = lang => require(`locales/${lang}.json`) @@ -116,22 +115,20 @@ const AppWrapper = ({ children }) => { - - - ( - - {children} - - )} - > - + + ( + {children} - - - - + + )} + > + + {children} + + +