Skip to content

Commit

Permalink
fix: 🐛 Fixed an error in confirmation modal
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLambrecht committed Sep 27, 2019
1 parent b7c3d8a commit 8792f72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
15 changes: 9 additions & 6 deletions src/components/editor/EditorOperationPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ export default {
},
methods: {
async onClickShuffle() {
const confirmed = await this.askForConfirmation({
headline: 'Shuffle',
question: 'Are you sure you want to shuffle your playlist?',
positive: 'Shuffle',
negative: 'Cancel',
});
if (!confirmed) return;
try {
await this.askForConfirmation({
headline: 'Shuffle',
question: 'Are you sure you want to shuffle your playlist?',
positive: 'Shuffle',
negative: 'Cancel',
});
await this.rearrangePlaylistWith({
rearranger: RandomShuffle,
});
Expand Down
5 changes: 4 additions & 1 deletion src/components/editor/SortConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ export default {
},
async sort() {
this.showModal = false;
await this.askForConfirmation({
const confirmed = await this.askForConfirmation({
headline: 'Sort',
question: 'Are you sure you want to sort your playlist?',
positive: 'Sort',
negative: 'Cancel',
});
if (!confirmed) return;
await this.rearrangePlaylistWith({
rearranger: this.sortModeMap[this.sortMode],
options: this.options,
Expand Down
9 changes: 5 additions & 4 deletions src/store/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export default {
},

askForConfirmation({ commit }, confirmation = {}) {
const promise = new Promise((resolve, reject) => {
const promise = new Promise((resolve) => {
commit('setOnConfirmationAccept', resolve);
commit('setOnConfirmationDecline', reject);
commit('setOnConfirmationDecline', resolve);
});

commit('setPendingConfirmation', {
Expand All @@ -54,20 +54,21 @@ export default {
negative: 'No',
...confirmation,
});

return promise;
},

async acceptConfirmation({ commit, state }) {
const { onConfirmationAccept } = state;
onConfirmationAccept(); // resolve promise
onConfirmationAccept(true); // resolve promise
commit('setPendingConfirmation', null);
commit('setOnConfirmationAccept', null);
commit('setOnConfirmationDecline', null);
},

declineConfirmation({ commit, state }) {
const { onConfirmationDecline } = state;
onConfirmationDecline(); // reject promise
onConfirmationDecline(false); // resolve promise
commit('setPendingConfirmation', null);
commit('setOnConfirmationAccept', null);
commit('setOnConfirmationDecline', null);
Expand Down

0 comments on commit 8792f72

Please sign in to comment.