|
7 | 7 | import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte'; |
8 | 8 | import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; |
9 | 9 | import { assetSnapshot, assetsSnapshot } from '$lib/managers/timeline-manager/utils.svelte'; |
| 10 | + import { viewTransitionManager } from '$lib/managers/ViewTransitionManager.svelte'; |
10 | 11 | import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte'; |
11 | 12 | import { assetViewingStore } from '$lib/stores/asset-viewing.store'; |
12 | 13 | import { isSelectingAllAssets } from '$lib/stores/assets-store.svelte'; |
|
68 | 69 | let hoveredDayGroup = $state(); |
69 | 70 | const send = shared.send; |
70 | 71 |
|
71 | | - let clickedThumb = $state<string | null>(null); |
| 72 | + let animationTargetAssetId = $state<string | null>(null); |
72 | 73 |
|
73 | 74 | const transitionDuration = $derived.by(() => |
74 | 75 | monthGroup.timelineManager.suspendTransitions && !$isUploading ? 0 : 150, |
|
138 | 139 | }); |
139 | 140 | return getDateLocaleString(date); |
140 | 141 | }; |
141 | | - let animateTarget = $state<string | null>(null); |
142 | | - $inspect(clickedThumb).with((a, b) => console.log('clicked', a, b)); |
143 | | - $inspect(animateTarget).with((a, b) => console.log('clicked', a, b)); |
| 142 | + let transitionTargetAssetId = $state<string | null>(null); |
144 | 143 |
|
145 | | - eventManager.on('BackToTimeline', async ({ assetId }) => { |
146 | | - const asset = await monthGroup.findAssetById({ id: assetId }); |
| 144 | + eventManager.on('TransitionToTimeline', ({ id }) => { |
| 145 | + const asset = monthGroup.findAssetById({ id }); |
147 | 146 | if (!asset) { |
148 | 147 | return; |
149 | 148 | } |
150 | | - console.log('BACK TO TIMLEINE'); |
151 | | -
|
152 | | - debugger; |
153 | | - const navigatingPromise = new Promise((resolve) => { |
154 | | - eventManager.once('TimelineLoaded', (assetId) => { |
155 | | - console.log('timeline loaded', assetId); |
156 | | - animateTarget = assetId; |
157 | | - resolve(); |
158 | | - }); |
159 | | - console.log('hi'); |
160 | | - const transition = document.startViewTransition(async () => { |
161 | | - console.log('start view transition - 2'); |
162 | | - eventManager.emit('StartViewTransition'); |
163 | | - console.log('starting2'); |
164 | | - eventManager.emit('WaitForInit'); |
165 | | - await navigatingPromise; |
166 | | - console.log('AFTER VIEW TRANS - 2!'); |
167 | | - debugger; |
168 | | - }); |
169 | | - transition.updateCallbackDone.then(() => ((animateTarget = null), eventManager.emit('EndViewTransition'))); |
170 | | - }); |
| 149 | +
|
| 150 | + viewTransitionManager.startTransition( |
| 151 | + new Promise<void>((resolve) => { |
| 152 | + console.log('BACK TO TIMLEINE'); |
| 153 | + eventManager.once('TimelineLoaded', ({ id }) => { |
| 154 | + console.log('timeline loaded', id); |
| 155 | + transitionTargetAssetId = id; |
| 156 | + resolve(); |
| 157 | + }); |
| 158 | + }), |
| 159 | + () => { |
| 160 | + console.log('finished loaded', id); |
| 161 | + transitionTargetAssetId = null; |
| 162 | + }, |
| 163 | + ); |
171 | 164 | }); |
172 | 165 | </script> |
173 | 166 |
|
|
228 | 221 | {#each filterIntersecting(dayGroup.viewerAssets) as viewerAsset (viewerAsset.id)} |
229 | 222 | {@const position = viewerAsset.position!} |
230 | 223 | {@const asset = viewerAsset.asset!} |
231 | | - {@const transitionName = clickedThumb === asset.id || animateTarget === asset.id ? 'good' : undefined} |
| 224 | + {@const transitionName = |
| 225 | + animationTargetAssetId === asset.id || transitionTargetAssetId === asset.id ? 'good' : undefined} |
232 | 226 |
|
233 | 227 | <!-- {#if viewerAsset.intersecting} --> |
234 | 228 | <!-- note: don't remove data-asset-id - its used by web e2e tests --> |
235 | 229 | <div |
236 | 230 | data-asset-id={asset.id} |
237 | | - data-transition-thumb={clickedThumb === asset.id || animateTarget === asset.id ? true : undefined} |
| 231 | + data-transition-thumb={animationTargetAssetId === asset.id || transitionTargetAssetId === asset.id |
| 232 | + ? true |
| 233 | + : undefined} |
238 | 234 | style:view-transition-name={transitionName} |
239 | 235 | class="absolute" |
240 | 236 | style:top={position.top + 'px'} |
|
250 | 246 | {groupIndex} |
251 | 247 | onClick={async (asset) => { |
252 | 248 | console.log('adding clickedThumb', asset.id); |
253 | | - clickedThumb = asset.id; |
| 249 | + |
| 250 | + // tag target on the 'old' snaptho |
| 251 | + animationTargetAssetId = asset.id; |
| 252 | + viewTransitionManager.startTransition( |
| 253 | + new Promise<void>((resolve) => eventManager.once('AssetViewerLoaded', () => resolve())), |
| 254 | + ); |
| 255 | + |
254 | 256 | eventManager.once('StartViewTransition', () => { |
255 | 257 | console.log('removing clickedThumb'); |
256 | | - clickedThumb = null; |
| 258 | + // remove target on the 'old' view, |
| 259 | + // asset-viewer will tag new target element for 'new' snapshot |
| 260 | + animationTargetAssetId = null; |
257 | 261 | }); |
258 | 262 |
|
259 | 263 | if (typeof onThumbnailClick === 'function') { |
|
0 commit comments