fix tab switching state issues
- Add useFocusEffect to calendar for automatic event reload on tab focus - Create ChatStore (Zustand) for persistent chat messages across tab switches - Replace local useState with store in chat screen
This commit is contained in:
37
apps/client/src/stores/ChatStore.ts
Normal file
37
apps/client/src/stores/ChatStore.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { create } from "zustand";
|
||||
import { ProposedEventChange } from "@caldav/shared";
|
||||
|
||||
type BubbleSide = "left" | "right";
|
||||
|
||||
export type MessageData = {
|
||||
id: string;
|
||||
side: BubbleSide;
|
||||
content: string;
|
||||
proposedChange?: ProposedEventChange;
|
||||
respondedAction?: "confirm" | "reject";
|
||||
conversationId?: string;
|
||||
};
|
||||
|
||||
interface ChatState {
|
||||
messages: MessageData[];
|
||||
addMessage: (message: MessageData) => void;
|
||||
updateMessage: (id: string, updates: Partial<MessageData>) => void;
|
||||
clearMessages: () => void;
|
||||
}
|
||||
|
||||
export const useChatStore = create<ChatState>((set) => ({
|
||||
messages: [],
|
||||
addMessage: (message: MessageData) => {
|
||||
set((state) => ({ messages: [...state.messages, message] }));
|
||||
},
|
||||
updateMessage: (id: string, updates: Partial<MessageData>) => {
|
||||
set((state) => ({
|
||||
messages: state.messages.map((msg) =>
|
||||
msg.id === id ? { ...msg, ...updates } : msg,
|
||||
),
|
||||
}));
|
||||
},
|
||||
clearMessages: () => {
|
||||
set({ messages: [] });
|
||||
},
|
||||
}));
|
||||
@@ -1,2 +1,3 @@
|
||||
export { useAuthStore } from "./AuthStore";
|
||||
export { useChatStore, type MessageData } from "./ChatStore";
|
||||
export { useEventsStore } from "./EventsStore";
|
||||
|
||||
Reference in New Issue
Block a user