Skip to content

Commit 9327e30

Browse files
committed
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`
1 parent c771331 commit 9327e30

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

src/assistant/AssistantProvider.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const AssistantProvider = ({ children }) => {
2222
const client = useClient()
2323
const [assistantState, setAssistantState] = useState({
2424
message: {},
25-
status: 'idle',
25+
status: 'pending',
2626
messagesId: []
2727
})
2828

@@ -82,7 +82,7 @@ const AssistantProvider = ({ children }) => {
8282
() =>
8383
setAssistantState({
8484
message: {},
85-
status: 'idle',
85+
status: 'pending',
8686
messagesId: []
8787
}),
8888
[]

src/assistant/AssistantWrapperDesktop.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import React from 'react'
22

33
import SearchBar from './Search/SearchBar'
44
import SearchProvider from './Search/SearchProvider'
5+
import AssistantProvider from './AssistantProvider'
56

67
const AssistantWrapperDesktop = () => {
78
return (
89
<div className="app-list-wrapper u-mb-3 u-mh-auto u-w-100">
9-
<SearchProvider>
10-
<SearchBar />
11-
</SearchProvider>
10+
<AssistantProvider>
11+
<SearchProvider>
12+
<SearchBar />
13+
</SearchProvider>
14+
</AssistantProvider>
1215
</div>
1316
)
1417
}

src/assistant/Views/AssistantDialog.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useBreakpoints } from 'cozy-ui/transpiled/react/providers/Breakpoints'
66

77
import Conversation from '../Conversations/Conversation'
88
import ConversationBar from '../Conversations/ConversationBar'
9-
import { useAssistant } from '../AssistantProvider'
9+
import AssistantProvider, { useAssistant } from '../AssistantProvider'
1010

1111
const AssistantDialog = () => {
1212
const { assistantState } = useAssistant()
@@ -36,4 +36,12 @@ const AssistantDialog = () => {
3636
)
3737
}
3838

39-
export default AssistantDialog
39+
const AssistantDialogWithProviders = () => {
40+
return (
41+
<AssistantProvider>
42+
<AssistantDialog />
43+
</AssistantProvider>
44+
)
45+
}
46+
47+
export default AssistantDialogWithProviders

src/assistant/Views/SearchDialog.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import flag from 'cozy-flags'
55
import { FixedDialog } from 'cozy-ui/transpiled/react/CozyDialogs'
66

77
import SearchProvider from '../Search/SearchProvider'
8-
import { useAssistant } from '../AssistantProvider'
8+
import AssistantProvider, { useAssistant } from '../AssistantProvider'
99
import { makeConversationId } from '../helpers'
1010
import ResultMenuContent from '../ResultMenu/ResultMenuContent'
1111
import { useSearch } from '../Search/SearchProvider'
@@ -54,9 +54,11 @@ const SearchDialog = () => {
5454

5555
const SearchDialogWithProviders = () => {
5656
return (
57-
<SearchProvider>
58-
<SearchDialog />
59-
</SearchProvider>
57+
<AssistantProvider>
58+
<SearchProvider>
59+
<SearchDialog />
60+
</SearchProvider>
61+
</AssistantProvider>
6062
)
6163
}
6264

src/components/AppWrapper.jsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { useWallpaperContext } from 'hooks/useWallpaperContext'
2121

2222
import schema from '../schema'
2323
import { ConditionalWrapper } from './ConditionalWrapper'
24-
import AssistantProvider from 'assistant/AssistantProvider'
2524
import { WallPaperProvider } from 'hooks/useWallpaperContext'
2625
import { SectionsProvider } from './Sections/SectionsContext'
2726
const dictRequire = lang => require(`locales/${lang}.json`)
@@ -116,22 +115,20 @@ const AppWrapper = ({ children }) => {
116115
<CozyTheme>
117116
<ThemeProvider>
118117
<AlertProvider>
119-
<AssistantProvider>
120-
<ReduxProvider store={store}>
121-
<ConditionalWrapper
122-
condition={persistor}
123-
wrapper={children => (
124-
<PersistGate loading={null} persistor={persistor}>
125-
{children}
126-
</PersistGate>
127-
)}
128-
>
129-
<Inner lang={lang} context={context}>
118+
<ReduxProvider store={store}>
119+
<ConditionalWrapper
120+
condition={persistor}
121+
wrapper={children => (
122+
<PersistGate loading={null} persistor={persistor}>
130123
{children}
131-
</Inner>
132-
</ConditionalWrapper>
133-
</ReduxProvider>
134-
</AssistantProvider>
124+
</PersistGate>
125+
)}
126+
>
127+
<Inner lang={lang} context={context}>
128+
{children}
129+
</Inner>
130+
</ConditionalWrapper>
131+
</ReduxProvider>
135132
</AlertProvider>
136133
</ThemeProvider>
137134
</CozyTheme>

0 commit comments

Comments
 (0)