diff --git a/web/src/lib/components/photos-page/asset-grid.svelte b/web/src/lib/components/photos-page/asset-grid.svelte index fb776d5895..562b5900a4 100644 --- a/web/src/lib/components/photos-page/asset-grid.svelte +++ b/web/src/lib/components/photos-page/asset-grid.svelte @@ -8,10 +8,7 @@ import AssetViewer from '../asset-viewer/asset-viewer.svelte'; import IntersectionObserver from '../asset-viewer/intersection-observer.svelte'; import Portal from '../shared-components/portal/portal.svelte'; - import Scrollbar, { - OnScrollbarClickDetail, - OnScrollbarDragDetail, - } from '../shared-components/scrollbar/scrollbar.svelte'; + import Scrollbar from '../shared-components/scrollbar/scrollbar.svelte'; import AssetDateGroup from './asset-date-group.svelte'; import MemoryLane from './memory-lane.svelte'; @@ -30,13 +27,13 @@ export let assetInteractionStore: AssetInteractionStore; const { assetSelectionCandidates, assetSelectionStart, selectedAssets, isMultiSelectState } = assetInteractionStore; - - let { isViewing: showAssetViewer, asset: viewingAsset } = assetViewingStore; - const viewport: Viewport = { width: 0, height: 0 }; - let assetGridElement: HTMLElement; + let { isViewing: showAssetViewer, asset: viewingAsset } = assetViewingStore; + let element: HTMLElement; let showShortcuts = false; + $: timelineY = element?.scrollTop || 0; + const onKeyboardPress = (event: KeyboardEvent) => handleKeyboardPress(event); onMount(async () => { @@ -84,7 +81,7 @@ } function handleScrollTimeline(event: CustomEvent) { - assetGridElement.scrollBy(0, event.detail.heightDelta); + element.scrollBy(0, event.detail.heightDelta); } const navigateToPreviousAsset = async () => { @@ -101,26 +98,18 @@ } }; - let lastScrollPosition = 0; let animationTick = false; const handleTimelineScroll = () => { - if (!animationTick) { - window.requestAnimationFrame(() => { - lastScrollPosition = assetGridElement?.scrollTop; - animationTick = false; - }); - - animationTick = true; + if (animationTick) { + return; } - }; - const handleScrollbarClick = (e: OnScrollbarClickDetail) => { - assetGridElement.scrollTop = e.scrollTo; - }; - - const handleScrollbarDrag = (e: OnScrollbarDragDetail) => { - assetGridElement.scrollTop = e.scrollTo; + animationTick = true; + window.requestAnimationFrame(() => { + timelineY = element?.scrollTop || 0; + animationTick = false; + }); }; const handleArchiveSuccess = (e: CustomEvent) => { @@ -278,26 +267,23 @@ (showShortcuts = !showShortcuts)} /> {/if} -{#if $assetStore.timelineHeight > viewport.height} - handleScrollbarClick(e.detail)} - on:onscrollbardrag={(e) => handleScrollbarDrag(e.detail)} - /> -{/if} + (element.scrollTop = detail)} +/>
- {#if assetGridElement} + {#if element} {#if showMemoryLane} {/if} @@ -309,7 +295,7 @@ let:intersecting top={750} bottom={750} - root={assetGridElement} + root={element} >
{#if intersecting} diff --git a/web/src/lib/components/shared-components/scrollbar/scrollbar.svelte b/web/src/lib/components/shared-components/scrollbar/scrollbar.svelte index 0908a049a8..5882f7903c 100644 --- a/web/src/lib/components/shared-components/scrollbar/scrollbar.svelte +++ b/web/src/lib/components/shared-components/scrollbar/scrollbar.svelte @@ -1,158 +1,128 @@ - - + + -
(isHover = true)} - on:mouseleave={() => { - isHover = false; - isDragging = false; - }} - on:mouseup={handleMouseUp} - on:mousemove={handleMouseDrag} - on:mousedown={handleMouseDown} - style:height={scrollbarHeight + 'px'} -> - {#if isHover} -
- {hoveredDate?.toLocaleString('default', { month: 'short' })} - {hoveredDate?.getFullYear()} -
- {/if} - - {#if !isDragging} -
- {/if} - - {#each segmentScrollbarLayout as segment, index (segment.timeGroup)} - {@const groupDate = new Date(segment.timeGroup)} +{#if $assetStore.timelineHeight > height} +
(isHover = true)} + on:mouseleave={() => { + isHover = false; + isDragging = false; + }} + on:mouseenter={({ clientY, buttons }) => handleMouseEvent({ clientY, isDragging: !!buttons })} + on:mousemove={({ clientY }) => handleMouseEvent({ clientY })} + on:mousedown={({ clientY }) => handleMouseEvent({ clientY, isDragging: true })} + on:mouseup={({ clientY }) => handleMouseEvent({ clientY, isDragging: false })} + > + {#if isHover} +
+ {hoverLabel} +
+ {/if} -
handleMouseMove(e, groupDate)} - > - {#if new Date(segmentScrollbarLayout[index - 1]?.timeGroup).getFullYear() !== groupDate.getFullYear()} - {#if segment.height > 8} + + {#if !isDragging} +
+ {/if} + + {#each segments as segment, index (segment.timeGroup)} + {@const date = new Date(segment.timeGroup)} + {@const year = date.getFullYear()} + {@const label = `${date.toLocaleString('default', { month: 'short' })} ${year}`} + + +
(hoverLabel = label)} + > + {#if new Date(segments[index - 1]?.timeGroup).getFullYear() !== year} + {#if segment.height > 8} +
+ {year} +
+ {/if} + {:else if segment.height > 5}
- {groupDate.getFullYear()} -
+ class="absolute right-0 mr-3 block h-[4px] w-[4px] rounded-full bg-gray-300" + /> {/if} - {:else if segment.height > 5} -
- {/if} -
- {/each} -
+
+ {/each} +
+{/if}