diff --git a/src/App.vue b/src/App.vue index a20712c..5dd0a28 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,8 +5,9 @@ import PlayButton from '@/components/icons/PlayButton.vue' import PauseButton from '@/components/icons/PauseButton.vue' import RangeSlider from '@/components/RangeSlider.vue' import ChartControlButton from '@/components/ChartControlButton.vue' -import GithubIcon from '@/components/icons/GithubIcon.vue' import { useTimer } from '@/hooks/useTimer' +import AppHeader from './components/AppHeader.vue' +import SpeedControls from './components/SpeedControls.vue' const sliderValue = ref(30) const algorithmSelection = ref('bubble') @@ -101,25 +102,6 @@ const resetChart = async () => { } } -// Added function to update playback speed -const updatePlaybackSpeed = (speed) => { - playbackSpeed.value = speed - - // If currently playing, restart the interval with new speed - if (isPlaying.value && intervalId) { - clearInterval(intervalId) - playAlgorithm() - } -} - -// Added speed presets -const speedPresets = [ - { label: 'Slow', value: 250 }, - { label: 'Medium', value: 100 }, - { label: 'Fast', value: 25 }, - { label: 'Very Fast', value: 5 }, -] - onMounted(() => { const sortingAlgo = algorithmSelection.value const button = document.getElementById(`${sortingAlgo}-button`) @@ -143,6 +125,29 @@ watch([frame, totalFrames], () => { } }) +const handlePlaybackSpeedUpdate = (newSpeed) => { + playbackSpeed.value = newSpeed + + // If currently playing, restart the interval with new speed + if (isPlaying.value && intervalId) { + clearInterval(intervalId) + intervalId = null + + // Restart the interval with the new speed + let i = frame.value + intervalId = setInterval(() => { + frame.value = i + i++ + if (i > totalFrames.value) { + clearInterval(intervalId) + intervalId = null + isPlaying.value = false + timer.pause() + } + }, playbackSpeed.value) + } +} + watch(sliderValue, () => { // Reset the elapsed frames and timer when the slider value changes frame.value = 0 @@ -155,19 +160,7 @@ watch(algorithmSelection, () => { - - - Timothy White - Vue JS Algorithm Sorting Project - - - - + @@ -267,21 +260,12 @@ watch(algorithmSelection, () => { :step="1" :disabled="isPlaying" /> - - Speed per frame: {{ playbackSpeed }}ms - - - {{ preset.label }} - - - + + @@ -382,24 +366,4 @@ header { gap: 10px; width: 100%; } - -.speed-buttons { - display: flex; - gap: 10px; -} - -.speed-button { - width: 100%; - background-color: rgb(19, 90, 74); - color: white; - padding: 7px; - border: none; - border-radius: 5px; - cursor: pointer; -} - -.speed-button.active { - background-color: rgb(91, 236, 255); - color: black; -} diff --git a/src/components/AppHeader.vue b/src/components/AppHeader.vue new file mode 100644 index 0000000..7cdfe8b --- /dev/null +++ b/src/components/AppHeader.vue @@ -0,0 +1,22 @@ + + + + + + Timothy White - Vue JS Algorithm Sorting Project + + + + + diff --git a/src/components/SpeedControls.vue b/src/components/SpeedControls.vue new file mode 100644 index 0000000..fbad19a --- /dev/null +++ b/src/components/SpeedControls.vue @@ -0,0 +1,80 @@ + + + + + Speed per frame: {{ playbackSpeed }}ms + + + {{ preset.label }} + + + + + + diff --git a/src/hooks/useSessionStorage.ts b/src/hooks/useSessionStorage.ts deleted file mode 100644 index e69de29..0000000
Timothy White - Vue JS Algorithm Sorting Project
Speed per frame: {{ playbackSpeed }}ms