Skip to content

Commit fb04b0e

Browse files
committed
Frontend: Refactor dialogs and lightbox photoprism#3168 photoprism#4777
Signed-off-by: Michael Mayer <michael@photoprism.app>
1 parent 341dfca commit fb04b0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+657
-458
lines changed

assets/templates/app.gohtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
</div>
3333
</div>
3434
</div>
35-
<div id="busy-overlay"><div class="splash-center"><progress id="busy-progress" class="html-progress" max="100"></progress></div></div>
35+
<div id="busy-overlay"><div class="splash-center"><progress id="busy-progress" class="html-progress" max="100"></progress></div></div>

frontend/src/app.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ Additional information can be found in our Developer Guide:
2323
2424
*/
2525

26+
import "common/debug";
2627
import "core-js/stable";
2728
import "regenerator-runtime/runtime";
2829
import "common/navigation";
2930
import $api from "common/api";
3031
import $notify from "common/notify";
3132
import { $view } from "common/view";
33+
import { $lightbox } from "common/lightbox";
3234
import { PhotoClipboard } from "common/clipboard";
3335
import $event from "pubsub-js";
3436
import $log from "common/log";
@@ -95,6 +97,7 @@ $config.update().finally(() => {
9597
app.config.globalProperties.$event = $event;
9698
app.config.globalProperties.$notify = $notify;
9799
app.config.globalProperties.$view = $view;
100+
app.config.globalProperties.$lightbox = $lightbox;
98101
app.config.globalProperties.$session = $session;
99102
app.config.globalProperties.$api = $api;
100103
app.config.globalProperties.$log = $log;
@@ -161,13 +164,13 @@ $config.update().finally(() => {
161164
components.install(app);
162165

163166
// Make scroll-pos-restore compatible with bfcache (required to work in PWA mode on iOS).
164-
window.addEventListener("pagehide", (event) => {
165-
if (event.persisted) {
167+
window.addEventListener("pagehide", (ev) => {
168+
if (ev.persisted) {
166169
localStorage.setItem("lastScrollPosBeforePageHide", JSON.stringify({ x: window.scrollX, y: window.scrollY }));
167170
}
168171
});
169-
window.addEventListener("pageshow", (event) => {
170-
if (event.persisted) {
172+
window.addEventListener("pageshow", (ev) => {
173+
if (ev.persisted) {
171174
const lastSavedScrollPos = localStorage.getItem("lastScrollPosBeforePageHide");
172175
if (lastSavedScrollPos !== undefined && lastSavedScrollPos !== null && lastSavedScrollPos !== "") {
173176
window.positionToRestore = JSON.parse(localStorage.getItem("lastScrollPosBeforePageHide"));

frontend/src/app.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</v-main>
1313
</v-app>
1414

15-
<p-lightbox ref="lightbox"></p-lightbox>
15+
<p-dialogs></p-dialogs>
1616
</div>
1717
</template>
1818

@@ -21,15 +21,15 @@ import Event from "pubsub-js";
2121
import PLoadingBar from "component/loading-bar.vue";
2222
import PNotify from "component/notify.vue";
2323
import PNavigation from "component/navigation.vue";
24-
import PLightbox from "component/lightbox.vue";
24+
import PDialogs from "component/dialogs.vue";
2525
2626
export default {
2727
name: "App",
2828
components: {
2929
PLoadingBar,
3030
PNotify,
3131
PNavigation,
32-
PLightbox,
32+
PDialogs,
3333
},
3434
data() {
3535
return {

frontend/src/common/captions.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ class PhotoSwipeDynamicCaption {
128128
if (slide.captionFadeTimeout) {
129129
clearTimeout(slide.captionFadeTimeout);
130130
}
131+
131132
slide.captionFadeTimeout = setTimeout(() => {
132-
captionElement.style.visibility = "hidden";
133+
if (captionElement) {
134+
captionElement.style.visibility = "hidden";
135+
}
133136
delete slide.captionFadeTimeout;
134137
}, 400);
135138
}
@@ -150,9 +153,14 @@ class PhotoSwipeDynamicCaption {
150153
slide.dynamicCaption.hidden = false;
151154
captionElement.style.visibility = "visible";
152155

153-
clearTimeout(slide.captionFadeTimeout);
156+
if (slide.captionFadeTimeout) {
157+
clearTimeout(slide.captionFadeTimeout);
158+
}
159+
154160
slide.captionFadeTimeout = setTimeout(() => {
155-
captionElement.classList.remove("pswp__dynamic-caption--faded");
161+
if (captionElement) {
162+
captionElement.classList.remove("pswp__dynamic-caption--faded");
163+
}
156164
delete slide.captionFadeTimeout;
157165
}, 50);
158166
}

frontend/src/common/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export default class Config {
173173
}
174174

175175
if (values.jsUri && this.values.jsUri !== values.jsUri) {
176-
$event.publish("dialog.reload", { values });
176+
$event.publish("dialog.update", { values });
177177
}
178178

179179
for (let key in values) {

frontend/src/common/debug.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let lastLog = Date.now();
2+
let log = console.log;
3+
4+
console.log = function () {
5+
if (!window.__CONFIG__?.debug) {
6+
return;
7+
}
8+
9+
if (log && arguments.length) {
10+
const args = Array.from(arguments);
11+
if (typeof args[0] === "string") {
12+
args[0] += ` [${Date.now() - lastLog}ms]`;
13+
}
14+
log.apply(console, args);
15+
lastLog = Date.now();
16+
}
17+
};

frontend/src/common/lightbox.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import $event from "pubsub-js";
2+
3+
// Opens the lightbox dialog with the specified options.
4+
export class Lightbox {
5+
open(options) {
6+
$event.publish("lightbox.open", options);
7+
}
8+
9+
openModels(models, index) {
10+
$event.publish("lightbox.open", { models, index });
11+
}
12+
13+
openView(view, index) {
14+
$event.publish("lightbox.open", { view, index });
15+
}
16+
}
17+
18+
export const $lightbox = new Lightbox();

frontend/src/common/view.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const TouchStartEvent = "touchstart";
44
const TouchMoveEvent = "touchmove";
55

66
// If true, logging is enabled.
7-
const log = window.__CONFIG__?.debug && typeof console.log == "function";
7+
const debug = window.__CONFIG__?.debug;
88

99
// Returns the <html> element.
1010
export function getHtmlElement() {
@@ -16,7 +16,7 @@ export function initHtmlElement() {
1616
const htmlElement = document.documentElement;
1717

1818
if (htmlElement && htmlElement.hasAttribute("class")) {
19-
if (log) {
19+
if (debug) {
2020
console.log(`html: removed class="${htmlElement.getAttribute("class")}"`);
2121
}
2222

@@ -28,7 +28,7 @@ export function initHtmlElement() {
2828
if (document.body.classList.contains("hide-scrollbar")) {
2929
htmlElement.setAttribute("class", "hide-scrollbar");
3030

31-
if (log) {
31+
if (debug) {
3232
console.log('html: added class="hide-scrollbar" to permanently hide the scrollbar');
3333
}
3434
}
@@ -210,7 +210,7 @@ export class View {
210210

211211
this.preventNavigation = preventNavigation;
212212

213-
if (log && name && uid) {
213+
if (debug && name && uid) {
214214
const scope = this.scopes.map((s) => `${s?.$options?.name} #${s?.$?.uid.toString()}`).join(" › ");
215215
console.log(`view: ${scope}`, toRaw(c?.$data));
216216
}
@@ -220,47 +220,47 @@ export class View {
220220
bodyEl.classList.add("hide-scrollbar");
221221
setHtmlStyle("scrollbar-width", "none");
222222
setHtmlStyle("overflow-y", "hidden");
223-
if (log) {
223+
if (debug) {
224224
console.log(`html: added style="scrollbar-width: none; overflow-y: hidden;"`);
225225
}
226226
}
227227
} else if (bodyEl.classList.contains("hide-scrollbar")) {
228228
bodyEl.classList.remove("hide-scrollbar");
229229
setHtmlStyle("scrollbar-width");
230230
setHtmlStyle("overflow-y");
231-
if (log) {
231+
if (debug) {
232232
console.log(`html: removed style="scrollbar-width: none; overflow-y: hidden;"`);
233233
}
234234
}
235235

236236
if (disableScrolling) {
237237
if (!bodyEl.classList.contains("disable-scrolling")) {
238238
bodyEl.classList.add("disable-scrolling");
239-
if (log) {
239+
if (debug) {
240240
console.log(`body: added class="disable-scrolling"`);
241241
}
242242
}
243243
} else if (bodyEl.classList.contains("disable-scrolling")) {
244244
bodyEl.classList.remove("disable-scrolling");
245-
if (log) {
245+
if (debug) {
246246
console.log(`body: removed class="disable-scrolling"`);
247247
}
248248
}
249249

250250
if (disableNavigationGestures) {
251251
if (!bodyEl.classList.contains("disable-navigation-gestures")) {
252252
bodyEl.classList.add("disable-navigation-gestures");
253-
document.addEventListener(TouchStartEvent, preventNavigationTouchEvent, { passive: false });
254-
document.addEventListener(TouchMoveEvent, preventNavigationTouchEvent, { passive: false });
255-
if (log) {
253+
window.addEventListener(TouchStartEvent, preventNavigationTouchEvent, { passive: false });
254+
window.addEventListener(TouchMoveEvent, preventNavigationTouchEvent, { passive: false });
255+
if (debug) {
256256
console.log(`view: disabled touch navigation gestures`);
257257
}
258258
}
259259
} else if (bodyEl.classList.contains("disable-navigation-gestures")) {
260260
bodyEl.classList.remove("disable-navigation-gestures");
261-
document.removeEventListener(TouchStartEvent, preventNavigationTouchEvent, false);
262-
document.removeEventListener(TouchMoveEvent, preventNavigationTouchEvent, false);
263-
if (log) {
261+
window.removeEventListener(TouchStartEvent, preventNavigationTouchEvent, false);
262+
window.removeEventListener(TouchMoveEvent, preventNavigationTouchEvent, false);
263+
if (debug) {
264264
console.log(`view: re-enabled touch navigation gestures`);
265265
}
266266
}

frontend/src/component/album/clipboard.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@
9191
</v-speed-dial>
9292
</div>
9393
<p-photo-album-dialog
94-
:show="dialog.album"
94+
:visible="dialog.album"
9595
@close="dialog.album = false"
9696
@confirm="cloneAlbums"
9797
></p-photo-album-dialog>
9898
<p-album-delete-dialog
99-
:show="dialog.delete"
99+
:visible="dialog.delete"
100100
@close="dialog.delete = false"
101101
@confirm="batchDelete"
102102
></p-album-delete-dialog>

frontend/src/component/album/delete/dialog.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<v-dialog :model-value="show" persistent max-width="350" class="p-dialog p-album-delete-dialog" @keydown.esc="close">
2+
<v-dialog :model-value="visible" persistent max-width="350" class="p-dialog p-album-delete-dialog" @keydown.esc="close">
33
<v-card>
44
<v-card-title class="d-flex justify-start align-center ga-3">
55
<v-icon icon="mdi-delete-outline" size="54" color="primary"></v-icon>
@@ -20,7 +20,7 @@
2020
export default {
2121
name: "PAlbumDeleteDialog",
2222
props: {
23-
show: Boolean,
23+
visible: Boolean,
2424
},
2525
data() {
2626
return {};

0 commit comments

Comments
 (0)