-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #564 from Adamant-im/Feat/save-texts-in-input-fiel…
…ds-message-drafts feat(Chat): save draft messages
- Loading branch information
Showing
5 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { MutationTree, GetterTree, ActionTree } from 'vuex' | ||
import { RootState } from '@/store/types' | ||
|
||
export interface DraftState { | ||
drafts: { [key: string]: { replyToId?: string; message?: string } } | ||
} | ||
|
||
const state = (): DraftState => ({ | ||
drafts: {} | ||
}) | ||
|
||
const mutations: MutationTree<DraftState> = { | ||
saveReplyToId(state, payload: { partnerId: string; replyToId: string }) { | ||
if (state.drafts[payload.partnerId]) { | ||
state.drafts[payload.partnerId].replyToId = payload.replyToId | ||
} else { | ||
state.drafts[payload.partnerId] = { | ||
replyToId: payload.replyToId | ||
} | ||
} | ||
}, | ||
|
||
saveMessage(state, payload: { partnerId: string; message: string }) { | ||
if (state.drafts[payload.partnerId]) { | ||
state.drafts[payload.partnerId].message = payload.message | ||
} else { | ||
state.drafts[payload.partnerId] = { | ||
message: payload.message | ||
} | ||
} | ||
}, | ||
|
||
deleteReplyTold(state, payload: { partnerId: string; replyToId: string }) { | ||
delete state.drafts[payload.partnerId].replyToId | ||
}, | ||
|
||
deleteMessage(state, payload: { partnerId: string; message: string }) { | ||
delete state.drafts[payload.partnerId].message | ||
}, | ||
|
||
reset(state) { | ||
state.drafts = {} | ||
} | ||
} | ||
|
||
const getters: GetterTree<DraftState, RootState> = { | ||
draftMessage: (state) => (partnerId: string) => { | ||
const objMessage = state.drafts[partnerId] | ||
if (objMessage) { | ||
return objMessage.message | ||
} else { | ||
return '' | ||
} | ||
}, | ||
|
||
draftReplyTold: (state) => (partnerId: string) => { | ||
const objMessage = state.drafts[partnerId] | ||
if (objMessage) { | ||
return objMessage.replyToId | ||
} else { | ||
return '' | ||
} | ||
} | ||
} | ||
|
||
const actions: ActionTree<DraftState, RootState> = { | ||
resetState(context) { | ||
context.commit('reset') | ||
}, | ||
|
||
deleteDraft(context, payload: { partnerId: string }) { | ||
context.commit('deleteReplyTold', payload) | ||
context.commit('deleteMessage', payload) | ||
} | ||
} | ||
|
||
export default { | ||
state, | ||
mutations, | ||
getters, | ||
actions, | ||
namespaced: true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters