From 37989d5f7a05bbcb7c5bd7139cc548ac7e197cb2 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Tue, 10 Sep 2024 07:46:37 +0900 Subject: [PATCH] [Update] Config Page: Device Tab. To sync Threshold value between slider and entry component. --- .../ThresholdComponent.jsx | 70 ++++++++++++++++++- .../slider_and_meter/SliderAndMeter.jsx | 53 ++++++-------- .../threshold_entry/ThresholdEntry.jsx | 20 +++--- 3 files changed, 95 insertions(+), 48 deletions(-) diff --git a/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/ThresholdComponent.jsx b/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/ThresholdComponent.jsx index f3c86b1e..0ce81361 100644 --- a/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/ThresholdComponent.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/ThresholdComponent.jsx @@ -1,14 +1,78 @@ +import { useState } from "react"; + import styles from "./ThresholdComponent.module.scss"; import { SliderAndMeter } from "./slider_and_meter/SliderAndMeter"; import { ThresholdEntry } from "./threshold_entry/ThresholdEntry"; import { VolumeCheckButton } from "./volume_check_button/VolumeCheckButton"; +import { useConfig } from "@logics/useConfig"; export const ThresholdComponent = (props) => { return (
- - - + + {props.id === "mic_threshold" + ? + : + }
); +}; + +const MicComponent = (props) => { + const { currentMicThreshold, setMicThreshold } = useConfig(); + const [ui_threshold, setUiThreshold] = useState(currentMicThreshold); + + const setUiThresholdFunction = (payload_ui_threshold) => { + setUiThreshold(payload_ui_threshold); + }; + const setThresholdFunction = (payload_threshold) => { + setMicThreshold(payload_threshold); + }; + + return ( + <> + + + + ); +}; + +const SpeakerComponent = (props) => { + + const { currentSpeakerThreshold, setSpeakerThreshold } = useConfig(); + const [ui_threshold, setUiThreshold] = useState(currentSpeakerThreshold); + + const setUiThresholdFunction = (payload_ui_threshold) => { + setUiThreshold(payload_ui_threshold); + }; + const setThresholdFunction = (payload_threshold) => { + setSpeakerThreshold(payload_threshold); + }; + + return ( + <> + + + + ); }; \ No newline at end of file diff --git a/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/slider_and_meter/SliderAndMeter.jsx b/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/slider_and_meter/SliderAndMeter.jsx index bf98c313..e22ab890 100644 --- a/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/slider_and_meter/SliderAndMeter.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/slider_and_meter/SliderAndMeter.jsx @@ -6,15 +6,14 @@ import { } from "@store"; import { useVolume } from "@logics/useVolume"; -import { useConfig } from "@logics/useConfig"; export const SliderAndMeter = (props) => { return (
{props.id === "mic_threshold" - ? - : + ? + : }
@@ -23,28 +22,22 @@ export const SliderAndMeter = (props) => { }; -const ThresholdVolumeMeter_Mic = ({min, max}) => { +const ThresholdVolumeMeter_Mic = (props) => { const { currentMicVolume } = useMicVolume(); - const { currentMicThreshold, setMicThreshold } = useConfig(); - const [threshold, setThreshold] = useState(currentMicThreshold); - const currentVolumeVariable = Math.min(currentMicVolume.data, max); - const volume_width_percentage = (currentVolumeVariable / max) * 100; - - const onMOuseUpFunction = () => { - setMicThreshold(threshold); - }; + const currentVolumeVariable = Math.min(currentMicVolume.data, props.max); + const volume_width_percentage = (currentVolumeVariable / props.max) * 100; return ( <> - + setThreshold(e.target.value)} - onMouseUp={() => onMOuseUpFunction()} + min={props.min} + max={props.max} + value={props.ui_threshold} + onChange={(e) => props.setUiThresholdFunction(e.target.value)} + onMouseUp={(e) => props.setThresholdFunction(e.target.value)} className={styles.threshold_slider} /> @@ -52,28 +45,22 @@ const ThresholdVolumeMeter_Mic = ({min, max}) => { }; -const ThresholdVolumeMeter_Speaker = ({ min, max }) => { +const ThresholdVolumeMeter_Speaker = (props) => { const { currentSpeakerVolume } = useSpeakerVolume(); - const { currentSpeakerThreshold, setSpeakerThreshold } = useConfig(); - const [threshold, setThreshold] = useState(currentSpeakerThreshold); - const currentVolumeVariable = Math.min(currentSpeakerVolume.data, max); - const volume_width_percentage = (currentVolumeVariable / max) * 100; - - const onMouseUpFunction = () => { - setSpeakerThreshold(threshold); - }; + const currentVolumeVariable = Math.min(currentSpeakerVolume.data, props.max); + const volume_width_percentage = (currentVolumeVariable / props.max) * 100; return ( <> - + setThreshold(e.target.value)} - onMouseUp={() => onMouseUpFunction()} + min={props.min} + max={props.max} + value={props.ui_threshold} + onChange={(e) => props.setUiThresholdFunction(e.target.value)} + onMouseUp={(e) => props.setThresholdFunction(e.target.value)} className={styles.threshold_slider} /> diff --git a/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/threshold_entry/ThresholdEntry.jsx b/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/threshold_entry/ThresholdEntry.jsx index 95d9f825..a464c7ea 100644 --- a/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/threshold_entry/ThresholdEntry.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/components/threshold_component/threshold_entry/ThresholdEntry.jsx @@ -1,46 +1,42 @@ -import { useState, useEffect } from "react"; import styles from "./ThresholdEntry.module.scss"; -import { useConfig } from "@logics/useConfig"; export const ThresholdEntry = (props) => { return (
{props.id === "mic_threshold" - ? - : + ? + : }
); }; -const ThresholdEntry_Mic = () => { - const { currentMicThreshold, setMicThreshold } = useConfig(); +const ThresholdEntry_Mic = (props) => { const onChangeFunction = (e) => { - setMicThreshold(e.currentTarget.value); + props.setThresholdFunction(e.currentTarget.value); }; return ( ); }; -const ThresholdEntry_Speaker = () => { - const { currentSpeakerThreshold, setSpeakerThreshold } = useConfig(); +const ThresholdEntry_Speaker = (props) => { const onChangeFunction = (e) => { - setSpeakerThreshold(e.currentTarget.value); + props.setThresholdFunction(e.currentTarget.value); }; return ( ); }; \ No newline at end of file