[Refactor] Implement useSaveButtonLogic for managing save functionality in Translation settings.
This commit is contained in:
@@ -309,6 +309,39 @@ export const useSliderLogic = ({
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
export const useSaveButtonLogic = ({
|
||||
variable,
|
||||
state,
|
||||
setFunction,
|
||||
deleteFunction
|
||||
}) => {
|
||||
const [input_value, setInputValue] = useState(variable);
|
||||
|
||||
const onChangeFunction = (value) => {
|
||||
setInputValue(value);
|
||||
};
|
||||
|
||||
const saveFunction = () => {
|
||||
if (input_value === "" || input_value === null) {
|
||||
return deleteFunction();
|
||||
}
|
||||
setFunction(input_value);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (state === "pending") return;
|
||||
setInputValue(variable);
|
||||
|
||||
}, [variable]);
|
||||
|
||||
return {
|
||||
variable: input_value,
|
||||
onChangeFunction: onChangeFunction,
|
||||
saveFunction: saveFunction,
|
||||
};
|
||||
};
|
||||
|
||||
const createMarks = (min, max, marks_step = 1, labelFormatter = (value) => value) => {
|
||||
const marks = [];
|
||||
let variable = min;
|
||||
|
||||
@@ -18,4 +18,5 @@ export { useSettingBoxScrollPosition } from "./config_page_setter/_aux/useSettin
|
||||
|
||||
export {
|
||||
useSliderLogic,
|
||||
useSaveButtonLogic,
|
||||
} from "./config_page_setter/useSettingsLogics.js";
|
||||
Reference in New Issue
Block a user