Skip to content

Commit

Permalink
add notice to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Specy committed Jul 6, 2024
1 parent c3ac0ea commit f463f7f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/components/pages/Player/PlayerKeyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ export default class KeyboardPlayer extends Component<KeyboardPlayerProps, Keybo
notes.push(obj)
}
await delay(2000) //add an initial delay to let the user prepare
playerControlsStore.setSong(song)
//not sure why i even save the song, i dont use it anywhere
//playerControlsStore.setSong(song)
playerControlsStore.clearPages()
playerControlsStore.resetScore()
this.setState({
Expand Down
13 changes: 11 additions & 2 deletions src/components/pages/Player/PlayerSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import sl from "./Slider.module.css"
import {setTimeout} from "worker-timers";


export function _PlayerSlider() {
interface PlayerSliderProps{
onChange?: (start: number, end: number) => void
}

export function _PlayerSlider({onChange}: PlayerSliderProps) {
const sliderState = useObservableObject(playerControlsStore.state)
const [selectedThumb, setSelectedThumb] = useState<'start' | 'end' | null>(null)
const [inputDimension, setInputDimension] = useState(DEFAULT_DOM_RECT)
Expand Down Expand Up @@ -39,6 +43,7 @@ export function _PlayerSlider() {
} else {
playerControlsStore.setState({end: Math.min(sliderState.size, Math.max(val, sliderState.position))})
}
onChange?.(playerControlsStore.current, playerControlsStore.end)
}

const handleSliderClick = (event: React.PointerEvent<HTMLDivElement>) => {
Expand Down Expand Up @@ -84,6 +89,8 @@ export function _PlayerSlider() {
} else {
if (value - sliderState.position > 1) playerControlsStore.setState({end: value})
}
onChange?.(playerControlsStore.current, playerControlsStore.end)

}
const start = sliderState.size !== 0 ? sliderState.position / sliderState.size * 100 : 0
const end = sliderState.size !== 0 ? sliderState.end / sliderState.size * 100 : 100
Expand Down Expand Up @@ -139,4 +146,6 @@ export function _PlayerSlider() {
</>
}

export const PlayerSlider = memo(_PlayerSlider, () => true)
export const PlayerSlider = memo(_PlayerSlider, (p,v) => {
return p.onChange === v.onChange
})
17 changes: 14 additions & 3 deletions src/components/pages/Player/PlayerSongControls.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {SPEED_CHANGERS} from "$config"
import {MemoizedIcon} from "$cmp/shared/Utility/Memoized";
import {FaEye, FaEyeSlash, FaStop} from "react-icons/fa";
import {ChangeEvent, memo} from "react";
import {ChangeEvent, memo, useCallback, useEffect, useState} from "react";
import {playerStore} from "$stores/PlayerStore";
import {playerControlsStore} from "$stores/PlayerControlsStore";
import {hasTooltip, Tooltip} from '$cmp/shared/Utility/Tooltip'
Expand Down Expand Up @@ -50,8 +50,17 @@ function _PlayerSongControls({
hidePracticeNotes,
setHidePracticeNotes,
}: PlayerSongControlsProps) {
const [needsRefresh, setNeedsRefresh] = useState(false)
const songData = useObservableObject(playerStore.state)
const {t} = useTranslation(["player", 'common', "settings", "shortcuts"])

const toggleNeedsRefresh = useCallback(() => {
setNeedsRefresh(true)
}, [])

useEffect(() => {
setNeedsRefresh(false)
}, [songData.key]);
return <>
{songData.eventType === 'approaching' &&
<Score/>
Expand Down Expand Up @@ -126,9 +135,11 @@ function _PlayerSongControls({
</IconButton>
</div>

<PlayerSlider/>

<PlayerSlider
onChange={toggleNeedsRefresh}
/>
<IconButton
toggled={needsRefresh}
onClick={onRestart}
tooltip={t('shortcuts:props.restart')}
ariaLabel={t("shortcuts:props.restart_description")}
Expand Down
7 changes: 7 additions & 0 deletions src/stores/PlayerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type eventType = "play" | "practice" | "approaching" | "stop"
type SongTypes = RecordedSong | ComposedSong | null
type SongTypesNonNull = RecordedSong | ComposedSong
type PlayerStoreState = {
key: number
song: SongTypes,
playId: number,
eventType: eventType,
Expand All @@ -18,6 +19,7 @@ type PlayerStoreState = {
class PlayerStore {
@observable
state: PlayerStoreState = {
key: 0,
song: null,
playId: 0,
eventType: 'stop',
Expand Down Expand Up @@ -72,6 +74,7 @@ class PlayerStore {
start,
eventType: 'play',
end,
key: this.state.key + 1,
playId: this.state.playId + 1
})
}
Expand All @@ -81,6 +84,7 @@ class PlayerStore {
start,
eventType: 'practice',
end,
key: this.state.key + 1,
playId: this.state.playId + 1
})
}
Expand All @@ -90,6 +94,7 @@ class PlayerStore {
start,
eventType: 'approaching',
end,
key: this.state.key + 1,
playId: this.state.playId + 1
})
}
Expand All @@ -99,13 +104,15 @@ class PlayerStore {
eventType: 'stop',
start: 0,
end: 0,
key: this.state.key + 1,
playId: 0
})
}
restartSong = (start: number, end: number) => {
this.setState({
start,
end,
key: this.state.key + 1,
playId: this.state.playId + 1
})
}
Expand Down

0 comments on commit f463f7f

Please sign in to comment.