diff --git a/src/renderer/MainContent.tsx b/src/renderer/MainContent.tsx index 6a5b0fa34..2b01276c1 100644 --- a/src/renderer/MainContent.tsx +++ b/src/renderer/MainContent.tsx @@ -1,33 +1,28 @@ -import { - createRef, - Fragment, - RefObject, - useEffect, - useRef, - useState, -} from 'react'; +import { Fragment, useMemo } from 'react'; import { MAX_NUM_FILTERS, MIN_NUM_FILTERS } from 'common/constants'; import FrequencyBand from './components/FrequencyBand'; import { useAquaContext } from './utils/AquaContext'; import './styles/MainContent.scss'; import AddSliderDivider from './components/AddSliderDivider'; -import SortWrapper from './SortWrapper'; import Spinner from './icons/Spinner'; const MainContent = () => { - const { filters, isLoading } = useAquaContext(); - const wrapperRef = createRef(); - const sliderRefs = useRef>([]); - const dividerRefs = useRef>([]); + const { filters: sortedFilters, isLoading } = useAquaContext(); + const DIVIDER_WIDTH = 28; + const BAND_WIDTH = 72.94; - useEffect(() => { - sliderRefs.current = sliderRefs.current.slice(0, filters.length); - dividerRefs.current = dividerRefs.current.slice(0, filters.length + 1); - }, [filters]); + const [filters, sortIndexMap] = useMemo(() => { + const fixedSort = sortedFilters + .slice() + .sort((a, b) => a.id.localeCompare(b.id)); - useEffect(() => { - sliderRefs.current?.forEach((r) => {}); - }, [filters]); + const map: { [key: string]: number } = {}; + sortedFilters.forEach((f, index) => { + map[f.id] = index; + }); + + return [fixedSort, map]; + }, [sortedFilters]); return isLoading ? (
@@ -46,35 +41,37 @@ const MainContent = () => { Gain (dB) Quality
-
+
= MAX_NUM_FILTERS} /> - {filters.map((filter, sliderIndex) => ( - - - = MAX_NUM_FILTERS} - style={{ - position: 'fixed', - transform: `translateX(${(sliderIndex + 1) * (28 + 72.47)}px)`, - 'transition-duration': '500ms', - }} - /> - - ))} + {filters.map((filter) => { + const sliderIndex = sortIndexMap[filter.id]; + return ( + + + = MAX_NUM_FILTERS} + style={{ + transform: `translateX(${ + (sliderIndex + 1) * (DIVIDER_WIDTH + BAND_WIDTH) + }px)`, + }} + /> + + ); + })}
); diff --git a/src/renderer/styles/AddSliderDivider.scss b/src/renderer/styles/AddSliderDivider.scss index 7af5f8263..65fd633a2 100644 --- a/src/renderer/styles/AddSliderDivider.scss +++ b/src/renderer/styles/AddSliderDivider.scss @@ -1,4 +1,5 @@ @import 'color'; +@import 'constant'; @import 'spacing'; .addFilter { @@ -6,6 +7,10 @@ gap: $spacing-m; padding: 0 $spacing-s; + // For sorting frequency bands + position: absolute; + transition-duration: $sort-animate-duration; + .divider { width: $spacing-xxs; height: calc(250px / 2 - 12px - $spacing-m); diff --git a/src/renderer/styles/FrequencyBand.scss b/src/renderer/styles/FrequencyBand.scss index b9092fc5c..2fdd9e8ea 100644 --- a/src/renderer/styles/FrequencyBand.scss +++ b/src/renderer/styles/FrequencyBand.scss @@ -3,6 +3,10 @@ @import 'spacing'; .bandWrapper { + // For sorting frequency bands + position: absolute; + transition-duration: $sort-animate-duration; + &:hover { .removeFilter { opacity: 1; diff --git a/src/renderer/styles/MainContent.scss b/src/renderer/styles/MainContent.scss index 1ddf2d9a0..ced924ffc 100644 --- a/src/renderer/styles/MainContent.scss +++ b/src/renderer/styles/MainContent.scss @@ -42,6 +42,7 @@ position: relative; justify-content: flex-start; padding: 0 $spacing-xxs; // add some horizontal padding so the outline isn't cut off at either end + height: 100%; width: 100%; overflow-x: auto; overflow-y: hidden; diff --git a/src/renderer/styles/_constant.scss b/src/renderer/styles/_constant.scss index e98a973d7..980b3ff6a 100644 --- a/src/renderer/styles/_constant.scss +++ b/src/renderer/styles/_constant.scss @@ -9,3 +9,6 @@ $equalizer-height: 580px; // NumberInput $input-height: 24px; + +// FrequencyBand and AddSliderDivider +$sort-animate-duration: 500ms;