Skip to content

Commit

Permalink
refactor: move modal functions to namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <radialapps@gmail.com>
  • Loading branch information
pulsejet committed Sep 30, 2023
1 parent 87b99fe commit 23d54d3
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export default defineComponent({
utils.bus.on('memories:user-config-changed', this.refreshNav);
// Register global functions
globalThis.showSettings = () => this.showSettings();
mModals.showSettings = this.showSettings;
},
mounted() {
Expand Down
25 changes: 15 additions & 10 deletions src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ declare global {
var mode: 'admin' | 'user';

var vueroute: () => Route;
var OC: Nextcloud.v24.OC;
var OCP: Nextcloud.v24.OCP;

var editMetadata: (photos: IPhoto[], sections?: number[]) => void;
var updateAlbums: (photos: IPhoto[]) => void;
var sharePhoto: (photo: IPhoto) => void;
var shareNodeLink: (path: string, immediate?: boolean) => Promise<void>;
var moveToFolder: (photos: IPhoto[]) => void;
var moveToFace: (photos: IPhoto[]) => void;
var showSettings: () => void;
var OC: Nextcloud.Common.OC;
var OCP: Nextcloud.Common.OCP;

var mModals: {
editMetadata: (photos: IPhoto[], sections?: number[]) => void;
updateAlbums: (photos: IPhoto[]) => void;
sharePhoto: (photo: IPhoto) => void;
shareNodeLink: (path: string, immediate?: boolean) => Promise<void>;
moveToFolder: (photos: IPhoto[]) => void;
moveToFace: (photos: IPhoto[]) => void;
showSettings: () => void;
};

var mSidebar: {
open: (photo: IPhoto | number, filename?: string, forceNative?: boolean) => void;
Expand Down Expand Up @@ -72,6 +74,9 @@ declare global {
// Allow global access to the router
globalThis.vueroute = () => router.currentRoute;

// Initialize blank arrays
globalThis.mModals = {} as any;

// Cache these for better performance
globalThis.windowInnerWidth = window.innerWidth;
globalThis.windowInnerHeight = window.innerHeight;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Explore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default defineComponent({
name: t('memories', 'Settings'),
icon: CogIcon,
link: undefined,
click: globalThis.showSettings,
click: mModals.showSettings,
},
] as {
name: string;
Expand Down
8 changes: 4 additions & 4 deletions src/components/Metadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,19 @@ export default defineComponent({
},
editDate() {
globalThis.editMetadata([globalThis.currentViewerPhoto], [1]);
mModals.editMetadata([globalThis.currentViewerPhoto], [1]);
},
editTags() {
globalThis.editMetadata([globalThis.currentViewerPhoto], [2]);
mModals.editMetadata([globalThis.currentViewerPhoto], [2]);
},
editEXIF() {
globalThis.editMetadata([globalThis.currentViewerPhoto], [3]);
mModals.editMetadata([globalThis.currentViewerPhoto], [3]);
},
editGeo() {
globalThis.editMetadata([globalThis.currentViewerPhoto], [4]);
mModals.editMetadata([globalThis.currentViewerPhoto], [4]);
},
async refresh() {
Expand Down
8 changes: 4 additions & 4 deletions src/components/SelectionManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ export default defineComponent({
* Open the edit date dialog
*/
async editMetadataSelection(selection: Selection, sections?: number[]) {
globalThis.editMetadata(selection.photosNoDupFileId(), sections);
mModals.editMetadata(selection.photosNoDupFileId(), sections);
},
/**
Expand All @@ -817,14 +817,14 @@ export default defineComponent({
* Move selected photos to album
*/
async addToAlbum(selection: Selection) {
globalThis.updateAlbums(selection.photosNoDupFileId());
mModals.updateAlbums(selection.photosNoDupFileId());
},
/**
* Move selected photos to folder
*/
async moveToFolder(selection: Selection) {
globalThis.moveToFolder(selection.photosNoDupFileId());
mModals.moveToFolder(selection.photosNoDupFileId());
},
/**
Expand All @@ -835,7 +835,7 @@ export default defineComponent({
showError(this.t('memories', 'You must enable "Mark person in preview" to use this feature'));
return;
}
globalThis.moveToFace(Array.from(selection.values()));
mModals.moveToFace(Array.from(selection.values()));
},
/**
Expand Down
6 changes: 3 additions & 3 deletions src/components/modal/AddToAlbumModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export default defineComponent({
},
},
mounted() {
console.assert(!globalThis.updateAlbums, 'AddToAlbumModal mounted twice');
globalThis.updateAlbums = this.open;
created() {
console.assert(!mModals.updateAlbums, 'AddToAlbumModal created twice');
mModals.updateAlbums = this.open;
},
methods: {
Expand Down
5 changes: 3 additions & 2 deletions src/components/modal/EditMetadataModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export default defineComponent({
state: 0,
}),
mounted() {
globalThis.editMetadata = this.open;
created() {
console.assert(!mModals.editMetadata, 'EditMetadataModal created twice');
mModals.editMetadata = this.open;
},
methods: {
Expand Down
3 changes: 2 additions & 1 deletion src/components/modal/FaceMoveModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export default defineComponent({
}),
created() {
globalThis.moveToFace = this.open.bind(this);
console.assert(!mModals.moveToFace, 'FaceMoveModal created twice');
mModals.moveToFace = this.open;
},
methods: {
Expand Down
11 changes: 7 additions & 4 deletions src/components/modal/MoveToFolderModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ export default defineComponent({
}),
created() {
globalThis.moveToFolder = (photos: IPhoto[]) => {
console.assert(!mModals.moveToFolder, 'MoveToFolderModal created twice');
mModals.moveToFolder = this.open;
},
methods: {
open(photos: IPhoto[]) {
this.photosDone = 0;
this.processing = false;
this.photos = photos;
this.chooseFolderPath();
};
},
},
methods: {
close() {
this.photos = [];
this.processing = false;
Expand Down
3 changes: 2 additions & 1 deletion src/components/modal/NodeShareModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export default defineComponent({
},
created() {
globalThis.shareNodeLink = this.open;
console.assert(!mModals.shareNodeLink, 'NodeShareModal created twice');
mModals.shareNodeLink = this.open;
},
methods: {
Expand Down
13 changes: 8 additions & 5 deletions src/components/modal/ShareModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ export default defineComponent({
},
created() {
globalThis.sharePhoto = (photo: IPhoto) => {
this.photo = photo;
this.loading = 0;
};
console.assert(!mModals.sharePhoto, 'ShareModal created twice');
mModals.sharePhoto = this.open;
},
computed: {
Expand All @@ -140,6 +138,11 @@ export default defineComponent({
},
methods: {
open(photo: IPhoto) {
this.photo = photo;
this.loading = 0;
},
close() {
this.photo = null;
},
Expand Down Expand Up @@ -177,7 +180,7 @@ export default defineComponent({
async shareLink() {
this.l(async () => {
const fileInfo = (await dav.getFiles([this.photo!]))[0];
globalThis.shareNodeLink(fileInfo.filename, true);
mModals.shareNodeLink(fileInfo.filename, true);
});
this.close();
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/top-matter/FolderTopMatter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default defineComponent({
methods: {
share() {
globalThis.shareNodeLink(utils.getFolderRoutePath(this.config.folders_path));
mModals.shareNodeLink(utils.getFolderRoutePath(this.config.folders_path));
},
toggleRecursive() {
Expand Down
6 changes: 3 additions & 3 deletions src/components/viewer/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ export default defineComponent({
/** Share the current photo externally */
async shareCurrent() {
globalThis.sharePhoto(this.currentPhoto!);
mModals.sharePhoto(this.currentPhoto!);
},
/** Key press events */
Expand Down Expand Up @@ -1186,14 +1186,14 @@ export default defineComponent({
* Edit metadata for current photo
*/
editMetadata() {
globalThis.editMetadata([globalThis.currentViewerPhoto]);
mModals.editMetadata([globalThis.currentViewerPhoto]);
},
/**
* Update album selection for current photo
*/
updateAlbums() {
globalThis.updateAlbums([this.currentPhoto!]);
mModals.updateAlbums([this.currentPhoto!]);
},
},
});
Expand Down

0 comments on commit 23d54d3

Please sign in to comment.