mirror of
https://github.com/balzack/databag.git
synced 2025-02-16 05:29:15 +00:00
adding conversation context
This commit is contained in:
parent
c01b6e3fd7
commit
5f83b3e38f
@ -1,5 +1,6 @@
|
|||||||
import login from './login.png';
|
import login from './login.png';
|
||||||
import { AppContextProvider } from './AppContext/AppContext';
|
import { AppContextProvider } from './AppContext/AppContext';
|
||||||
|
import { ConversationContextProvider } from './ConversationContext/ConversationContext';
|
||||||
import { Home } from './Home/Home';
|
import { Home } from './Home/Home';
|
||||||
import { Login } from './Login/Login';
|
import { Login } from './Login/Login';
|
||||||
import { Create } from './Create/Create';
|
import { Create } from './Create/Create';
|
||||||
@ -26,8 +27,16 @@ function App() {
|
|||||||
<Route path="/user" element={ <User /> }>
|
<Route path="/user" element={ <User /> }>
|
||||||
<Route path="profile" element={<Profile />} />
|
<Route path="profile" element={<Profile />} />
|
||||||
<Route path="contact/:guid" element={<Contact />} />
|
<Route path="contact/:guid" element={<Contact />} />
|
||||||
<Route path="conversation/:card/:channel" element={<Conversation />} />
|
<Route path="conversation/:card/:channel" element={
|
||||||
<Route path="conversation/:channel" element={<Conversation />} />
|
<ConversationContextProvider>
|
||||||
|
<Conversation />
|
||||||
|
</ConversationContextProvider>
|
||||||
|
} />
|
||||||
|
<Route path="conversation/:channel" element={
|
||||||
|
<ConversationContextProvider>
|
||||||
|
<Conversation />
|
||||||
|
</ConversationContextProvider>
|
||||||
|
} />
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
</Router>
|
</Router>
|
||||||
|
14
net/web/src/ConversationContext/ConversationContext.js
Normal file
14
net/web/src/ConversationContext/ConversationContext.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { createContext } from 'react';
|
||||||
|
import { useConversationContext } from './useConversationContext.hook';
|
||||||
|
|
||||||
|
export const ConversationContext = createContext({});
|
||||||
|
|
||||||
|
export function ConversationContextProvider({ children }) {
|
||||||
|
const { state, actions } = useConversationContext();
|
||||||
|
return (
|
||||||
|
<ConversationContext.Provider value={{ state, actions }}>
|
||||||
|
{children}
|
||||||
|
</ConversationContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
import { useEffect, useState, useRef } from 'react';
|
||||||
|
|
||||||
|
export function useConversationContext() {
|
||||||
|
const [state, setState] = useState({});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("CREATED CONVERSATION");
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const updateState = (value) => {
|
||||||
|
setState((s) => ({ ...s, ...value }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const actions = {
|
||||||
|
}
|
||||||
|
|
||||||
|
return { state, actions }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react'
|
import React, { useState, useEffect, useRef } from 'react'
|
||||||
|
import { ConversationContextProvider } from '../../ConversationContext/ConversationContext';
|
||||||
import { CloseOutlined, UserOutlined } from '@ant-design/icons';
|
import { CloseOutlined, UserOutlined } from '@ant-design/icons';
|
||||||
import { useConversation } from './useConversation.hook';
|
import { useConversation } from './useConversation.hook';
|
||||||
import { Button, Checkbox, Modal } from 'antd'
|
import { Button, Checkbox, Modal } from 'antd'
|
||||||
import { ConversationWrapper, CloseButton, ListItem } from './Conversation.styled';
|
import { ConversationWrapper, CloseButton, ListItem } from './Conversation.styled';
|
||||||
import { AutoSizer, CellMeasurer, CellMeasurerCache, List } from 'react-virtualized';
|
import { AutoSizer, CellMeasurer, CellMeasurerCache, List } from 'react-virtualized';
|
||||||
import { AddTopic } from './AddTopic/AddTopic';
|
import { AddTopic } from './AddTopic/AddTopic';
|
||||||
import { VirtualList } from '../..//VirtualList/VirtualList';
|
import { VirtualList } from '../../VirtualList/VirtualList';
|
||||||
import { TopicItem } from './TopicItem/TopicItem';
|
import { TopicItem } from './TopicItem/TopicItem';
|
||||||
|
|
||||||
export function Conversation() {
|
export function Conversation() {
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { TopicItemWrapper } from './TopicItem.styled';
|
import { TopicItemWrapper } from './TopicItem.styled';
|
||||||
import ReactResizeDetector from 'react-resize-detector';
|
import ReactResizeDetector from 'react-resize-detector';
|
||||||
|
import { useTopicItem } from './useTopicItem.hook';
|
||||||
|
|
||||||
export function TopicItem({ topic }) {
|
export function TopicItem({ topic }) {
|
||||||
|
|
||||||
|
const { state, actions } = useTopicItem();
|
||||||
const [ text, setText ] = useState(null);
|
const [ text, setText ] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
20
net/web/src/User/Conversation/TopicItem/useTopicItem.hook.js
Normal file
20
net/web/src/User/Conversation/TopicItem/useTopicItem.hook.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { useContext, useState, useEffect, useRef } from 'react';
|
||||||
|
import { AppContext } from '../../../AppContext/AppContext';
|
||||||
|
import { ConversationContext } from '../../../ConversationContext/ConversationContext';
|
||||||
|
|
||||||
|
export function useTopicItem() {
|
||||||
|
|
||||||
|
const [state, setState] = useState({});
|
||||||
|
|
||||||
|
const app = useContext(AppContext);
|
||||||
|
const conversation = useContext(ConversationContext);
|
||||||
|
|
||||||
|
const updateState = (value) => {
|
||||||
|
setState((s) => ({ ...s, ...value }));
|
||||||
|
}
|
||||||
|
|
||||||
|
const actions = {
|
||||||
|
};
|
||||||
|
|
||||||
|
return { state, actions };
|
||||||
|
}
|
@ -5,6 +5,7 @@ import { getChannelTopics } from '../../Api/getChannelTopics';
|
|||||||
import { getChannelTopic } from '../../Api/getChannelTopic';
|
import { getChannelTopic } from '../../Api/getChannelTopic';
|
||||||
import { getContactChannelTopics } from '../../Api/getContactChannelTopics';
|
import { getContactChannelTopics } from '../../Api/getContactChannelTopics';
|
||||||
import { getContactChannelTopic } from '../../Api/getContactChannelTopic';
|
import { getContactChannelTopic } from '../../Api/getContactChannelTopic';
|
||||||
|
import { ConversationContext } from '../../ConversationContext/ConversationContext';
|
||||||
|
|
||||||
export function useConversation() {
|
export function useConversation() {
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ export function useConversation() {
|
|||||||
const { card, channel } = useParams();
|
const { card, channel } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const app = useContext(AppContext);
|
const app = useContext(AppContext);
|
||||||
|
const conversation = useContext(ConversationContext);
|
||||||
const topics = useRef(new Map());
|
const topics = useRef(new Map());
|
||||||
|
|
||||||
const updateState = (value) => {
|
const updateState = (value) => {
|
||||||
|
@ -289,7 +289,7 @@ export function VirtualList({ items, itemRenderer }) {
|
|||||||
<VirtualItem style={{ top: container.top, paddingTop: GUTTER, paddingBottom: GUTTER }}>
|
<VirtualItem style={{ top: container.top, paddingTop: GUTTER, paddingBottom: GUTTER }}>
|
||||||
<ReactResizeDetector handleHeight={true}>
|
<ReactResizeDetector handleHeight={true}>
|
||||||
{({ height }) => {
|
{({ height }) => {
|
||||||
if (typeof height !== 'undefined' && height > 0) {
|
if (typeof height !== 'undefined') {
|
||||||
onItemHeight(container, height);
|
onItemHeight(container, height);
|
||||||
}
|
}
|
||||||
return itemRenderer(items[container.index]);
|
return itemRenderer(items[container.index]);
|
||||||
|
Loading…
Reference in New Issue
Block a user