refactor: viewer

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/888/head
Varun Patil 2023-10-24 00:47:37 -07:00
parent a0f40dfcae
commit 8eefae4247
2 changed files with 24 additions and 16 deletions

View File

@ -639,6 +639,22 @@ export default defineComponent({
return this.photoswipe; 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 */ /** Open using start photo and rows list */
async openDynamic(anchorPhoto: IPhoto, rows: IRow[]) { async openDynamic(anchorPhoto: IPhoto, rows: IRow[]) {
const detail = anchorPhoto.d?.detail; const detail = anchorPhoto.d?.detail;
@ -869,22 +885,6 @@ export default defineComponent({
return elem; 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 * Load the metadata (image info) for a photo asynchronously
*/ */

View File

@ -53,6 +53,9 @@ const cache = {
}; };
export default { export default {
/**
* List of all fragment types.
*/
types: FragmentType, types: FragmentType,
/** /**
@ -148,6 +151,11 @@ export default {
return this.get(FragmentType.viewer); 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) { changeTrigger(to: Route, from: Route) {
const toF = decodeFragment(to.hash); const toF = decodeFragment(to.hash);
const fromF = decodeFragment(from.hash); const fromF = decodeFragment(from.hash);