diff --git a/src/assistant/AssistantProvider.jsx b/src/assistant/AssistantProvider.jsx
index ed7728471..0ab25871b 100644
--- a/src/assistant/AssistantProvider.jsx
+++ b/src/assistant/AssistantProvider.jsx
@@ -1,4 +1,5 @@
import React, { useMemo, useContext, useState, useCallback } from 'react'
+import { useParams } from 'react-router-dom'
import set from 'lodash/set'
import { useClient } from 'cozy-client'
@@ -19,10 +20,11 @@ export const useAssistant = () => {
}
const AssistantProvider = ({ children }) => {
+ const { conversationId } = useParams()
const client = useClient()
const [assistantState, setAssistantState] = useState({
message: {},
- status: 'idle',
+ status: 'pending',
messagesId: []
})
@@ -31,10 +33,10 @@ const AssistantProvider = ({ children }) => {
{
[CHAT_CONVERSATIONS_DOCTYPE]: {
created: res => {
- pushMessagesIdInState(res, setAssistantState)
+ pushMessagesIdInState(conversationId, res, setAssistantState)
},
updated: res => {
- pushMessagesIdInState(res, setAssistantState)
+ pushMessagesIdInState(conversationId, res, setAssistantState)
}
}
},
@@ -82,7 +84,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/assistant/helpers.js b/src/assistant/helpers.js
index 4fa0e8b10..6d53d5458 100644
--- a/src/assistant/helpers.js
+++ b/src/assistant/helpers.js
@@ -7,7 +7,9 @@ export const getInstantMessage = assistantState =>
export const makeConversationId = () =>
`${Date.now()}-${Math.floor(Math.random() * 90000) + 10000}`
-export const pushMessagesIdInState = (res, setState) => {
+export const pushMessagesIdInState = (id, res, setState) => {
+ if (id !== res._id) return
+
const messagesId = res.messages.map(message => message.id)
setState(v => ({
...v,
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}
+
+
+