Dialog stack callbacks can now return a return element ID to animate to

This commit is contained in:
Stefan Zermatten
2019-02-20 14:29:33 +02:00
parent 9d027aeabf
commit 9e208ad3b3
3 changed files with 23 additions and 14 deletions

View File

@@ -9,6 +9,11 @@
<slot name="toolbar"></slot>
<template v-if="$slots.edit">
<v-spacer/>
<v-btn icon flat @click="() => $emit('delete')" v-if="isEditing">
<v-icon>
delete
</v-icon>
</v-btn>
<v-btn icon flat @click="isEditing = !isEditing">
<v-icon>
{{isEditing ? 'check' : 'create'}}

View File

@@ -20,7 +20,6 @@
:key="dialog._id"
class="dialog"
:data-element-id="dialog.elementId"
:data-return-element-id="dialog.returnElementId"
:data-index="index"
:ref="index"
:style="getDialogStyle(index)"
@@ -111,13 +110,18 @@
target.style.transition = originalStyle.transition;
target.style.boxShadow = originalStyle.boxShadow;
source.style.transition = originalStyle.sourceTransition;
setTimeout(() => done, MOCK_DURATION);
setTimeout(done, MOCK_DURATION);
});
},
leave(target, done){
// Give minimongo time to update documents we might need to animate to
setTimeout(() => this.doLeave(target, done));
},
doLeave(target, done){
let elementId;
if (target && target.attributes['data-return-element-id']) {
elementId = target.attributes['data-return-element-id'].value;
let returnElementId = this.$store.state.dialogStack.currentReturnElement;
if (returnElementId) {
elementId = returnElementId;
} else {
if (!target || !target.attributes['data-element-id']){
done();
@@ -127,6 +131,7 @@
}
let source = this.getTopElementByDataId(elementId);
if (!source){
console.log(`Can't find source for ${elementId}`);
done();
return;
}

View File

@@ -5,9 +5,10 @@ const dialogStackStore = {
state: {
dialogs: [],
currentResult: null,
currentReturnElement: null,
},
mutations: {
pushDialogStack(state, {component, data, elementId, returnElementId, callback}){
pushDialogStack(state, {component, data, elementId, callback}){
// Generate a new _id so that Vue knows how to shuffle the array
const _id = Random.id();
state.dialogs.push({
@@ -15,7 +16,6 @@ const dialogStackStore = {
component,
data,
elementId,
returnElementId,
callback,
});
updateHistory();
@@ -25,20 +25,19 @@ const dialogStackStore = {
state.currentResult = null;
updateHistory();
if (!dialog) return;
if (dialog.callback) dialog.callback(result);
if (dialog.callback){
let returnElementId = dialog.callback(result);
state.currentReturnElement = returnElementId;
} else {
state.currentReturnElement = null;
}
},
setCurrentResult (state, result){
state.currentResult = result;
},
setTopReturnElementId (state, elementId){
state.dialogs[state.dialogs.length - 1].returnElementId = elementId;
},
},
actions: {
popDialogStack(context, result, {returnElementId} = {}){
if (returnElementId){
context.commit("setTopReturnElementId", returnElementId);
}
popDialogStack(context, result){
if (history && history.state && history.state.openDialogs){
context.commit("setCurrentResult", result);
history.back();