viewer: minor fixes

pull/175/head
Varun Patil 2022-11-05 17:22:02 -07:00 committed by Varun Patil
parent daf079f101
commit e276f51fc1
3 changed files with 53 additions and 20 deletions

View File

@ -370,18 +370,6 @@ export default class SelectionManager extends Mixins(GlobalMixin, UserConfig) {
Array.from(selection.values()), Array.from(selection.values()),
val val
)) { )) {
favIds.forEach((id) => {
const photo = selection.get(id);
if (!photo) {
return;
}
if (val) {
photo.flag |= this.c.FLAG_IS_FAVORITE;
} else {
photo.flag &= ~this.c.FLAG_IS_FAVORITE;
}
});
} }
this.clearSelection(); this.clearSelection();
} }

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="memories_viewer outer"> <div class="memories_viewer outer" v-if="show">
<div class="inner" ref="inner"> <div class="inner" ref="inner">
<div class="top-bar" v-if="photoswipe"> <div class="top-bar" v-if="photoswipe" :class="{ opened }">
<NcActions :inline="2" container=".memories_viewer .pswp"> <NcActions :inline="2" container=".memories_viewer .pswp">
<NcActionButton <NcActionButton
:aria-label="t('memories', 'Delete')" :aria-label="t('memories', 'Delete')"
@ -61,6 +61,9 @@ export default class Viewer extends Mixins(GlobalMixin) {
@Emit("fetchDay") fetchDay(dayId: number) {} @Emit("fetchDay") fetchDay(dayId: number) {}
@Emit("updateLoading") updateLoading(delta: number) {} @Emit("updateLoading") updateLoading(delta: number) {}
private show = false;
private opened = false;
/** Base dialog */ /** Base dialog */
private photoswipe: PhotoSwipe | null = null; private photoswipe: PhotoSwipe | null = null;
@ -71,7 +74,23 @@ export default class Viewer extends Mixins(GlobalMixin) {
private globalCount = 0; private globalCount = 0;
private globalAnchor = -1; private globalAnchor = -1;
private getBaseBox(args: PhotoSwipeOptions) { /** Get the currently open photo */
private getCurrentPhoto() {
if (!this.list.length || !this.photoswipe) {
return null;
}
const idx = this.photoswipe.currIndex - this.globalAnchor;
if (idx < 0 || idx >= this.list.length) {
return null;
}
return this.list[idx];
}
/** Create the base photoswipe object */
private async createBase(args: PhotoSwipeOptions) {
this.show = true;
await this.$nextTick();
this.photoswipe = new PhotoSwipe({ this.photoswipe = new PhotoSwipe({
counter: true, counter: true,
zoom: false, zoom: false,
@ -103,11 +122,19 @@ export default class Viewer extends Mixins(GlobalMixin) {
contentElem.classList.add(klass); contentElem.classList.add(klass);
navElem.style.zIndex = "0"; navElem.style.zIndex = "0";
}); });
this.photoswipe.on("openingAnimationStart", () => {
this.opened = true;
});
this.photoswipe.on("close", () => {
this.opened = false;
});
this.photoswipe.on("destroy", () => { this.photoswipe.on("destroy", () => {
contentElem.classList.remove(klass); contentElem.classList.remove(klass);
navElem.style.zIndex = ""; navElem.style.zIndex = "";
// reset everything // reset everything
this.show = false;
this.opened = false;
this.photoswipe = null; this.photoswipe = null;
this.list = []; this.list = [];
this.days.clear(); this.days.clear();
@ -119,6 +146,7 @@ export default class Viewer extends Mixins(GlobalMixin) {
return this.photoswipe; return this.photoswipe;
} }
/** Open using start photo and rows list */
public async open(anchorPhoto: IPhoto, rows?: IRow[]) { public async open(anchorPhoto: IPhoto, rows?: IRow[]) {
// list = list || photo.d?.detail; // list = list || photo.d?.detail;
// if (!list?.length) return; // if (!list?.length) return;
@ -198,7 +226,7 @@ export default class Viewer extends Mixins(GlobalMixin) {
} }
} }
this.getBaseBox({ await this.createBase({
index: this.globalAnchor + startIndex, index: this.globalAnchor + startIndex,
}); });
@ -287,6 +315,7 @@ export default class Viewer extends Mixins(GlobalMixin) {
this.photoswipe.init(); this.photoswipe.init();
} }
/** Get element for thumbnail if it exists */
private thumbElem(photo: IPhoto) { private thumbElem(photo: IPhoto) {
if (!photo) return; if (!photo) return;
return document.getElementById( return document.getElementById(
@ -294,6 +323,7 @@ export default class Viewer extends Mixins(GlobalMixin) {
); );
} }
/** Delete this photo and refresh */
private async deleteCurrent() { private async deleteCurrent() {
const idx = this.photoswipe.currIndex - this.globalAnchor; const idx = this.photoswipe.currIndex - this.globalAnchor;
@ -315,14 +345,16 @@ export default class Viewer extends Mixins(GlobalMixin) {
this.deleted(spliced); this.deleted(spliced);
} }
/** Is the current photo a favorite */
private isFavorite() { private isFavorite() {
const idx = this.photoswipe.currIndex - this.globalAnchor; const p = this.getCurrentPhoto();
return Boolean(this.list[idx].flag & this.c.FLAG_IS_FAVORITE); if (!p) return false;
return Boolean(p.flag & this.c.FLAG_IS_FAVORITE);
} }
/** Favorite the current photo */
private async favoriteCurrent() { private async favoriteCurrent() {
const idx = this.photoswipe.currIndex - this.globalAnchor; const photo = this.getCurrentPhoto();
const photo = this.list[idx];
const val = !this.isFavorite(); const val = !this.isFavorite();
try { try {
this.updateLoading(1); this.updateLoading(1);
@ -365,5 +397,11 @@ export default class Viewer extends Mixins(GlobalMixin) {
color: white; color: white;
background-color: transparent !important; background-color: transparent !important;
} }
transition: opacity 0.12s ease-in-out;
opacity: 0;
&.opened {
opacity: 1;
}
} }
</style> </style>

View File

@ -3,6 +3,7 @@ import { translate as t } from "@nextcloud/l10n";
import { IPhoto } from "../../types"; import { IPhoto } from "../../types";
import client from "../DavClient"; import client from "../DavClient";
import * as base from "./base"; import * as base from "./base";
import * as utils from "../Utils";
/** /**
* Favorite a file * Favorite a file
@ -61,6 +62,12 @@ export async function* favoritePhotos(
const calls = fileInfos.map((fileInfo) => async () => { const calls = fileInfos.map((fileInfo) => async () => {
try { try {
await favoriteFile(fileInfo.originalFilename, favoriteState); await favoriteFile(fileInfo.originalFilename, favoriteState);
const photo = photos.find((p) => p.fileid === fileInfo.fileid);
if (favoriteState) {
photo.flag |= utils.constants.c.FLAG_IS_FAVORITE;
} else {
photo.flag &= ~utils.constants.c.FLAG_IS_FAVORITE;
}
return fileInfo.fileid as number; return fileInfo.fileid as number;
} catch (error) { } catch (error) {
console.error("Failed to favorite", fileInfo, error); console.error("Failed to favorite", fileInfo, error);