Enhance adjustment nodes with localized labels and improved state management
- Integrated localization for slider labels and prompts in color-adjust, curves, detail-adjust, and light-adjust nodes. - Updated preset handling to include user-friendly prompts for saving presets. - Improved state management for slider values and preset selections, enhancing user experience. - Added reset actions to adjustment nodes for better control over user adjustments.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Handle, Position, type Node, type NodeProps } from "@xyflow/react";
|
||||
import { useMutation } from "convex/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Sun } from "lucide-react";
|
||||
|
||||
import { api } from "@/convex/_generated/api";
|
||||
@@ -41,6 +42,9 @@ type PresetDoc = {
|
||||
};
|
||||
|
||||
export default function LightAdjustNode({ id, data, selected, width }: NodeProps<LightAdjustNodeType>) {
|
||||
const tCommon = useTranslations("common");
|
||||
const tNodes = useTranslations("nodes");
|
||||
const tToasts = useTranslations("toasts");
|
||||
const { queueNodeDataUpdate } = useCanvasSync();
|
||||
const savePreset = useMutation(api.presets.save);
|
||||
const userPresets = (useAuthQuery(api.presets.list, { nodeType: "light-adjust" }) ?? []) as PresetDoc[];
|
||||
@@ -88,21 +92,21 @@ export default function LightAdjustNode({ id, data, selected, width }: NodeProps
|
||||
() => [
|
||||
{
|
||||
id: "brightness",
|
||||
label: "Brightness",
|
||||
label: tNodes("adjustments.lightAdjust.sliders.brightness"),
|
||||
min: -100,
|
||||
max: 100,
|
||||
value: DEFAULT_LIGHT_ADJUST_DATA.brightness,
|
||||
},
|
||||
{
|
||||
id: "contrast",
|
||||
label: "Contrast",
|
||||
label: tNodes("adjustments.lightAdjust.sliders.contrast"),
|
||||
min: -100,
|
||||
max: 100,
|
||||
value: DEFAULT_LIGHT_ADJUST_DATA.contrast,
|
||||
},
|
||||
{
|
||||
id: "exposure",
|
||||
label: "Exposure",
|
||||
label: tNodes("adjustments.lightAdjust.sliders.exposure"),
|
||||
min: -5,
|
||||
max: 5,
|
||||
step: 0.01,
|
||||
@@ -111,35 +115,35 @@ export default function LightAdjustNode({ id, data, selected, width }: NodeProps
|
||||
},
|
||||
{
|
||||
id: "highlights",
|
||||
label: "Highlights",
|
||||
label: tNodes("adjustments.lightAdjust.sliders.highlights"),
|
||||
min: -100,
|
||||
max: 100,
|
||||
value: DEFAULT_LIGHT_ADJUST_DATA.highlights,
|
||||
},
|
||||
{
|
||||
id: "shadows",
|
||||
label: "Shadows",
|
||||
label: tNodes("adjustments.lightAdjust.sliders.shadows"),
|
||||
min: -100,
|
||||
max: 100,
|
||||
value: DEFAULT_LIGHT_ADJUST_DATA.shadows,
|
||||
},
|
||||
{
|
||||
id: "whites",
|
||||
label: "Whites",
|
||||
label: tNodes("adjustments.lightAdjust.sliders.whites"),
|
||||
min: -100,
|
||||
max: 100,
|
||||
value: DEFAULT_LIGHT_ADJUST_DATA.whites,
|
||||
},
|
||||
{
|
||||
id: "blacks",
|
||||
label: "Blacks",
|
||||
label: tNodes("adjustments.lightAdjust.sliders.blacks"),
|
||||
min: -100,
|
||||
max: 100,
|
||||
value: DEFAULT_LIGHT_ADJUST_DATA.blacks,
|
||||
},
|
||||
{
|
||||
id: "vignette-amount",
|
||||
label: "Vignette",
|
||||
label: tNodes("adjustments.lightAdjust.sliders.vignette"),
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.01,
|
||||
@@ -147,7 +151,7 @@ export default function LightAdjustNode({ id, data, selected, width }: NodeProps
|
||||
value: DEFAULT_LIGHT_ADJUST_DATA.vignette.amount,
|
||||
},
|
||||
],
|
||||
[],
|
||||
[tNodes],
|
||||
);
|
||||
const sliderValues = useMemo<SliderValue[]>(
|
||||
() => [
|
||||
@@ -201,14 +205,14 @@ export default function LightAdjustNode({ id, data, selected, width }: NodeProps
|
||||
};
|
||||
|
||||
const handleSavePreset = async () => {
|
||||
const name = window.prompt("Preset-Name");
|
||||
const name = window.prompt(tNodes("adjustments.common.presetNamePrompt"));
|
||||
if (!name) return;
|
||||
await savePreset({
|
||||
name,
|
||||
nodeType: "light-adjust",
|
||||
params: localData,
|
||||
});
|
||||
toast.success("Preset gespeichert");
|
||||
toast.success(tToasts("canvas.adjustmentPresetSaved"));
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -228,24 +232,24 @@ export default function LightAdjustNode({ id, data, selected, width }: NodeProps
|
||||
<div className="space-y-3 p-3">
|
||||
<div className="flex items-center gap-1.5 text-xs font-medium text-amber-700 dark:text-amber-300">
|
||||
<Sun className="h-3.5 w-3.5" />
|
||||
Licht
|
||||
{tNodes("adjustments.lightAdjust.title")}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Select value={presetSelection} onValueChange={applyPresetValue}>
|
||||
<SelectTrigger className="nodrag h-8 text-xs" size="sm">
|
||||
<SelectValue placeholder="Preset" />
|
||||
<SelectValue placeholder={tNodes("adjustments.common.presetPlaceholder")} />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="nodrag">
|
||||
<SelectItem value="custom">Custom</SelectItem>
|
||||
<SelectItem value="custom">{tNodes("custom")}</SelectItem>
|
||||
{builtinOptions.map(([name]) => (
|
||||
<SelectItem key={name} value={`builtin:${name}`}>
|
||||
Built-in: {name}
|
||||
{tNodes("adjustments.common.builtinPresetLabel", { name })}
|
||||
</SelectItem>
|
||||
))}
|
||||
{userPresets.map((preset) => (
|
||||
<SelectItem key={preset._id} value={`user:${preset._id}`}>
|
||||
User: {preset.name}
|
||||
{tNodes("adjustments.common.userPresetLabel", { name: preset.name })}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
@@ -257,7 +261,7 @@ export default function LightAdjustNode({ id, data, selected, width }: NodeProps
|
||||
void handleSavePreset();
|
||||
}}
|
||||
>
|
||||
Save
|
||||
{tCommon("save")}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -276,6 +280,7 @@ export default function LightAdjustNode({ id, data, selected, width }: NodeProps
|
||||
fillClassName="bg-amber-500/35 dark:bg-amber-400/35"
|
||||
handleClassName="bg-amber-500 dark:bg-amber-400"
|
||||
trackClassName="bg-amber-500/10 dark:bg-amber-500/15"
|
||||
actions={[{ id: "reset", label: tCommon("reset") }]}
|
||||
onChange={(values) => {
|
||||
const valueById = new Map(values.map((entry) => [entry.id, entry.value]));
|
||||
updateData((current) => ({
|
||||
@@ -294,11 +299,6 @@ export default function LightAdjustNode({ id, data, selected, width }: NodeProps
|
||||
preset: null,
|
||||
}));
|
||||
}}
|
||||
onAction={async (actionId) => {
|
||||
if (actionId === "apply") {
|
||||
queueSave();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user