From 8eefae4247629e9123dbec74afbb57b78e1f0b2d Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 24 Oct 2023 00:47:37 -0700 Subject: [PATCH] refactor: viewer Signed-off-by: Varun Patil --- src/components/viewer/Viewer.vue | 32 ++++++++++++++++---------------- src/services/fragment.ts | 8 ++++++++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/components/viewer/Viewer.vue b/src/components/viewer/Viewer.vue index ee26d78b..4d38de62 100644 --- a/src/components/viewer/Viewer.vue +++ b/src/components/viewer/Viewer.vue @@ -639,6 +639,22 @@ export default defineComponent({ return this.photoswipe; }, + /** Set the route hash to the given photo */ + setFragment(photo: IPhoto | null) { + // Add or update fragment + if (photo) { + return fragment.push({ + type: fragment.types.viewer, + args: [String(photo.dayid), photo.key!], + }); + } + + // Remove fragment if closed + if (!this.isOpen) { + return fragment.pop(fragment.types.viewer); + } + }, + /** Open using start photo and rows list */ async openDynamic(anchorPhoto: IPhoto, rows: IRow[]) { const detail = anchorPhoto.d?.detail; @@ -869,22 +885,6 @@ export default defineComponent({ return elem; }, - /** Set the route hash to the given photo */ - setFragment(photo: IPhoto | null) { - // Add or update fragment - if (photo) { - return fragment.push({ - type: fragment.types.viewer, - args: [String(photo.dayid), photo.key!], - }); - } - - // Remove fragment if closed - if (!this.isOpen) { - return fragment.pop(fragment.types.viewer); - } - }, - /** * Load the metadata (image info) for a photo asynchronously */ diff --git a/src/services/fragment.ts b/src/services/fragment.ts index 5e5450f8..fa17abf0 100644 --- a/src/services/fragment.ts +++ b/src/services/fragment.ts @@ -53,6 +53,9 @@ const cache = { }; export default { + /** + * List of all fragment types. + */ types: FragmentType, /** @@ -148,6 +151,11 @@ export default { return this.get(FragmentType.viewer); }, + /** + * Trigger when route changes. Only called by App.vue as a router hook. + * @param to Switching to this route + * @param from Switching from this route + */ changeTrigger(to: Route, from: Route) { const toF = decodeFragment(to.hash); const fromF = decodeFragment(from.hash);