diff --git a/src/App.tsx b/src/App.tsx index 4bd4a7a..3a1653a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,7 +5,7 @@ import { wikipedia_link_of_page, wikipedia_link_of_year } from './utils' function App() { const [list, setList] = useState<{ from: number, to: number, person: { desc: string, link: string | undefined, death: number | undefined }, other_people: { desc: string, link: string | undefined, death: number | undefined }[] }[]>([]) - // const [currentIndex, setCurrentIndex] = useState(0) + const [currentIndex, setCurrentIndex] = useState(0) const [currentTimelineHighlight, setCurrentTimelineHighlight] = useState(0) // prepare (mock) data @@ -19,25 +19,31 @@ function App() { fetchData() }, []) - const handleScrollDebug: React.UIEventHandler = (e) => { + const handleScroll: React.UIEventHandler = (e) => { const { scrollTop, scrollHeight, clientHeight } = e.target as HTMLDivElement const position = Math.ceil( (scrollTop / (scrollHeight - clientHeight)) * 1000, ) setCurrentTimelineHighlight(position) + + if (position > list[currentIndex].to && currentIndex < list.length - 1) + setCurrentIndex(currentIndex + 1) + else if (position < list[currentIndex].from && currentIndex > 0) + setCurrentIndex(currentIndex - 1) } return (
-
- vertical timeline +
+ Timeline {Array.from({ length: 1000 }).map((_, index) => ( - + ))} @@ -46,7 +52,7 @@ function App() {
- {/*

{list[currentIndex].person.desc}

*/} +

{ list.length === 0 ? 'loading...' : list[currentIndex].person.desc}

description

diff --git a/src/index.css b/src/index.css index 4f7a0e3..08d0067 100644 --- a/src/index.css +++ b/src/index.css @@ -7,19 +7,24 @@ body { height: 100vh; } -.progress-bar { +.timeline { flex: 1; background-color: #f0f0f0; + display: flex; + flex-direction: column; + align-items: center; + overflow-y: scroll; scrollbar-width: none; } -.content { - flex: 3; - display: flex; +td { + text-align: center; +} - overflow: hidden; +.highlight { + color: #ff0000; } .text-detail { @@ -31,7 +36,7 @@ body { } .photo { - flex: 1; + flex: 2; display: flex; align-items: center; justify-content: center; @@ -44,4 +49,4 @@ body { max-width: 100%; max-height: 100%; object-fit: contain; -} +} \ No newline at end of file
- Row - {index === currentTimelineHighlight ? 99999 : index} + Year + {' '} + {index }