enhanced overall Chat experience

This commit is contained in:
PxlLoewe
2025-06-09 22:38:31 -07:00
parent ea78b41510
commit b4b7b4def2
7 changed files with 119 additions and 98 deletions

View File

@@ -30,21 +30,30 @@ export const useLeftMenuStore = create<ChatStore>((set, get) => ({
chatOpen: false,
selectedChat: null,
setChatOpen: (open: boolean) => set({ chatOpen: open }),
setSelectedChat: (chatId: string | null) => set({ selectedChat: chatId }),
setSelectedChat: (chatId: string | null) => {
const { setChatNotification } = get();
set({ selectedChat: chatId });
if (chatId) {
setChatNotification(chatId, false); // Set notification to false when chat is selected
}
},
setOwnId: (id: string) => set({ ownId: id }),
chats: {},
sendMessage: (userId: string, message: string) => {
return new Promise((resolve, reject) => {
if(dispatchSocket.connected){
dispatchSocket.emit("send-message", { userId, message }, ({ error }: { error?: string }) => {
if (error) {
reject(error);
} else {
resolve();
}
});
} else if(pilotSocket.connected){
if (dispatchSocket.connected) {
dispatchSocket.emit(
"send-message",
{ userId, message },
({ error }: { error?: string }) => {
if (error) {
reject(error);
} else {
resolve();
}
},
);
} else if (pilotSocket.connected) {
pilotSocket.emit("send-message", { userId, message }, ({ error }: { error?: string }) => {
if (error) {
reject(error);
@@ -66,7 +75,6 @@ export const useLeftMenuStore = create<ChatStore>((set, get) => ({
setChatNotification: (userId, notification) => {
const chat = get().chats[userId];
if (!chat) return;
console.log("setChatNotification", userId, notification);
set((state) => {
return {
chats: {
@@ -95,7 +103,7 @@ export const useLeftMenuStore = create<ChatStore>((set, get) => ({
[userId]: {
...user,
name: isSender ? message.receiverName : message.senderName,
notification: !isSender && (state.selectedChat !== userId || !state.chatOpen),
notification: state.selectedChat !== userId || !state.chatOpen,
messages: [...user.messages, message], // Neuen Zustand erzeugen
},
},