From 7b86fe2a41d7f1de9d3c67a46ef61495757bc7c0 Mon Sep 17 00:00:00 2001 From: Sebastian Fudalej Date: Tue, 7 Sep 2021 12:47:36 +0200 Subject: [PATCH 1/4] build: add run and debug scriptsm, add tab config --- .vscode/launch.json | 21 +++++++++++++++++++++ .vscode/settings.json | 4 ++++ 2 files changed, 25 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6b99cea --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "command": "npm start", + "name": "Run npm start", + "request": "launch", + "type": "node-terminal" + }, + { + "type": "pwa-msedge", + "request": "launch", + "name": "Launch Edge against localhost:3000", + "url": "http://localhost:3000", + "webRoot": "${workspaceFolder}" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..976f404 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.insertSpaces": false, + "editor.tabSize": 2 +} -- 2.54.0 From d33c05f1334a3b25552f3edf3ea1d0fef96e5671 Mon Sep 17 00:00:00 2001 From: Sebastian Fudalej Date: Tue, 7 Sep 2021 12:49:53 +0200 Subject: [PATCH 2/4] build: add run and debug scripts, add tab config --- .vscode/launch.json | 21 +++++++++++++++++++++ .vscode/settings.json | 4 ++++ 2 files changed, 25 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6b99cea --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "command": "npm start", + "name": "Run npm start", + "request": "launch", + "type": "node-terminal" + }, + { + "type": "pwa-msedge", + "request": "launch", + "name": "Launch Edge against localhost:3000", + "url": "http://localhost:3000", + "webRoot": "${workspaceFolder}" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..976f404 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.insertSpaces": false, + "editor.tabSize": 2 +} -- 2.54.0 From 81066d6470f5f54d2b4a61d4102422687924abff Mon Sep 17 00:00:00 2001 From: Sebastian Fudalej Date: Tue, 7 Sep 2021 13:37:00 +0200 Subject: [PATCH 3/4] refactor: change let to const, code quality --- src/components/History/History.js | 8 +++---- src/components/Info/Info.js | 4 ++-- src/components/Main/Main.js | 2 +- src/components/Nav/Nav.js | 35 +++++++++++++++---------------- src/components/Search/Search.js | 8 +++---- src/components/Status/Status.js | 19 ++++++++++------- src/components/Track/Track.js | 26 +++++++++-------------- 7 files changed, 49 insertions(+), 53 deletions(-) diff --git a/src/components/History/History.js b/src/components/History/History.js index 3332e92..010b77a 100644 --- a/src/components/History/History.js +++ b/src/components/History/History.js @@ -6,17 +6,17 @@ import PlayingContext from '../../contexts/Playing' import './History.css' -function History(props) { - let playing = useContext(PlayingContext) +function History({ next, tracks }) { + const playing = useContext(PlayingContext) return (
Następny: - + Gra teraz: Poprzednie: - {props.tracks.map((track) => { + {tracks.map((track) => { return })}
diff --git a/src/components/Info/Info.js b/src/components/Info/Info.js index b636a1b..6620333 100644 --- a/src/components/Info/Info.js +++ b/src/components/Info/Info.js @@ -5,10 +5,10 @@ import { get } from '../../Cache' import './Info.css' function Info() { - let { id } = useParams(), + const { id } = useParams(), track = get(id) - let percent = (track.votes.up / (track.votes.up + track.votes.down)) * 100 + const percent = (track.votes.up / (track.votes.up + track.votes.down)) * 100 document.title = `${track.title} | radio-rolnik` diff --git a/src/components/Main/Main.js b/src/components/Main/Main.js index b623d2b..6cea793 100644 --- a/src/components/Main/Main.js +++ b/src/components/Main/Main.js @@ -24,7 +24,7 @@ document.setTitle = (prefix, suffix) => { } function Main() { - let [playing] = useState({ + const [playing] = useState({ ...get('2340q8ghedsnawg1'), }) diff --git a/src/components/Nav/Nav.js b/src/components/Nav/Nav.js index 1d06e01..a69bba0 100644 --- a/src/components/Nav/Nav.js +++ b/src/components/Nav/Nav.js @@ -2,25 +2,24 @@ import { useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { useLocation } from 'react-router-dom' - import './Nav.css' -function Button(props) { +function Button({ to, onClick, active, icon, label }) { return ( - - {props.label} + + {label} ) } -function Nav(props) { +function Nav({ buttons }) { function getTab() { - return props.buttons + return buttons .slice() .reverse() .find((button) => @@ -28,12 +27,12 @@ function Nav(props) { ).label } - let [current, setCurrent] = useState(getTab()), + const [current, setCurrent] = useState(getTab()), location = useLocation() useEffect(() => { setCurrent(getTab()) - let label = (function () { + const label = (function () { switch (current) { default: case 'History': @@ -52,14 +51,14 @@ function Nav(props) { return ( diff --git a/src/components/Search/Search.js b/src/components/Search/Search.js index 38cb02c..35d59b3 100644 --- a/src/components/Search/Search.js +++ b/src/components/Search/Search.js @@ -7,9 +7,9 @@ import { search } from '../../Cache' import './Search.css' function Search(props) { - let { query } = useParams(), - [results, setResults] = useState([]), - timeout + const { query } = useParams(), + [results, setResults] = useState([]) + let timeout document.setTitle(`"${query}"`) @@ -17,7 +17,7 @@ function Search(props) { return () => { clearTimeout(timeout) } - }, []) + }, []) // eslint-disable-line react-hooks/exhaustive-deps return (
diff --git a/src/components/Status/Status.js b/src/components/Status/Status.js index ac4492d..f9d92bc 100644 --- a/src/components/Status/Status.js +++ b/src/components/Status/Status.js @@ -6,23 +6,26 @@ import PlayingContext from '../../contexts/Playing' import './Status.css' function Status(props) { - let playing = useContext(PlayingContext), + const { id, album, title, duration, artists } = useContext(PlayingContext), [progress, setProgress] = useState(0) - let step = 1 / playing.duration + const step = 1 / duration useEffect(() => { let anim = setInterval(() => { - setProgress((progress += step)) + setProgress((progress) => progress + step) if (progress >= 1) clearInterval(anim) }, 1e3) - }, []) + return () => { + clearInterval(anim) + } + }, []) // eslint-disable-line react-hooks/exhaustive-deps return ( - - album cover - {playing.title} - {playing.artists.join(', ')} + + album cover + {title} + {artists.join(', ')}
-
- {props.timestamp && ( - {props.timestamp} - )} - {props.rank && {props.rank}} +
+ {timestamp && {timestamp}} + {rank && {rank}} album cover
- - {props.title} + + {title} - {props.artists.join(', ')} + {artists.join(', ')}
@@ -45,7 +39,7 @@ function Track(props) {
- +
Date: Tue, 7 Sep 2021 14:33:30 +0200 Subject: [PATCH 4/4] fix: progress bar going indefinitely --- src/components/Status/Status.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/components/Status/Status.js b/src/components/Status/Status.js index f9d92bc..e52cb7b 100644 --- a/src/components/Status/Status.js +++ b/src/components/Status/Status.js @@ -11,15 +11,21 @@ function Status(props) { const step = 1 / duration - useEffect(() => { - let anim = setInterval(() => { - setProgress((progress) => progress + step) - if (progress >= 1) clearInterval(anim) - }, 1e3) - return () => { - clearInterval(anim) - } - }, []) // eslint-disable-line react-hooks/exhaustive-deps + useEffect( + (anim) => { + if (progress < 1) { + anim = setTimeout(() => { + setProgress(progress + step) + }, 1e3) + } else if (progress > 1) { + setProgress(1) // if FPU decides that 1 / duration * duration !== 1 + } + return () => { + clearInterval(anim) + } + }, + [progress, step] + ) return ( -- 2.54.0