Fixed all bugs with tweaks on API modal

This commit is contained in:
Lucas Oliveira 2023-07-24 09:55:42 -03:00
commit 169a20ab97
9 changed files with 1098 additions and 2393 deletions

File diff suppressed because it is too large Load diff

View file

@ -254,8 +254,7 @@ export default function CodeTabsComponent({
n n
].value ].value
} }
onChange={(k) => {}} onChange={(k) => {
onAddInput={(k) => {
tweaks.buildTweakObject( tweaks.buildTweakObject(
t["data"]["id"], t["data"]["id"],
k, k,

View file

@ -1,4 +1,4 @@
import { useEffect } from "react"; import { useEffect, useState } from "react";
import { FloatComponentType } from "../../types/components"; import { FloatComponentType } from "../../types/components";
export default function FloatComponent({ export default function FloatComponent({
@ -11,6 +11,12 @@ export default function FloatComponent({
const min = 0; const min = 0;
const max = 1; const max = 1;
const [myValue, setMyValue] = useState(value);
useEffect(() => {
setMyValue(value);
}, [value]);
// Clear component state // Clear component state
useEffect(() => { useEffect(() => {
if (disabled) { if (disabled) {
@ -33,7 +39,7 @@ export default function FloatComponent({
} }
}} }}
max={max} max={max}
value={value ?? ""} value={myValue ?? ""}
className={ className={
"nopan nodrag noundo nocopy " + "nopan nodrag noundo nocopy " +
(editNode (editNode
@ -45,6 +51,7 @@ export default function FloatComponent({
} }
onChange={(e) => { onChange={(e) => {
onChange(e.target.value); onChange(e.target.value);
setMyValue(e.target.value);
}} }}
/> />
</div> </div>

View file

@ -10,6 +10,11 @@ export default function InputComponent({
editNode = false, editNode = false,
}: InputComponentType) { }: InputComponentType) {
const [pwdVisible, setPwdVisible] = useState(false); const [pwdVisible, setPwdVisible] = useState(false);
const [myValue, setMyValue] = useState(value);
useEffect(() => {
setMyValue(value);
}, [value]);
// Clear component state // Clear component state
useEffect(() => { useEffect(() => {
@ -21,7 +26,7 @@ export default function InputComponent({
return ( return (
<div className={disabled ? "input-component-div" : "relative"}> <div className={disabled ? "input-component-div" : "relative"}>
<input <input
value={value} value={myValue}
className={classNames( className={classNames(
disabled ? " input-disable " : "", disabled ? " input-disable " : "",
password && !pwdVisible && value !== "" ? " text-clip password " : "", password && !pwdVisible && value !== "" ? " text-clip password " : "",
@ -33,6 +38,7 @@ export default function InputComponent({
placeholder={password && editNode ? "Key" : "Type something..."} placeholder={password && editNode ? "Key" : "Type something..."}
onChange={(e) => { onChange={(e) => {
onChange(e.target.value); onChange(e.target.value);
setMyValue(e.target.value);
}} }}
/> />
{password && ( {password && (

View file

@ -10,7 +10,6 @@ export default function InputListComponent({
onChange, onChange,
disabled, disabled,
editNode = false, editNode = false,
onAddInput,
}: InputListComponentType) { }: InputListComponentType) {
const [inputList, setInputList] = useState(value ?? [""]); const [inputList, setInputList] = useState(value ?? [""]);
const { closeEdit } = useContext(PopUpContext); const { closeEdit } = useContext(PopUpContext);

View file

@ -1,4 +1,4 @@
import { useEffect } from "react"; import { useEffect, useState } from "react";
import { FloatComponentType } from "../../types/components"; import { FloatComponentType } from "../../types/components";
export default function IntComponent({ export default function IntComponent({
@ -9,6 +9,12 @@ export default function IntComponent({
}: FloatComponentType) { }: FloatComponentType) {
const min = 0; const min = 0;
const [myValue, setMyValue] = useState(value);
useEffect(() => {
setMyValue(value);
}, [value]);
// Clear component state // Clear component state
useEffect(() => { useEffect(() => {
if (disabled) { if (disabled) {
@ -50,7 +56,7 @@ export default function IntComponent({
e.target.value = min.toString(); e.target.value = min.toString();
} }
}} }}
value={value ?? ""} value={myValue ?? ""}
className={ className={
"nopan nodrag noundo nocopy " + "nopan nodrag noundo nocopy " +
(editNode (editNode
@ -60,6 +66,7 @@ export default function IntComponent({
placeholder={editNode ? "Integer number" : "Type an integer number"} placeholder={editNode ? "Integer number" : "Type an integer number"}
onChange={(e) => { onChange={(e) => {
onChange(e.target.value); onChange(e.target.value);
setMyValue(e.target.value);
}} }}
/> />
</div> </div>

View file

@ -1,3 +1,4 @@
import { useEffect, useState } from "react";
import { ToggleComponentType } from "../../types/components"; import { ToggleComponentType } from "../../types/components";
import { Switch } from "../ui/switch"; import { Switch } from "../ui/switch";
@ -25,6 +26,13 @@ export default function ToggleShadComponent({
scaleX = 1; scaleX = 1;
scaleY = 1; scaleY = 1;
} }
const [myValue, setMyValue] = useState(enabled);
useEffect(() => {
setMyValue(enabled);
}, [enabled]);
return ( return (
<div className={disabled ? "pointer-events-none cursor-not-allowed " : ""}> <div className={disabled ? "pointer-events-none cursor-not-allowed " : ""}>
<Switch <Switch
@ -33,9 +41,10 @@ export default function ToggleShadComponent({
}} }}
disabled={disabled} disabled={disabled}
className="" className=""
checked={enabled} checked={myValue}
onCheckedChange={(x: boolean) => { onCheckedChange={(x: boolean) => {
setEnabled(x); setEnabled(x);
setMyValue(x);
}} }}
></Switch> ></Switch>
</div> </div>

View file

@ -45,7 +45,6 @@ export type InputListComponentType = {
onChange: (value: string[]) => void; onChange: (value: string[]) => void;
disabled: boolean; disabled: boolean;
editNode?: boolean; editNode?: boolean;
onAddInput?: (value?: string[]) => void;
}; };
export type TextAreaComponentType = { export type TextAreaComponentType = {

View file

@ -275,7 +275,7 @@ export function buildTweakObject(tweak) {
}); });
}); });
const tweakString = JSON.stringify(tweak, null, 2); const tweakString = JSON.stringify(tweak.at(-1), null, 2);
return tweakString; return tweakString;
} }