adding conversation list

This commit is contained in:
talksik
2022-06-11 13:07:19 -05:00
parent 10ac1626ab
commit 74ade53e82
3 changed files with 209 additions and 10 deletions
@@ -16,16 +16,16 @@ import { useAsyncFn } from 'react-use';
import { useImmer } from 'use-immer';
interface IConversationContext {
conversations: ConversationMap;
conversationMap: ConversationMap;
selectedConversation?: MasterConversation;
// handleSetConversation?: (conversationId: string) => void;
selectConversation?: (conversationId: string, temporaryOverrideSort?: boolean) => Promise<void>;
handleStartConversation?: (otherUsers: User[]) => void;
handleStartConversation?: (otherUsers: User[], conversationName?: string) => Promise<void>;
}
const ConversationContext = React.createContext<IConversationContext>({
conversations: {},
conversationMap: {},
});
export function ConversationProvider({ children }: { children: React.ReactNode }) {
@@ -100,7 +100,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
);
const handleStartConversation = useCallback(
async (otherUsers: User[]) => {
async (otherUsers: User[], conversationName?: string) => {
try {
/** group conversation
* 1. create it
@@ -133,7 +133,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
}
const createdConversationResult = await createConversation(
new CreateConversationRequest(otherUsers),
new CreateConversationRequest(otherUsers, conversationName),
);
selectConversation(createdConversationResult.data.conversationId.toString());
@@ -144,7 +144,7 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
toast.error(error.message);
}
},
[conversationMap, selectConversation],
[selectConversation],
);
// todo: open up a handler for children
@@ -162,7 +162,12 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
return (
<ConversationContext.Provider
value={{ conversations: conversationMap, handleStartConversation, selectedConversation }}
value={{
conversationMap,
handleStartConversation,
selectedConversation,
selectConversation,
}}
>
{children}
</ConversationContext.Provider>