Skip to content

Commit

Permalink
feat(Assistant): Move provider from global app to specific places
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
JF-Cozy committed Nov 5, 2024
1 parent c771331 commit 9327e30
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/assistant/AssistantProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const AssistantProvider = ({ children }) => {
const client = useClient()
const [assistantState, setAssistantState] = useState({
message: {},
status: 'idle',
status: 'pending',
messagesId: []
})

Expand Down Expand Up @@ -82,7 +82,7 @@ const AssistantProvider = ({ children }) => {
() =>
setAssistantState({
message: {},
status: 'idle',
status: 'pending',
messagesId: []
}),
[]
Expand Down
9 changes: 6 additions & 3 deletions src/assistant/AssistantWrapperDesktop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="app-list-wrapper u-mb-3 u-mh-auto u-w-100">
<SearchProvider>
<SearchBar />
</SearchProvider>
<AssistantProvider>
<SearchProvider>
<SearchBar />
</SearchProvider>
</AssistantProvider>
</div>
)
}
Expand Down
12 changes: 10 additions & 2 deletions src/assistant/Views/AssistantDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -36,4 +36,12 @@ const AssistantDialog = () => {
)
}

export default AssistantDialog
const AssistantDialogWithProviders = () => {
return (
<AssistantProvider>
<AssistantDialog />
</AssistantProvider>
)
}

export default AssistantDialogWithProviders
10 changes: 6 additions & 4 deletions src/assistant/Views/SearchDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -54,9 +54,11 @@ const SearchDialog = () => {

const SearchDialogWithProviders = () => {
return (
<SearchProvider>
<SearchDialog />
</SearchProvider>
<AssistantProvider>
<SearchProvider>
<SearchDialog />
</SearchProvider>
</AssistantProvider>
)
}

Expand Down
29 changes: 13 additions & 16 deletions src/components/AppWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -116,22 +115,20 @@ const AppWrapper = ({ children }) => {
<CozyTheme>
<ThemeProvider>
<AlertProvider>
<AssistantProvider>
<ReduxProvider store={store}>
<ConditionalWrapper
condition={persistor}
wrapper={children => (
<PersistGate loading={null} persistor={persistor}>
{children}
</PersistGate>
)}
>
<Inner lang={lang} context={context}>
<ReduxProvider store={store}>
<ConditionalWrapper
condition={persistor}
wrapper={children => (
<PersistGate loading={null} persistor={persistor}>
{children}
</Inner>
</ConditionalWrapper>
</ReduxProvider>
</AssistantProvider>
</PersistGate>
)}
>
<Inner lang={lang} context={context}>
{children}
</Inner>
</ConditionalWrapper>
</ReduxProvider>
</AlertProvider>
</ThemeProvider>
</CozyTheme>
Expand Down

0 comments on commit 9327e30

Please sign in to comment.