Skip to content

Commit

Permalink
Hack: remove chat in place to avoid cast error
Browse files Browse the repository at this point in the history
- this works because it also modifies other values
- ticket created to find longer term solution
  • Loading branch information
mrdjohnson committed Feb 23, 2024
1 parent af2dae2 commit c3c0c4d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/models/ChatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const ChatModel = types
}
},

deleteMessage(uniqId: string) {
async deleteMessage(uniqId: string) {
const messagesWithoutMessage = _.reject(self.messages, { uniqId })

self.messages = cast(messagesWithoutMessage)
Expand Down
10 changes: 4 additions & 6 deletions src/models/ChatStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cast, types } from 'mobx-state-tree'
import { types } from 'mobx-state-tree'
import persist from 'mst-persist'
import _ from 'lodash'

Expand All @@ -24,15 +24,13 @@ export const ChatStore = types
},

deleteChat(chat: IChatModel) {
const chats = _.reject(self.chats, { id: chat.id })
_.remove(self.chats, { id: chat.id })

if (self.selectedChat?.id === chat.id) {
self.selectedChat = chats[0]
self.selectedChat = self.chats[0]
}

self.chats = cast(chats)

if (chats.length === 0) {
if (self.chats.length === 0) {
this.createChat()
}
},
Expand Down

0 comments on commit c3c0c4d

Please sign in to comment.