summaryrefslogtreecommitdiff
path: root/apps/web/src/components/editor/panels/assets/views/settings
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/components/editor/panels/assets/views/settings')
-rw-r--r--apps/web/src/components/editor/panels/assets/views/settings/index.tsx32
1 files changed, 20 insertions, 12 deletions
diff --git a/apps/web/src/components/editor/panels/assets/views/settings/index.tsx b/apps/web/src/components/editor/panels/assets/views/settings/index.tsx
index bf3a1c16..5edbeab3 100644
--- a/apps/web/src/components/editor/panels/assets/views/settings/index.tsx
+++ b/apps/web/src/components/editor/panels/assets/views/settings/index.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useRef, useState } from "react";
+import { useState } from "react";
import { PanelView } from "@/components/editor/panels/assets/views/base-panel";
import {
Select,
@@ -34,6 +34,10 @@ import type { TCanvasSize } from "@/project/types";
type SettingsView = "project-info" | "background";
+function isSettingsView(value: string): value is SettingsView {
+ return value === "project-info" || value === "background";
+}
+
const PRESET_LABELS: Record<string, string> = {
"1:1": "1:1",
"16:9": "16:9",
@@ -73,23 +77,20 @@ function useCanvasDimensionDraft({
value: number;
onCommit: (value: number) => void;
}) {
- const pendingValueRef = useRef(value);
- const syncedValueRef = useRef(value);
-
- if (syncedValueRef.current !== value) {
- syncedValueRef.current = value;
- pendingValueRef.current = value;
- }
+ const [pendingValue, setPendingValue] = useState(value);
return usePropertyDraft({
displayValue: formatCanvasDimension({ value }),
parse: (input) => parseCanvasDimension({ input }),
+ onStartEditing: () => {
+ setPendingValue(value);
+ },
onPreview: (nextValue) => {
- pendingValueRef.current = nextValue;
+ setPendingValue(nextValue);
},
onCommit: () => {
- if (pendingValueRef.current !== value) {
- onCommit(pendingValueRef.current);
+ if (pendingValue !== value) {
+ onCommit(pendingValue);
}
},
});
@@ -212,7 +213,14 @@ export function SettingsView() {
contentClassName="px-0"
scrollClassName="pt-0"
actions={
- <Tabs value={view} onValueChange={(v) => setView(v as SettingsView)}>
+ <Tabs
+ value={view}
+ onValueChange={(value) => {
+ if (isSettingsView(value)) {
+ setView(value);
+ }
+ }}
+ >
<TabsList>
<TabsTrigger value="project-info">Project info</TabsTrigger>
<TabsTrigger value="background">Background</TabsTrigger>