modal: fix sharing modal

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/888/head
Varun Patil 2023-10-24 10:55:48 -07:00
parent 79ae924a00
commit 926e57f896
3 changed files with 29 additions and 18 deletions

View File

@ -7,6 +7,7 @@ export default defineComponent({
data: () => ({ data: () => ({
show: false, show: false,
_closing: null as null | ((value: unknown) => void),
}), }),
mounted() { mounted() {
@ -18,15 +19,27 @@ export default defineComponent({
}, },
watch: { watch: {
show(value: boolean, from: boolean) { show(value: boolean) {
utils.fragment.if(value, utils.fragment.types.modal); utils.fragment.if(value, utils.fragment.types.modal);
if (!value) {
this._closing?.(null);
this._closing = null;
}
}, },
}, },
methods: { methods: {
close() { async close() {
if (this.show) { if (this.show && !this._closing) {
// pop the fragment immediately
await utils.fragment.pop(utils.fragment.types.modal);
// close the modal with animation
(<any>this.$refs.modal)?.close?.(); (<any>this.$refs.modal)?.close?.();
// wait for transition to end
await new Promise((resolve) => (this._closing = resolve));
} }
}, },
}, },

View File

@ -155,10 +155,10 @@ export default defineComponent({
this.photo = null; this.photo = null;
}, },
async l(cb: Function) { async l<T>(cb: () => Promise<T>): Promise<T> {
try { try {
this.loading++; this.loading++;
await cb(); return await cb();
} finally { } finally {
this.loading--; this.loading--;
} }
@ -195,11 +195,9 @@ export default defineComponent({
}, },
async shareLink() { async shareLink() {
this.l(async () => { const fileInfo = await this.l(async () => (await dav.getFiles([this.photo!]))[0]);
const fileInfo = (await dav.getFiles([this.photo!]))[0]; await this.close(); // wait till transition is done
_m.modals.shareNodeLink(fileInfo.filename, true); _m.modals.shareNodeLink(fileInfo.filename, true);
});
this.close();
}, },
/** /**

View File

@ -84,7 +84,7 @@ export const fragment = {
* Add fragment to route. * Add fragment to route.
* @param frag Fragment to add to route * @param frag Fragment to add to route
*/ */
push(type: FragmentType, ...args: string[]) { async push(type: FragmentType, ...args: string[]) {
const frag: Fragment = { type, args }; const frag: Fragment = { type, args };
const list = this.list; const list = this.list;
@ -101,7 +101,7 @@ export const fragment = {
if (hash === _m.route.hash) return; if (hash === _m.route.hash) return;
// Replace the route with the new fragment // Replace the route with the new fragment
_m.router.replace({ await _m.router.replace({
path: _m.route.path, path: _m.route.path,
query: _m.route.query, query: _m.route.query,
hash: hash, hash: hash,
@ -118,7 +118,7 @@ export const fragment = {
// Add fragment to route // Add fragment to route
list.push(frag); list.push(frag);
_m.router.push({ await _m.router.push({
path: _m.route.path, path: _m.route.path,
query: _m.route.query, query: _m.route.query,
hash: encodeFragment(list), hash: encodeFragment(list),
@ -129,7 +129,7 @@ export const fragment = {
* Remove the top fragment from route. * Remove the top fragment from route.
* @param type Fragment identifier * @param type Fragment identifier
*/ */
pop(type: FragmentType) { async pop(type: FragmentType) {
// Get the index of this fragment from the end // Get the index of this fragment from the end
const frag = this.get(type); const frag = this.get(type);
if (!frag) return; if (!frag) return;
@ -141,7 +141,7 @@ export const fragment = {
// In that case, replace the route to remove the fragment // In that case, replace the route to remove the fragment
const sfrag = this.get(type); const sfrag = this.get(type);
if (sfrag) { if (sfrag) {
_m.router.replace({ await _m.router.replace({
path: _m.route.path, path: _m.route.path,
query: _m.route.query, query: _m.route.query,
hash: encodeFragment(this.list.slice(0, -sfrag.index! - 1)), hash: encodeFragment(this.list.slice(0, -sfrag.index! - 1)),
@ -152,9 +152,9 @@ export const fragment = {
/** /**
* Sync a fragment with a boolean condition. * Sync a fragment with a boolean condition.
*/ */
if(condition: boolean, type: FragmentType, ...args: string[]) { async if(condition: boolean, type: FragmentType, ...args: string[]) {
if (condition) this.push(type, ...args); if (condition) await this.push(type, ...args);
else this.pop(type); else await this.pop(type);
}, },
get viewer() { get viewer() {