diff --git a/src/components/Pages/InboxPage.tsx b/src/components/Pages/InboxPage.tsx
index 67a01ab3..403b9097 100644
--- a/src/components/Pages/InboxPage.tsx
+++ b/src/components/Pages/InboxPage.tsx
@@ -1,10 +1,16 @@
import { PageWrap } from '../_shared/PageWrap'
import { InboxView } from '../Views/Inbox'
+import { InboxProvider } from '../../context/inbox'
+import { ShowOnlyOnClient } from '../_shared/ShowOnlyOnClient'
export const InboxPage = () => {
return (
-
+
+
+
+
+
)
}
diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx
index 522577c2..18095ecc 100644
--- a/src/components/Views/Inbox.tsx
+++ b/src/components/Views/Inbox.tsx
@@ -11,6 +11,7 @@ import Message from '../Inbox/Message'
import { loadRecipients, loadChats } from '../../stores/inbox'
import { t } from '../../utils/intl'
import '../../styles/Inbox.scss'
+import { useInbox } from '../../context/inbox'
const OWNER_ID = '501'
const client = createClient({
@@ -56,7 +57,7 @@ const postMessage = async (msg: string) => {
const handleGetChats = async () => {
try {
const response = await loadChats()
- console.log('!!! response:', response)
+ console.log('!!! handleGetChats:', response)
} catch (error) {
console.log(error)
}
@@ -68,14 +69,8 @@ export const InboxView = () => {
const [cashedRecipients, setCashedRecipients] = createSignal
([])
const [postMessageText, setPostMessageText] = createSignal('')
const [loading, setLoading] = createSignal(false)
- const [currentSlug, setCurrentSlug] = createSignal()
-
const { session } = useSession()
- createEffect(() => {
- console.log('!!! session:', session())
- setCurrentSlug(session()?.user?.slug)
- })
- console.log('!!! currentSlug:', currentSlug())
+ const currentSlug = createMemo(() => session()?.user?.slug)
// Поиск по диалогам
const getQuery = (query) => {
@@ -112,7 +107,6 @@ export const InboxView = () => {
try {
const response = await loadRecipients({ days: 365 })
- console.log('!!! response:', response)
setRecipients(response as unknown as Author[])
setCashedRecipients(response as unknown as Author[])
} catch (error) {
@@ -139,6 +133,10 @@ export const InboxView = () => {
formParent.dataset.replicatedValue = postMessageText()
})
+ // FIXME: прописать типы
+ // const { chatEntitieies, actions: { createCaht }} = useInbox()
+ // const { actions: { createCaht }} = useInbox()
+
return (
diff --git a/src/context/inbox.tsx b/src/context/inbox.tsx
new file mode 100644
index 00000000..216b1a36
--- /dev/null
+++ b/src/context/inbox.tsx
@@ -0,0 +1,36 @@
+import type { JSX } from 'solid-js'
+import { createContext, useContext } from 'solid-js'
+import type { Message, Chat } from '../graphql/types.gen'
+import { apiClient } from '../utils/apiClient'
+import { createStore } from 'solid-js/store'
+
+type InboxContextType = {
+ chatEntities: { [chatId: string]: Message[] }
+ actions: {
+ createChat: (memberSlugs: string[], title?: string) => Promise
+ }
+}
+
+const InboxContext = createContext()
+
+export function useInbox() {
+ return useContext(InboxContext)
+}
+
+export const InboxProvider = (props: { children: JSX.Element }) => {
+ const [chatEntities, setChatEntities] = createStore({})
+
+ const createChat = async (memberSlugs: string[], title?: string) => {
+ // @ts-ignore FIXME: вывести типы
+ const chat = await apiClient.createChat({ string, title })
+
+ // @ts-ignore FIXME: вывести типы
+ setChatEntities(chat.id, chat)
+ }
+
+ const actions = {
+ createChat
+ }
+ const value: InboxContextType = { chatEntities, actions }
+ return {props.children}
+}