Skip to content

Commit 7a5301c

Browse files
committed
Upload: Update search results after uploading files photoprism#4799
Signed-off-by: Michael Mayer <michael@photoprism.app>
1 parent 343260b commit 7a5301c

File tree

10 files changed

+93
-65
lines changed

10 files changed

+93
-65
lines changed

frontend/src/common/config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ export default class Config {
169169
setValues(values) {
170170
if (!values) return;
171171

172-
if (this.debug) {
173-
console.log("config: updated", values);
174-
}
175-
176172
if (values.jsUri && this.values.jsUri !== values.jsUri) {
177173
$event.publish("dialog.update", { values });
178174
}

frontend/src/common/event.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
1-
import * as pubsub from "pubsub-js";
1+
// True if debug and/or trace logs should be recorded.
2+
const debug = window.__CONFIG__?.debug;
3+
const trace = window.__CONFIG__?.trace;
24

3-
const $event = pubsub;
5+
// Use global variable to configure pubsub.js, a dependency-free publish/subscribe event hub:
6+
// https://sahadar.github.io/pubsub/#installation
7+
window.pubsub = {
8+
separator: ".",
9+
recurrent: true,
10+
async: true,
11+
log: trace,
12+
};
413

14+
// Import pubsub.js, see https://www.npmjs.com/package/pubsub-js.
15+
import * as PubSub from "pubsub-js";
16+
17+
// Use $event as a generic alias for publishing and subscribing to events.
18+
const $event = PubSub;
19+
20+
// Log all events when running in trace log mode, and log config events in debug mode.
21+
// Event names are displayed in blue so that they are easy to recognize.
22+
if (trace) {
23+
$event.subscribeAll((ev, data) => {
24+
if (data) {
25+
console.debug(`%c${ev}`, "background: transparent; color: #1E88E5; font-weight: normal;", data);
26+
} else {
27+
console.debug(`%c${ev}`, "background: transparent; color: #1E88E5; font-weight: normal;");
28+
}
29+
});
30+
} else if (debug) {
31+
$event.subscribe("config", (ev, data) => {
32+
if (data) {
33+
console.debug(`%c${ev}`, "background: transparent; color: #1E88E5; font-weight: normal;", data);
34+
} else {
35+
console.debug(`%c${ev}`, "background: transparent; color: #1E88E5; font-weight: normal;");
36+
}
37+
});
38+
}
39+
40+
// Export $event to publish and subscribe to events.
541
export default $event;

frontend/src/common/view.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,15 @@ export class View {
213213
return false;
214214
}
215215

216-
// If debug mode is enabled, create a new log group in the browser console:
216+
// When debug mode is enabled, write logs to a collapsed group in the browser console:
217217
// https://developer.mozilla.org/en-US/docs/Web/API/console/groupCollapsed_static
218218
if (debug) {
219-
const scope = this.scopes.map((s) => `${s?.$options?.name} #${s?.$?.uid.toString()}`).join(" ▶ ");
219+
const scope = this.scopes.map((s) => `${s?.$options?.name} #${s?.$?.uid.toString()}`).join(" › ");
220+
// To make them easy to recognize, the collapsed view logs are displayed
221+
// in the browser console with bold white text on a purple background.
220222
console.groupCollapsed(
221223
`%c${scope}`,
222-
"background: #502A85; color: white; padding: 2px 6px; border-radius: 8px; font-weight: bold;"
224+
"background: #502A85; color: white; padding: 3px 5px; border-radius: 8px; font-weight: bold;"
223225
);
224226
console.log("data:", toRaw(c?.$data));
225227
}

frontend/src/component/dialogs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<script>
2222
import Album from "model/album";
2323
24-
import PPhotoUploadDialog from "component/photo/upload/dialog.vue";
2524
import PPhotoEditDialog from "component/photo/edit/dialog.vue";
25+
import PPhotoUploadDialog from "component/photo/upload/dialog.vue";
2626
import PUpdate from "component/update.vue";
2727
import PLightbox from "component/lightbox.vue";
2828

frontend/src/component/lightbox.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,9 +1436,9 @@ export default {
14361436
// see https://developer.chrome.com/blog/play-request-was-interrupted.
14371437
const playPromise = video.play();
14381438
if (playPromise !== undefined) {
1439-
playPromise.catch((e) => {
1440-
if (this.trace) {
1441-
console.log(e.message);
1439+
playPromise.catch((err) => {
1440+
if (this.trace && err && err.message) {
1441+
console.log(err.message);
14421442
}
14431443
});
14441444
}

frontend/src/component/photo/view/cards.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,10 @@ export default {
442442
// see https://developer.chrome.com/blog/play-request-was-interrupted.
443443
const playPromise = player.play();
444444
if (playPromise !== undefined) {
445-
playPromise.catch((e) => {
446-
if (this.trace) {
447-
console.log(e.message);
445+
playPromise.catch((err) => {
446+
if (this.trace && err && err.message) {
447+
// Ignore this error, or uncomment the following line to log it.
448+
// console.debug(err.message);
448449
}
449450
});
450451
}
@@ -513,14 +514,14 @@ export default {
513514
*/
514515
this.$forceUpdate();
515516
},
516-
onOpen(ev, index, showMerged, preferVideo) {
517+
onOpen(ev, index, showMerged) {
517518
const inputType = this.input.eval(ev, index);
518519
519520
if (inputType !== ClickShort) {
520521
return;
521522
}
522523
523-
this.openPhoto(index, showMerged, preferVideo);
524+
this.openPhoto(index, showMerged);
524525
},
525526
onClick(ev, index) {
526527
const inputType = this.input.eval(ev, index);

frontend/src/component/photo/view/list.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<button
8080
v-else-if="m.Type === 'video' || m.Type === 'live' || m.Type === 'animated'"
8181
class="input-open"
82-
@click.stop.prevent="openPhoto(index, false, m.Type === 'live')"
82+
@click.stop.prevent="openPhoto(index, false)"
8383
>
8484
<i v-if="m.Type === 'live'" class="action-live" :title="$gettext('Live')"><icon-live-photo /></i>
8585
<i v-if="m.Type === 'animated'" class="mdi mdi-file-gif-box" :title="$gettext('Animated')" />

frontend/src/component/photo/view/mosaic.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,10 @@ export default {
268268
// see https://developer.chrome.com/blog/play-request-was-interrupted.
269269
const playPromise = player.play();
270270
if (playPromise !== undefined) {
271-
playPromise.catch((e) => {
272-
if (this.trace) {
273-
console.log(e.message);
271+
playPromise.catch((err) => {
272+
if (this.trace && err && err.message) {
273+
// Ignore this error, or uncomment the following line to log it.
274+
// console.debug(err.message);
274275
}
275276
});
276277
}
@@ -327,14 +328,14 @@ export default {
327328
this.$clipboard.toggle(photo);
328329
this.$forceUpdate();
329330
},
330-
onOpen(ev, index, showMerged, preferVideo) {
331+
onOpen(ev, index, showMerged) {
331332
const inputType = this.input.eval(ev, index);
332333
333334
if (inputType !== ClickShort) {
334335
return;
335336
}
336337
337-
this.openPhoto(index, showMerged, preferVideo);
338+
this.openPhoto(index, showMerged);
338339
},
339340
onClick(ev, index) {
340341
const inputType = this.input.eval(ev, index);

frontend/src/page/album/photos.vue

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export default {
292292
// Open Edit Dialog
293293
this.$event.publish("dialog.edit", { selection, album: this.album, index, tab });
294294
},
295-
openPhoto(index, showMerged = false, preferVideo = false) {
295+
openPhoto(index, showMerged = false) {
296296
if (this.loading || !this.listen || this.lightbox.loading || !this.results[index]) {
297297
return false;
298298
}
@@ -304,20 +304,6 @@ export default {
304304
showMerged = false;
305305
}
306306
307-
/**
308-
* If the file is a video or an animation (like gif), then we always play
309-
* it in the video-player.
310-
* If the file is a live-image (an image with an embedded video), then we only
311-
* play it in the video-player if specifically requested.
312-
* This is because:
313-
* 1. the lower-resolution video in these files is already
314-
* played when hovering the element (which does not happen for regular
315-
* video files)
316-
* 2. The video in live-images is an addon. The main focus is usually still
317-
* the high resolution image inside
318-
*
319-
* preferVideo is true, when the user explicitly clicks the live-image-icon.
320-
*/
321307
if (showMerged) {
322308
this.$lightbox.openModels(Thumb.fromFiles([selected]), 0);
323309
} else {
@@ -326,8 +312,10 @@ export default {
326312
327313
return true;
328314
},
329-
loadMore() {
330-
if (this.scrollDisabled || this.$view.isHidden(this)) return;
315+
loadMore(force) {
316+
if (!force && (this.scrollDisabled || this.$view.isHidden(this))) {
317+
return;
318+
}
331319
332320
this.scrollDisabled = true;
333321
this.listen = false;
@@ -434,10 +422,11 @@ export default {
434422
435423
if (this.model.Order !== this.filter.order) {
436424
this.model.Order = this.filter.order;
437-
this.updateAlbum();
438425
}
439426
440-
if (this.loading) return;
427+
if (this.loading) {
428+
return;
429+
}
441430
442431
const query = {
443432
view: this.settings.view,
@@ -487,6 +476,15 @@ export default {
487476
this.loadMore();
488477
},
489478
search() {
479+
/**
480+
* search is called on mount or route change. If the route changed to an
481+
* open lightbox, no search is required. There is no reason to do an
482+
* initial results load, if the results aren't currently visible
483+
*/
484+
if (this.lightbox.open) {
485+
return;
486+
}
487+
490488
this.scrollDisabled = true;
491489
492490
// Don't query the same data more than once
@@ -587,7 +585,7 @@ export default {
587585
this.filter.order = this.model.Order;
588586
this.updateQuery();
589587
} else {
590-
this.loadMore();
588+
this.loadMore(true);
591589
}
592590
593591
return;
@@ -623,7 +621,9 @@ export default {
623621
}
624622
},
625623
onUpdate(ev, data) {
626-
if (!this.listen) return;
624+
if (!this.listen) {
625+
return;
626+
}
627627
628628
if (!data || !data.entities) {
629629
return;

frontend/src/page/photos.vue

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ export default {
434434
// Open Edit Dialog
435435
this.$event.publish("dialog.edit", { selection, album: null, index, tab });
436436
},
437-
openPhoto(index, showMerged = false, preferVideo = false) {
437+
openPhoto(index, showMerged = false) {
438438
if (this.loading || !this.listen || this.lightbox.loading || !this.results[index]) {
439439
return false;
440440
}
@@ -446,20 +446,6 @@ export default {
446446
showMerged = false;
447447
}
448448
449-
/**
450-
* If the file is a video or an animation (like gif), then we always play
451-
* it in the video-player.
452-
* If the file is a live-image (an image with an embedded video), then we only
453-
* play it in the video-player if specifically requested.
454-
* This is because:
455-
* 1. the lower-resolution video in these files is already
456-
* played when hovering the element (which does not happen for regular
457-
* video files)
458-
* 2. The video in live-images is an addon. The main focus is usually still
459-
* the high resolution image inside
460-
*
461-
* preferVideo is true, when the user explicitly clicks the live-image-icon.
462-
*/
463449
if (showMerged) {
464450
this.$lightbox.openModels(Thumb.fromFiles([selected]), 0);
465451
} else {
@@ -468,8 +454,10 @@ export default {
468454
469455
return true;
470456
},
471-
loadMore() {
472-
if (this.scrollDisabled || this.$view.isHidden(this)) return;
457+
loadMore(force) {
458+
if (!force && (this.scrollDisabled || this.$view.isHidden(this))) {
459+
return;
460+
}
473461
474462
this.scrollDisabled = true;
475463
this.listen = false;
@@ -698,9 +686,11 @@ export default {
698686
});
699687
},
700688
onImportCompleted() {
701-
if (!this.listen) return;
689+
if (!this.listen) {
690+
return;
691+
}
702692
703-
this.loadMore();
693+
this.loadMore(true);
704694
},
705695
updateResults(entity) {
706696
this.results
@@ -731,7 +721,9 @@ export default {
731721
}
732722
},
733723
onUpdate(ev, data) {
734-
if (!this.listen) return;
724+
if (!this.listen) {
725+
return;
726+
}
735727
736728
if (!data || !data.entities || !Array.isArray(data.entities)) {
737729
return;

0 commit comments

Comments
 (0)