Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions web/src/lib/components/memory-page/memory-photo-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@

interface Props {
asset: TimelineAsset;
onImageLoad: () => void;
}

const { asset }: Props = $props();
const { asset, onImageLoad }: Props = $props();

let assetFileUrl: string = $state('');
let imageLoaded: boolean = $state(false);
let loader = $state<HTMLImageElement>();

const onload = () => {
const onLoadCallback = () => {
imageLoaded = true;
assetFileUrl = imageLoaderUrl;
onImageLoad();
};

onMount(() => {
if (loader?.complete) {
onload();
onLoadCallback();
}
loader?.addEventListener('load', onload);
loader?.addEventListener('load', onLoadCallback);
return () => {
loader?.removeEventListener('load', onload);
loader?.removeEventListener('load', onLoadCallback);
};
});

Expand Down
26 changes: 21 additions & 5 deletions web/src/lib/components/memory-page/memory-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
let progressBarController: Tween<number> | undefined = $state(undefined);
let videoPlayer: HTMLVideoElement | undefined = $state();
const asHref = (asset: { id: string }) => `?${QueryParameter.ID}=${asset.id}`;

const handleNavigate = async (asset?: { id: string }) => {
if ($isViewing) {
return asset;
Expand All @@ -95,6 +96,7 @@

await goto(asHref(asset));
};

const setProgressDuration = (asset: TimelineAsset) => {
if (asset.isVideo) {
const timeParts = asset.duration!.split(':').map(Number);
Expand All @@ -108,13 +110,15 @@
});
}
};

const handleNextAsset = () => handleNavigate(current?.next?.asset);
const handlePreviousAsset = () => handleNavigate(current?.previous?.asset);
const handleNextMemory = () => handleNavigate(current?.nextMemory?.assets[0]);
const handlePreviousMemory = () => handleNavigate(current?.previousMemory?.assets[0]);
const handleEscape = async () => goto(AppRoute.PHOTOS);
const handleSelectAll = () =>
assetInteraction.selectAssets(current?.memory.assets.map((a) => toTimelineAsset(a)) || []);

const handleAction = async (callingContext: string, action: 'reset' | 'pause' | 'play') => {
// leaving these log statements here as comments. Very useful to figure out what's going on during dev!
// console.log(`handleAction[${callingContext}] called with: ${action}`);
Expand Down Expand Up @@ -154,6 +158,7 @@
}
}
};

const handleProgress = async (progress: number) => {
if (!progressBarController) {
return;
Expand Down Expand Up @@ -184,6 +189,7 @@
memoryStore.hideAssetsFromMemory(ids);
init(page);
};

const handleDeleteMemoryAsset = async () => {
if (!current) {
return;
Expand All @@ -192,6 +198,7 @@
await memoryStore.deleteAssetFromMemory(current.asset.id);
init(page);
};

const handleDeleteMemory = async () => {
if (!current) {
return;
Expand All @@ -201,6 +208,7 @@
notificationController.show({ message: $t('removed_memory'), type: NotificationType.Info });
init(page);
};

const handleSaveMemory = async () => {
if (!current) {
return;
Expand All @@ -214,10 +222,12 @@
});
init(page);
};

const handleGalleryScrollsIntoView = () => {
galleryInView = true;
handlePromiseError(handleAction('galleryInView', 'pause'));
};

const handleGalleryScrollsOutOfView = () => {
galleryInView = false;
// only call play after the first page load. When page first loads the gallery will not be visible
Expand Down Expand Up @@ -246,16 +256,22 @@
playerInitialized = false;
};

const resetAndPlay = () => {
handlePromiseError(handleAction('resetAndPlay', 'reset'));
handlePromiseError(handleAction('resetAndPlay', 'play'));
Comment on lines +260 to +261
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have changed the first parameter here. Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first parameter is only for logging, previously it was initPlayer[AssetViewOpen] since that was the name of the method it was contained in.

};

const initPlayer = () => {
const isVideoAssetButPlayerHasNotLoadedYet = current && current.asset.isVideo && !videoPlayer;
const isVideo = current && current.asset.isVideo;
const isVideoAssetButPlayerHasNotLoadedYet = isVideo && !videoPlayer;
if (playerInitialized || isVideoAssetButPlayerHasNotLoadedYet) {
return;
}
if ($isViewing) {
handlePromiseError(handleAction('initPlayer[AssetViewOpen]', 'pause'));
} else {
handlePromiseError(handleAction('initPlayer[AssetViewClosed]', 'reset'));
handlePromiseError(handleAction('initPlayer[AssetViewClosed]', 'play'));
} else if (isVideo) {
// Image assets will start playing when the image is loaded. Only autostart video assets.
resetAndPlay();
}
playerInitialized = true;
};
Expand Down Expand Up @@ -474,7 +490,7 @@
videoViewerVolume={$videoViewerVolume}
/>
{:else}
<MemoryPhotoViewer asset={current.asset} />
<MemoryPhotoViewer asset={current.asset} onImageLoad={resetAndPlay} />
{/if}
{/key}

Expand Down