Skip to content

Commit

Permalink
Revert Resettable changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Mar 14, 2024
1 parent 352cbc0 commit 19887f2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 37 deletions.
39 changes: 16 additions & 23 deletions src/components/editors/MultipleColorEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ export default function MultipleColorEditor(props: Props) {
value="↑"
disabled={index === 0}
onClick={() => {
resettable.setValue((value) => {
const newValue = value.slice();
const newValue = arr.slice();

[newValue[index - 1], newValue[index]] = [
newValue[index],
newValue[index - 1],
];
[newValue[index - 1], newValue[index]] = [
newValue[index],
newValue[index - 1],
];

return newValue;
});
resettable.setValue(newValue);
}}
/>

Expand All @@ -72,16 +70,14 @@ export default function MultipleColorEditor(props: Props) {
value="↓"
disabled={index === arr.length - 1}
onClick={() => {
resettable.setValue((value) => {
const newValue = value.slice();
const newValue = arr.slice();

[newValue[index], newValue[index + 1]] = [
newValue[index + 1],
newValue[index],
];
[newValue[index], newValue[index + 1]] = [
newValue[index + 1],
newValue[index],
];

return newValue;
});
resettable.setValue(newValue);
}}
/>

Expand All @@ -91,13 +87,10 @@ export default function MultipleColorEditor(props: Props) {
value="Remove"
disabled={arr.length === 1}
onClick={() => {
resettable.setValue((value) => {
const newValue = value.slice();
const newValue = arr.slice();
newValue.splice(index, 1);

newValue.splice(index, 1);

return newValue;
});
resettable.setValue(newValue);
}}
/>
</div>
Expand Down Expand Up @@ -145,7 +138,7 @@ export default function MultipleColorEditor(props: Props) {
type="button"
value="Add"
onClick={() => {
resettable.setValue((value) => value.concat(hexCode));
resettable.setValue(resettable.value.concat(hexCode));
}}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/ComboColor/ComboColorsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function ComboColorsContextProvider(props: PropsWithChildren) {
setValue(defaultValue);
},
setValue: (value = defaultValue) => {
setValue(value);
setValue(value.slice());
},
saveToJSON(json) {
if (!forceOverride.value) {
Expand Down
3 changes: 1 addition & 2 deletions src/structures/resettable/NumberJSONResettable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ import { NumberResettable } from "./NumberResettable";
/**
* A storage structure that allows the stored number to be reset and saved to a skin.json.
*/
export type NumberJSONResettable = NumberResettable &
Omit<JSONResettable<number>, "setValue">;
export type NumberJSONResettable = NumberResettable & JSONResettable<number>;
9 changes: 1 addition & 8 deletions src/structures/resettable/NumberResettable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { Resettable } from "./Resettable";
/**
* A number `Resettable` that has additional properties to deal with numbers.
*/
export interface NumberResettable extends Omit<Resettable<number>, "setValue"> {
/**
* Sets the value of this `NumberResettable`.
*
* @param value The new value. Defaults to the default value.
*/
setValue(value?: number): void;

export interface NumberResettable extends Resettable<number> {
/**
* The minimum number allowed.
*/
Expand Down
4 changes: 1 addition & 3 deletions src/structures/resettable/Resettable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { SetStateAction } from "react";

/**
* A storage structure that allows the stored value to be reset.
*/
Expand Down Expand Up @@ -29,5 +27,5 @@ export interface Resettable<T = unknown> {
*
* @param value The new value. Defaults to the default value.
*/
setValue(value?: SetStateAction<T>): void;
setValue(value?: T): void;
}

0 comments on commit 19887f2

Please sign in to comment.