mirror of
https://github.com/pmret/website.git
synced 2024-11-09 12:32:48 +01:00
Smoothed out tab transition and removed unused vars (#7)
This commit is contained in:
parent
59c129a713
commit
be18b9479a
@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect, useMemo } from "react"
|
import React, { useState, useEffect, useMemo } from "react"
|
||||||
import { createPortal } from "react-dom"
|
import { createPortal } from "react-dom"
|
||||||
import { Area, XAxis, YAxis, AreaChart, CartesianGrid, Tooltip, ResponsiveContainer, Text } from "recharts"
|
import { Area, XAxis, YAxis, AreaChart, CartesianGrid, Tooltip, ResponsiveContainer } from "recharts"
|
||||||
|
|
||||||
const csvVersions = {
|
const csvVersions = {
|
||||||
"1": {
|
"1": {
|
||||||
@ -47,7 +47,7 @@ async function fetchData(version) {
|
|||||||
return rows
|
return rows
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ProgressPane({ captionPortal, nonce, color, version }) {
|
export default function ProgressPane({ captionPortal, color, version }) {
|
||||||
const [data, setData] = useState()
|
const [data, setData] = useState()
|
||||||
const [dataVersion, setDataVersion] = useState()
|
const [dataVersion, setDataVersion] = useState()
|
||||||
|
|
||||||
@ -62,11 +62,11 @@ export default function ProgressPane({ captionPortal, nonce, color, version }) {
|
|||||||
const isDataValid = dataVersion === version
|
const isDataValid = dataVersion === version
|
||||||
|
|
||||||
return <div style={{ display: "flex", flexDirection: "column", width: "100%" }}>
|
return <div style={{ display: "flex", flexDirection: "column", width: "100%" }}>
|
||||||
{<DataView data={isDataValid ? data : []} nonce={nonce} captionPortal={captionPortal} color={color}/>}
|
{data && <DataView data={isDataValid ? data : []} captionPortal={captionPortal} color={color}/>}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
function DataView({ data, captionPortal, nonce, color }) {
|
function DataView({ data, captionPortal, color }) {
|
||||||
const latest = data[data.length - 1]
|
const latest = data[data.length - 1]
|
||||||
const oldest = data[0]
|
const oldest = data[0]
|
||||||
const { stroke, fill } = colors[color]
|
const { stroke, fill } = colors[color]
|
||||||
@ -148,7 +148,7 @@ function DataView({ data, captionPortal, nonce, color }) {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{data.length && selectedEntry && captionPortal.current && createPortal(<EntryInfo entry={selectedEntry} isLatest={selectedEntry.commit === latest.commit}/>, captionPortal.current)}
|
{(data.length && selectedEntry && captionPortal.current && createPortal(<EntryInfo entry={selectedEntry} isLatest={selectedEntry.commit === latest.commit}/>, captionPortal.current) || null)}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
src/main.jsx
16
src/main.jsx
@ -116,21 +116,20 @@ function App() {
|
|||||||
const [flip, setFlip] = useState(false)
|
const [flip, setFlip] = useState(false)
|
||||||
const pane = useRef()
|
const pane = useRef()
|
||||||
|
|
||||||
function switchToTab(index, pushState) {
|
function switchToTab(index, pushState, prevTabIndex) {
|
||||||
if (index === paneIndex || index === tabIndex) return
|
if (index === paneIndex || index === tabIndex) return
|
||||||
|
|
||||||
console.info("switching to tab", index)
|
|
||||||
|
|
||||||
setRotation(rotation - 180)
|
setRotation(rotation - 180)
|
||||||
setTabIndex(index)
|
|
||||||
|
console.info("switching to tab", index, "from ", prevTabIndex)
|
||||||
|
|
||||||
if (pushState)
|
if (pushState)
|
||||||
history.pushState(null, tabs[index].name, tabs[index].slug)
|
history.pushState(null, tabs[index].name, tabs[index].slug)
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
setTabIndex(index)
|
||||||
setPaneIndex(index)
|
setPaneIndex(index)
|
||||||
setFlip(!flip)
|
setFlip(!flip)
|
||||||
}, 300) // half the animation time
|
}, prevTabIndex === 0 ? 175 : 300) // half the animation time
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -155,7 +154,7 @@ function App() {
|
|||||||
onClick={evt => {
|
onClick={evt => {
|
||||||
const q = window.matchMedia("(prefers-reduced-motion: reduce)")
|
const q = window.matchMedia("(prefers-reduced-motion: reduce)")
|
||||||
if (!q.matches) {
|
if (!q.matches) {
|
||||||
switchToTab(index, true)
|
switchToTab(index, true, tabIndex)
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@ -172,13 +171,14 @@ function App() {
|
|||||||
</nav>
|
</nav>
|
||||||
<main id="main" ref={pane} className={clsx(tabs[paneIndex].color)} style={{
|
<main id="main" ref={pane} className={clsx(tabs[paneIndex].color)} style={{
|
||||||
transform: `perspective(4000px) rotateX(${rotation}deg)`,
|
transform: `perspective(4000px) rotateX(${rotation}deg)`,
|
||||||
|
overflow: 'hidden'
|
||||||
}}>
|
}}>
|
||||||
<div style={{
|
<div style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flex: 1,
|
flex: 1,
|
||||||
transform: `rotateX(${flip ? '180deg' : '0deg'})`,
|
transform: `rotateX(${flip ? '180deg' : '0deg'})`,
|
||||||
}}>
|
}}>
|
||||||
{tabs[paneIndex].pane({ captionPortal, nonce: rotation })}
|
{tabs[paneIndex].pane({ captionPortal })}
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
{tabIndex !== 0 && <div className="caption outline-invert" ref={captionPortal}></div>}
|
{tabIndex !== 0 && <div className="caption outline-invert" ref={captionPortal}></div>}
|
||||||
|
Loading…
Reference in New Issue
Block a user