modal: use fragment

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/888/head
Varun Patil 2023-10-24 02:28:30 -07:00
parent 937feff286
commit 9db97aed3d
16 changed files with 142 additions and 84 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" size="normal" v-if="show"> <Modal ref="modal" @close="cleanup" size="normal" v-if="show">
<template #title> <template #title>
{{ t('memories', 'Add to album') }} {{ t('memories', 'Add to album') }}
</template> </template>
@ -27,6 +27,7 @@ import { IAlbum, IPhoto } from '../../types';
const NcProgressBar = () => import('@nextcloud/vue/dist/Components/NcProgressBar'); const NcProgressBar = () => import('@nextcloud/vue/dist/Components/NcProgressBar');
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import AlbumPicker from './AlbumPicker.vue'; import AlbumPicker from './AlbumPicker.vue';
export default defineComponent({ export default defineComponent({
@ -37,10 +38,11 @@ export default defineComponent({
AlbumPicker, AlbumPicker,
}, },
mixins: [ModalMixin],
emits: [], emits: [],
data: () => ({ data: () => ({
show: false,
photos: [] as IPhoto[], photos: [] as IPhoto[],
opsDone: 0, opsDone: 0,
opsTotal: 0, opsTotal: 0,
@ -60,11 +62,11 @@ export default defineComponent({
methods: { methods: {
open(photos: IPhoto[]) { open(photos: IPhoto[]) {
this.photos = photos; this.photos = photos;
this.show = true;
this.opsTotal = 0; this.opsTotal = 0;
this.show = true;
}, },
close() { cleanup() {
this.show = false; this.show = false;
this.photos = []; this.photos = [];
this.opsTotal = 0; this.opsTotal = 0;

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" size="normal" v-if="show"> <Modal ref="modal" @close="cleanup" size="normal" v-if="show">
<template #title> <template #title>
<template v-if="!album"> <template v-if="!album">
{{ t('memories', 'Create new album') }} {{ t('memories', 'Create new album') }}
@ -22,6 +22,7 @@ import { showError } from '@nextcloud/dialogs';
import * as dav from '../../services/dav'; import * as dav from '../../services/dav';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import AlbumForm from './AlbumForm.vue'; import AlbumForm from './AlbumForm.vue';
export default defineComponent({ export default defineComponent({
@ -31,10 +32,11 @@ export default defineComponent({
AlbumForm, AlbumForm,
}, },
mixins: [ModalMixin],
emits: [], emits: [],
data: () => ({ data: () => ({
show: false,
album: null as any, album: null as any,
}), }),
@ -59,7 +61,7 @@ export default defineComponent({
this.show = true; this.show = true;
}, },
close() { cleanup() {
this.show = false; this.show = false;
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" v-if="show"> <Modal ref="modal" @close="cleanup" v-if="show">
<template #title> <template #title>
{{ owned ? t('memories', 'Remove Album') : t('memories', 'Leave Album') }} {{ owned ? t('memories', 'Remove Album') : t('memories', 'Leave Album') }}
</template> </template>
@ -27,6 +27,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton';
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField'); const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
import { showError } from '@nextcloud/dialogs'; import { showError } from '@nextcloud/dialogs';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import * as utils from '../../services/utils'; import * as utils from '../../services/utils';
import * as dav from '../../services/dav'; import * as dav from '../../services/dav';
@ -40,11 +41,9 @@ export default defineComponent({
Modal, Modal,
}, },
emits: [], mixins: [ModalMixin],
data: () => ({ emits: [],
show: false,
}),
computed: { computed: {
user() { user() {
@ -61,14 +60,14 @@ export default defineComponent({
}, },
methods: { methods: {
close() {
this.show = false;
},
open() { open() {
this.show = true; this.show = true;
}, },
cleanup() {
this.show = false;
},
async save() { async save() {
try { try {
await client.deleteFile(dav.getAlbumPath(this.user, this.name)); await client.deleteFile(dav.getAlbumPath(this.user, this.name));

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" v-if="show"> <Modal ref="modal" @close="cleanup" v-if="show">
<template #title> <template #title>
{{ t('memories', 'Share Album') }} {{ t('memories', 'Share Album') }}
</template> </template>
@ -34,11 +34,12 @@ import { defineComponent } from 'vue';
import NcButton from '@nextcloud/vue/dist/Components/NcButton'; import NcButton from '@nextcloud/vue/dist/Components/NcButton';
import * as dav from '../../services/dav';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import AlbumCollaborators from './AlbumCollaborators.vue'; import AlbumCollaborators from './AlbumCollaborators.vue';
import * as dav from '../../services/dav';
export default defineComponent({ export default defineComponent({
name: 'AlbumShareModal', name: 'AlbumShareModal',
components: { components: {
@ -47,21 +48,17 @@ export default defineComponent({
AlbumCollaborators, AlbumCollaborators,
}, },
mixins: [ModalMixin],
emits: [], emits: [],
data: () => ({ data: () => ({
album: null as any, album: null as any,
show: false,
loadingAddCollaborators: false, loadingAddCollaborators: false,
collaborators: [] as any[], collaborators: [] as any[],
}), }),
methods: { methods: {
close() {
this.show = false;
this.album = null;
},
async open() { async open() {
this.show = true; this.show = true;
this.loadingAddCollaborators = true; this.loadingAddCollaborators = true;
@ -70,6 +67,11 @@ export default defineComponent({
this.loadingAddCollaborators = false; this.loadingAddCollaborators = false;
}, },
cleanup() {
this.show = false;
this.album = null;
},
async handleSetCollaborators(collaborators: any[]) { async handleSetCollaborators(collaborators: any[]) {
try { try {
this.loadingAddCollaborators = true; this.loadingAddCollaborators = true;

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal v-if="show" @close="close"> <Modal ref="modal" @close="cleanup" v-if="show">
<template #title> <template #title>
{{ t('memories', 'Edit metadata') }} {{ t('memories', 'Edit metadata') }}
</template> </template>
@ -51,11 +51,13 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { IExif, IImageInfo, IPhoto } from '../../types'; import { IExif, IImageInfo, IPhoto } from '../../types';
import UserConfig from '../../mixins/UserConfig';
import NcButton from '@nextcloud/vue/dist/Components/NcButton'; import NcButton from '@nextcloud/vue/dist/Components/NcButton';
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField'); const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
const NcProgressBar = () => import('@nextcloud/vue/dist/Components/NcProgressBar'); const NcProgressBar = () => import('@nextcloud/vue/dist/Components/NcProgressBar');
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import UserConfig from '../../mixins/UserConfig';
import ModalMixin from './ModalMixin';
import EditDate from './EditDate.vue'; import EditDate from './EditDate.vue';
import EditTags from './EditTags.vue'; import EditTags from './EditTags.vue';
@ -82,12 +84,11 @@ export default defineComponent({
EditLocation, EditLocation,
}, },
mixins: [UserConfig], mixins: [UserConfig, ModalMixin],
data: () => ({ data: () => ({
photos: null as IPhoto[] | null, photos: null as IPhoto[] | null,
sections: [] as number[], sections: [] as number[],
show: false,
processing: false, processing: false,
progress: 0, progress: 0,
state: 0, state: 0,
@ -152,9 +153,9 @@ export default defineComponent({
this.processing = false; this.processing = false;
}, },
close() { cleanup() {
this.photos = null;
this.show = false; this.show = false;
this.photos = null;
this.processing = false; this.processing = false;
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" v-if="show"> <Modal ref="modal" @close="cleanup" v-if="show">
<template #title> <template #title>
{{ t('memories', 'Remove person') }} {{ t('memories', 'Remove person') }}
</template> </template>
@ -23,6 +23,7 @@ const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
import { showError } from '@nextcloud/dialogs'; import { showError } from '@nextcloud/dialogs';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import * as utils from '../../services/utils'; import * as utils from '../../services/utils';
import * as dav from '../../services/dav'; import * as dav from '../../services/dav';
@ -35,11 +36,9 @@ export default defineComponent({
Modal, Modal,
}, },
emits: [], mixins: [ModalMixin],
data: () => ({ emits: [],
show: false,
}),
computed: { computed: {
name() { name() {
@ -52,10 +51,6 @@ export default defineComponent({
}, },
methods: { methods: {
close() {
this.show = false;
},
open() { open() {
if (this.user !== utils.uid) { if (this.user !== utils.uid) {
showError(this.t('memories', 'Only user "{user}" can delete this person', { user: this.user })); showError(this.t('memories', 'Only user "{user}" can delete this person', { user: this.user }));
@ -65,6 +60,10 @@ export default defineComponent({
this.show = true; this.show = true;
}, },
cleanup() {
this.show = false;
},
async save() { async save() {
try { try {
if (this.routeIsRecognize) { if (this.routeIsRecognize) {

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" v-if="show"> <Modal ref="modal" @close="cleanup" v-if="show">
<template #title> <template #title>
{{ t('memories', 'Rename person') }} {{ t('memories', 'Rename person') }}
</template> </template>
@ -33,6 +33,7 @@ const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
import { showError } from '@nextcloud/dialogs'; import { showError } from '@nextcloud/dialogs';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import * as utils from '../../services/utils'; import * as utils from '../../services/utils';
import * as dav from '../../services/dav'; import * as dav from '../../services/dav';
@ -45,11 +46,12 @@ export default defineComponent({
Modal, Modal,
}, },
mixins: [ModalMixin],
emits: [], emits: [],
data: () => ({ data: () => ({
show: false, input: String(),
input: '',
}), }),
computed: { computed: {
@ -67,10 +69,6 @@ export default defineComponent({
}, },
methods: { methods: {
close() {
this.show = false;
},
open() { open() {
if (this.user !== utils.uid) { if (this.user !== utils.uid) {
showError(this.t('memories', 'Only user "{user}" can update this person', { user: this.user })); showError(this.t('memories', 'Only user "{user}" can update this person', { user: this.user }));
@ -81,6 +79,10 @@ export default defineComponent({
this.show = true; this.show = true;
}, },
cleanup() {
this.show = false;
},
async save() { async save() {
if (!this.canSave) return; if (!this.canSave) return;

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" size="large" v-if="show"> <Modal ref="modal" @close="cleanup" size="large" v-if="show">
<template #title> <template #title>
{{ t('memories', 'Merge {name} with person', { name: $route.params.name }) }} {{ t('memories', 'Merge {name} with person', { name: $route.params.name }) }}
</template> </template>
@ -33,6 +33,8 @@ import Cluster from '../frame/Cluster.vue';
import FaceList from './FaceList.vue'; import FaceList from './FaceList.vue';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import client from '../../services/dav/client'; import client from '../../services/dav/client';
import * as dav from '../../services/dav'; import * as dav from '../../services/dav';
import * as utils from '../../services/utils'; import * as utils from '../../services/utils';
@ -48,19 +50,16 @@ export default defineComponent({
FaceList, FaceList,
}, },
mixins: [ModalMixin],
emits: [], emits: [],
data: () => ({ data: () => ({
processing: 0, processing: 0,
processingTotal: 0, processingTotal: 0,
show: false,
}), }),
methods: { methods: {
close() {
this.show = false;
},
open() { open() {
const user = this.$route.params.user || ''; const user = this.$route.params.user || '';
if (this.$route.params.user !== utils.uid) { if (this.$route.params.user !== utils.uid) {
@ -74,6 +73,10 @@ export default defineComponent({
this.show = true; this.show = true;
}, },
cleanup() {
this.show = false;
},
async clickFace(face: IFace) { async clickFace(face: IFace) {
const user = this.$route.params.user || ''; const user = this.$route.params.user || '';
const name = this.$route.params.name || ''; const name = this.$route.params.name || '';

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" size="large" v-if="show"> <Modal ref="modal" @close="cleanup" size="large" v-if="show">
<template #title> <template #title>
{{ t('memories', 'Move selected photos to person') }} {{ t('memories', 'Move selected photos to person') }}
</template> </template>
@ -28,6 +28,8 @@ import Cluster from '../frame/Cluster.vue';
import FaceList from './FaceList.vue'; import FaceList from './FaceList.vue';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import * as dav from '../../services/dav'; import * as dav from '../../services/dav';
import * as utils from '../../services/utils'; import * as utils from '../../services/utils';
@ -41,10 +43,11 @@ export default defineComponent({
FaceList, FaceList,
}, },
mixins: [ModalMixin],
emits: [], emits: [],
data: () => ({ data: () => ({
show: false,
photos: [] as IPhoto[], photos: [] as IPhoto[],
}), }),
@ -75,9 +78,9 @@ export default defineComponent({
this.photos = photos; this.photos = photos;
}, },
close() { cleanup() {
this.photos = [];
this.show = false; this.show = false;
this.photos = [];
}, },
moved(photos: IPhoto[]) { moved(photos: IPhoto[]) {

View File

@ -1,11 +1,12 @@
<template> <template>
<NcModal <NcModal
class="memories-modal" class="memories-modal"
ref="modal"
:size="size" :size="size"
:outTransition="true" :outTransition="true"
:style="{ width: isSidebarShown ? `calc(100% - ${sidebarWidth}px)` : null }" :style="{ width: isSidebarShown ? `calc(100% - ${sidebarWidth}px)` : null }"
:additionalTrapElements="trapElements" :additionalTrapElements="trapElements"
@close="close" @close="cleanup"
> >
<div class="container" @keydown.stop="0"> <div class="container" @keydown.stop="0">
<div class="head"> <div class="head">
@ -83,6 +84,10 @@ export default defineComponent({
methods: { methods: {
close() { close() {
(<any>this.$refs.modal).close();
},
cleanup() {
this.$emit('close'); this.$emit('close');
}, },

View File

@ -0,0 +1,33 @@
import { defineComponent } from 'vue';
import * as utils from '../../services/utils';
export default defineComponent({
name: 'ModalMixin',
data: () => ({
show: false,
}),
mounted() {
utils.bus.on('memories:fragment:pop:modal', this.close);
},
beforeDestroy() {
utils.bus.off('memories:fragment:pop:modal', this.close);
},
watch: {
show(value: boolean, from: boolean) {
utils.fragment.if(value, utils.fragment.types.modal);
},
},
methods: {
close() {
if (this.show) {
(<any>this.$refs.modal)?.close?.();
}
},
},
});

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" size="normal" v-if="processing"> <Modal ref="modal" @close="cleanup" size="normal" v-if="processing">
<template #title> <template #title>
{{ t('memories', 'Move to folder') }} {{ t('memories', 'Move to folder') }}
</template> </template>
@ -23,8 +23,9 @@ import type { IPhoto } from '../../types';
const NcProgressBar = () => import('@nextcloud/vue/dist/Components/NcProgressBar'); const NcProgressBar = () => import('@nextcloud/vue/dist/Components/NcProgressBar');
import UserConfig from '../../mixins/UserConfig';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import UserConfig from '../../mixins/UserConfig';
import ModalMixin from './ModalMixin';
export default defineComponent({ export default defineComponent({
name: 'MoveToFolderModal', name: 'MoveToFolderModal',
@ -33,7 +34,7 @@ export default defineComponent({
Modal, Modal,
}, },
mixins: [UserConfig], mixins: [UserConfig, ModalMixin],
data: () => ({ data: () => ({
photos: [] as IPhoto[], photos: [] as IPhoto[],
@ -51,13 +52,12 @@ export default defineComponent({
this.photosDone = 0; this.photosDone = 0;
this.processing = false; this.processing = false;
this.photos = photos; this.photos = photos;
this.chooseFolderPath(); this.chooseFolderPath();
}, },
close() { cleanup() {
this.photos = [];
this.processing = false; this.processing = false;
this.photos = [];
}, },
async chooseFolderPath() { async chooseFolderPath() {

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" v-if="show" size="small"> <Modal ref="modal" @close="cleanup" v-if="show" size="small">
<template #title> <template #title>
{{ title }} {{ title }}
</template> </template>
@ -31,14 +31,15 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import Modal from './Modal.vue';
import * as utils from '../../services/utils'; import * as utils from '../../services/utils';
import NcActions from '@nextcloud/vue/dist/Components/NcActions'; import NcActions from '@nextcloud/vue/dist/Components/NcActions';
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton'; import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton';
import NcButton from '@nextcloud/vue/dist/Components/NcButton'; import NcButton from '@nextcloud/vue/dist/Components/NcButton';
import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import CloseIcon from 'vue-material-design-icons/Close.vue'; import CloseIcon from 'vue-material-design-icons/Close.vue';
export default defineComponent({ export default defineComponent({
@ -51,6 +52,8 @@ export default defineComponent({
CloseIcon, CloseIcon,
}, },
mixins: [ModalMixin],
props: { props: {
title: { title: {
type: String, type: String,
@ -63,23 +66,22 @@ export default defineComponent({
}, },
data: () => ({ data: () => ({
show: false,
paths: [] as string[], paths: [] as string[],
}), }),
methods: { methods: {
close(list: string[]) {
this.show = false;
this.$emit('close', list);
},
open(paths: string[]) { open(paths: string[]) {
this.paths = paths; this.paths = paths;
this.show = true; this.show = true;
}, },
cleanup() {
this.show = false;
this.$emit('close', this.paths);
},
save() { save() {
this.close(this.paths); this.close();
}, },
async add() { async add() {

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" size="normal" v-if="show" :sidebar="!isRoot && !isMobile ? filename : null"> <Modal ref="modal" @close="cleanup" size="normal" v-if="show" :sidebar="!isRoot && !isMobile ? filename : null">
<template #title> <template #title>
{{ t('memories', 'Link Sharing') }} {{ t('memories', 'Link Sharing') }}
</template> </template>
@ -70,6 +70,7 @@ const NcListItem = () => import('@nextcloud/vue/dist/Components/NcListItem');
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton'; import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton';
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import { API } from '../../services/API'; import { API } from '../../services/API';
import * as utils from '../../services/utils'; import * as utils from '../../services/utils';
@ -100,12 +101,11 @@ export default defineComponent({
LinkIcon, LinkIcon,
}, },
mixins: [UserConfig], mixins: [UserConfig, ModalMixin],
emits: [], emits: [],
data: () => ({ data: () => ({
show: false,
filename: '', filename: '',
loading: false, loading: false,
shares: [] as IShare[], shares: [] as IShare[],
@ -158,7 +158,7 @@ export default defineComponent({
} }
}, },
close() { cleanup() {
this.show = false; this.show = false;
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<Modal @close="close" size="normal" v-if="photo"> <Modal ref="modal" @close="cleanup" size="normal" v-if="show">
<template #title> <template #title>
{{ t('memories', 'Share File') }} {{ t('memories', 'Share File') }}
</template> </template>
@ -78,7 +78,9 @@ import { showError } from '@nextcloud/dialogs';
import axios from '@nextcloud/axios'; import axios from '@nextcloud/axios';
const NcListItem = () => import('@nextcloud/vue/dist/Components/NcListItem'); const NcListItem = () => import('@nextcloud/vue/dist/Components/NcListItem');
import Modal from './Modal.vue'; import Modal from './Modal.vue';
import ModalMixin from './ModalMixin';
import UserConfig from '../../mixins/UserConfig'; import UserConfig from '../../mixins/UserConfig';
import { IPhoto } from '../../types'; import { IPhoto } from '../../types';
@ -105,7 +107,7 @@ export default defineComponent({
FileIcon, FileIcon,
}, },
mixins: [UserConfig], mixins: [UserConfig, ModalMixin],
data: () => { data: () => {
return { return {
@ -145,9 +147,11 @@ export default defineComponent({
open(photo: IPhoto) { open(photo: IPhoto) {
this.photo = photo; this.photo = photo;
this.loading = 0; this.loading = 0;
this.show = true;
}, },
close() { cleanup() {
this.show = false;
this.photo = null; this.photo = null;
}, },

View File

@ -5,6 +5,7 @@ import { bus } from './event-bus';
enum FragmentType { enum FragmentType {
viewer = 'v', viewer = 'v',
selection = 's', selection = 's',
modal = 'm',
} }
/** Names of fragments */ /** Names of fragments */
@ -110,10 +111,10 @@ export const fragment = {
return; return;
} }
// If the fragment is already in the list, // If the fragment is already in the list, we can't touch it.
// we can't touch it. This should never happen.
if (list.find((f) => f.type === frag.type)) { if (list.find((f) => f.type === frag.type)) {
console.error('[BUG] Fragment already in route', frag.type); console.debug('Fragment already in route', frag.type);
return;
} }
// Add fragment to route // Add fragment to route