From 99519d741b69bfcddb587cc65adfee0068a7a2e6 Mon Sep 17 00:00:00 2001 From: lassejaco Date: Fri, 8 Nov 2024 17:42:41 +0700 Subject: [PATCH] timeline only missing date on phone --- .../domain/app/dc7/sessions/timeline.tsx | 35 ++++++++++++++++--- .../swipe-to-scroll/SwipeToScroll.tsx | 10 ++++-- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/devcon-app/src/components/domain/app/dc7/sessions/timeline.tsx b/devcon-app/src/components/domain/app/dc7/sessions/timeline.tsx index e63f93cd5..205cb7296 100644 --- a/devcon-app/src/components/domain/app/dc7/sessions/timeline.tsx +++ b/devcon-app/src/components/domain/app/dc7/sessions/timeline.tsx @@ -1,4 +1,4 @@ -import React, { useMemo, useRef } from 'react' +import React, { useMemo, useRef, useState } from 'react' import { Session as SessionType } from 'types/Session' import { Event } from 'types/Event' import moment from 'moment' @@ -6,6 +6,8 @@ import SwipeToScroll from 'lib/components/event-schedule/swipe-to-scroll' import { SessionCard, getTrackLogo } from './index' import { useRecoilState } from 'recoil' import { sessionFilterAtom } from 'pages/_app' +import useDimensions from "react-cool-dimensions"; +import { cn } from 'lib/shadcn/lib/utils' const RoomGrid = ({ rooms }: { rooms: string[] }) => { const [sessionFilter] = useRecoilState(sessionFilterAtom) @@ -49,6 +51,16 @@ const DayGrid = ({ day: string }) => { const scrollSyncRef = useRef(null) + const [isNativeScroll, setIsNativeScroll] = useState(false) + // When element changes size, record its max scroll boundary and reset all scroll related state to avoid edge cases + const { observe } = useDimensions({ + onResize: ({ width }) => { + const isNativeScroll = !window.matchMedia('not all and (hover: none)').matches + + setIsNativeScroll(isNativeScroll) + }, + }) + return (
{/*
*/}
{ + // console.log('scroll', e.target.scrollLeft) + // e.preventDefault() + // e.stopPropagation() + // }} + ref={(element) => { + // @ts-ignore + scrollSyncRef.current = element! + observe(element) + }} >
0 ? 'translateX(-50%)' : 'translateX(0)' }} diff --git a/lib/components/event-schedule/swipe-to-scroll/SwipeToScroll.tsx b/lib/components/event-schedule/swipe-to-scroll/SwipeToScroll.tsx index f199c833f..f8ca12cab 100644 --- a/lib/components/event-schedule/swipe-to-scroll/SwipeToScroll.tsx +++ b/lib/components/event-schedule/swipe-to-scroll/SwipeToScroll.tsx @@ -107,7 +107,8 @@ const SwipeToScroll = forwardRef((props: SwipeToScrollProps, ref) => { scrollContainer.style.transform = `translateX(0px)`; if (props.syncElement?.current) { - props.syncElement.current.style.transform = `translateX(0px)`; + // props.syncElement.current.style.transform = `translateX(0px)`; + props.syncElement.current.style.setProperty('--scroll-x', '0px'); } syncScrollIndicators(scrollContainer); @@ -184,7 +185,8 @@ const SwipeToScroll = forwardRef((props: SwipeToScrollProps, ref) => { scrollContainer.style.transform = `translateX(-${clampedScrollLeft}px)`; if (props.syncElement?.current) { - props.syncElement.current.style.transform = `translateX(-${clampedScrollLeft}px)`; + // props.syncElement.current.style.transform = `translateX(-${clampedScrollLeft}px)`; + props.syncElement.current.style.setProperty('--scroll-x', `-${clampedScrollLeft}px`); } } @@ -212,7 +214,8 @@ const SwipeToScroll = forwardRef((props: SwipeToScrollProps, ref) => { scrollContainer.style.transform = `translateX(-${lastX.current}px)`; if (props.syncElement?.current) { - props.syncElement.current.style.transform = `translateX(-${lastX.current}px)`; + // props.syncElement.current.style.transform = `translateX(-${lastX.current}px)`; + props.syncElement.current.style.setProperty('--scroll-x', `-${lastX.current}px`); } if (down) { @@ -248,6 +251,7 @@ const SwipeToScroll = forwardRef((props: SwipeToScrollProps, ref) => { if (props.syncElement?.current) { // @ts-ignore props.syncElement.current.scrollLeft = e.target.scrollLeft; + // props.syncElement.current.style.setProperty('--scroll-x', `-${e.target.scrollLeft}px`); } }} // This prevents selection (text, image) while dragging