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