Immediately render newly uploaded photo and scroll to it
This commit is contained in:
@@ -26,6 +26,7 @@ export default class PlaceDetails extends Component {
|
|||||||
@tracked showLists = false;
|
@tracked showLists = false;
|
||||||
@tracked isPhotoUploadModalOpen = false;
|
@tracked isPhotoUploadModalOpen = false;
|
||||||
@tracked isNostrConnectModalOpen = false;
|
@tracked isNostrConnectModalOpen = false;
|
||||||
|
@tracked newlyUploadedPhotoId = null;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
openPhotoUploadModal(e) {
|
openPhotoUploadModal(e) {
|
||||||
@@ -40,8 +41,11 @@ export default class PlaceDetails extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
closePhotoUploadModal() {
|
closePhotoUploadModal(eventId) {
|
||||||
this.isPhotoUploadModalOpen = false;
|
this.isPhotoUploadModalOpen = false;
|
||||||
|
if (typeof eventId === 'string') {
|
||||||
|
this.newlyUploadedPhotoId = eventId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@@ -352,7 +356,11 @@ export default class PlaceDetails extends Component {
|
|||||||
@onCancel={{this.cancelEditing}}
|
@onCancel={{this.cancelEditing}}
|
||||||
/>
|
/>
|
||||||
{{else}}
|
{{else}}
|
||||||
<PlacePhotosCarousel @photos={{this.photos}} @name={{this.name}} />
|
<PlacePhotosCarousel
|
||||||
|
@photos={{this.photos}}
|
||||||
|
@name={{this.name}}
|
||||||
|
@scrollToEventId={{this.newlyUploadedPhotoId}}
|
||||||
|
/>
|
||||||
<h3>{{this.name}}</h3>
|
<h3>{{this.name}}</h3>
|
||||||
<p class="place-type">
|
<p class="place-type">
|
||||||
{{this.type}}
|
{{this.type}}
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ export default class PlacePhotoUpload extends Component {
|
|||||||
this.uploadedPhoto = null;
|
this.uploadedPhoto = null;
|
||||||
|
|
||||||
if (this.args.onClose) {
|
if (this.args.onClose) {
|
||||||
this.args.onClose();
|
this.args.onClose(event.id);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.error = 'Failed to publish: ' + e.message;
|
this.error = 'Failed to publish: ' + e.message;
|
||||||
|
|||||||
@@ -29,6 +29,24 @@ export default class PlacePhotosCarousel extends Component {
|
|||||||
return !this.canScrollRight;
|
return !this.canScrollRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scrollToNewPhoto = modifier((element, [eventId]) => {
|
||||||
|
if (eventId && eventId !== this.lastEventId) {
|
||||||
|
this.lastEventId = eventId;
|
||||||
|
// Allow DOM to update first since the photo was *just* added to the store
|
||||||
|
setTimeout(() => {
|
||||||
|
const targetSlide = element.querySelector(
|
||||||
|
`[data-event-id="${eventId}"]`
|
||||||
|
);
|
||||||
|
if (targetSlide) {
|
||||||
|
element.scrollTo({
|
||||||
|
left: targetSlide.offsetLeft,
|
||||||
|
behavior: 'smooth',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
setupCarousel = modifier((element) => {
|
setupCarousel = modifier((element) => {
|
||||||
this.carouselElement = element;
|
this.carouselElement = element;
|
||||||
|
|
||||||
@@ -84,11 +102,16 @@ export default class PlacePhotosCarousel extends Component {
|
|||||||
<div
|
<div
|
||||||
class="place-photos-carousel-track"
|
class="place-photos-carousel-track"
|
||||||
{{this.setupCarousel}}
|
{{this.setupCarousel}}
|
||||||
|
{{this.scrollToNewPhoto @scrollToEventId}}
|
||||||
{{on "scroll" this.updateScrollState}}
|
{{on "scroll" this.updateScrollState}}
|
||||||
>
|
>
|
||||||
{{#each this.photos as |photo|}}
|
{{#each this.photos as |photo|}}
|
||||||
{{! template-lint-disable no-inline-styles }}
|
{{! template-lint-disable no-inline-styles }}
|
||||||
<div class="carousel-slide" style={{photo.style}}>
|
<div
|
||||||
|
class="carousel-slide"
|
||||||
|
style={{photo.style}}
|
||||||
|
data-event-id={{photo.eventId}}
|
||||||
|
>
|
||||||
{{#if photo.blurhash}}
|
{{#if photo.blurhash}}
|
||||||
<Blurhash
|
<Blurhash
|
||||||
@hash={{photo.blurhash}}
|
@hash={{photo.blurhash}}
|
||||||
|
|||||||
Reference in New Issue
Block a user