[#34] Add delete messages action handling

This commit is contained in:
Jannis Mattheis 2018-04-09 17:08:50 +02:00 committed by Jannis Mattheis
parent ca5a832baf
commit e28a157122
2 changed files with 11 additions and 2 deletions

View File

@ -35,13 +35,13 @@ function newMessages(id, data) {
export function deleteMessagesByApp(id) { export function deleteMessagesByApp(id) {
if (id === -1) { if (id === -1) {
axios.delete(config.get('url') + 'message').then(() => { axios.delete(config.get('url') + 'message').then(() => {
dispatcher.dispatch({type: 'DELETE_MESSAGES', id: -1}); dispatcher.dispatch({type: 'DELETE_MESSAGES', payload: -1});
snack('Messages deleted'); snack('Messages deleted');
}); });
} else { } else {
axios.delete(config.get('url') + 'application/' + id + '/message') axios.delete(config.get('url') + 'application/' + id + '/message')
.then(() => { .then(() => {
dispatcher.dispatch({type: 'DELETE_MESSAGES', id}); dispatcher.dispatch({type: 'DELETE_MESSAGES', payload: id});
snack('Deleted all messages from the application'); snack('Deleted all messages from the application');
}); });
} }

View File

@ -58,6 +58,15 @@ class MessageStore extends EventEmitter {
} }
}); });
this.emit('change'); this.emit('change');
} else if (data.type === 'DELETE_MESSAGES') {
const id = data.payload;
if (id === -1) {
this.appToMessages = {};
} else {
delete this.appToMessages[-1];
delete this.appToMessages[id];
}
this.emit('change');
} }
} }