From ac785b94af5607c9c28b4f9f08d800fe5609a0fe Mon Sep 17 00:00:00 2001 From: Timothy White Date: Mon, 31 Mar 2025 22:51:26 +0100 Subject: [PATCH 1/2] comeponent-a-rise --- src/App.vue | 100 ++++++++++--------------------- src/components/AppHeader.vue | 22 +++++++ src/components/SpeedControls.vue | 80 +++++++++++++++++++++++++ src/hooks/useSessionStorage.ts | 0 4 files changed, 134 insertions(+), 68 deletions(-) create mode 100644 src/components/AppHeader.vue create mode 100644 src/components/SpeedControls.vue delete mode 100644 src/hooks/useSessionStorage.ts 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, () => { @@ -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..1338c21 --- /dev/null +++ b/src/components/AppHeader.vue @@ -0,0 +1,22 @@ + + + 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 @@ + + + + + diff --git a/src/hooks/useSessionStorage.ts b/src/hooks/useSessionStorage.ts deleted file mode 100644 index e69de29..0000000 From 95d7351ab964786e619805d37d517164ed64accc Mon Sep 17 00:00:00 2001 From: Timothy White Date: Mon, 31 Mar 2025 22:54:47 +0100 Subject: [PATCH 2/2] fix logo path --- src/components/AppHeader.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AppHeader.vue b/src/components/AppHeader.vue index 1338c21..7cdfe8b 100644 --- a/src/components/AppHeader.vue +++ b/src/components/AppHeader.vue @@ -10,7 +10,7 @@ import GithubIcon from './icons/GithubIcon.vue'