Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 28 additions & 34 deletions apps/web/src/components/settings/ProviderAccentColorPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { PlusIcon, XIcon } from "lucide-react";
import { useCallback, useEffect, useRef, useState } from "react";
import { useEffect, useRef, useState } from "react";

import { hexToHsv, hsvToHex, type HsvColor } from "../../lib/color";
import { ColorHueSlider, ColorSaturationValuePlane } from "../ui/color-picker";
Expand All @@ -21,13 +21,10 @@ function ProviderCustomColorPanel(props: {
const currentColor = hsvToHex(hsv.h, hsv.s, hsv.v);
const [hexDraft, setHexDraft] = useState<string | null>(null);

const commitHsv = useCallback(
(nextHsv: HsvColor) => {
setHsv(nextHsv);
onCommit(hsvToHex(nextHsv.h, nextHsv.s, nextHsv.v));
},
[onCommit],
);
const commitHsv = (nextHsv: HsvColor) => {
setHsv(nextHsv);
onCommit(hsvToHex(nextHsv.h, nextHsv.s, nextHsv.v));
};

return (
<div className="w-56 bg-popover">
Expand Down Expand Up @@ -161,36 +158,33 @@ export function ProviderAccentColorPicker(props: {
};
}, []);

const commitAccentColor = useCallback(
(value: string) => {
const normalizedValue = normalizeProviderAccentColor(value) ?? "";
setOptimisticValue(normalizedValue);

if (commitDelayMs <= 0) {
pendingCommitRef.current = null;
if (commitTimeoutRef.current !== null) {
clearTimeout(commitTimeoutRef.current);
commitTimeoutRef.current = null;
}
onCommit(normalizedValue);
return;
}
const commitAccentColor = (value: string) => {
const normalizedValue = normalizeProviderAccentColor(value) ?? "";
setOptimisticValue(normalizedValue);

pendingCommitRef.current = normalizedValue;
if (commitDelayMs <= 0) {
pendingCommitRef.current = null;
if (commitTimeoutRef.current !== null) {
clearTimeout(commitTimeoutRef.current);
}
commitTimeoutRef.current = setTimeout(() => {
commitTimeoutRef.current = null;
const pendingCommit = pendingCommitRef.current;
pendingCommitRef.current = null;
if (pendingCommit !== null) {
onCommitRef.current(pendingCommit);
}
}, commitDelayMs);
},
[commitDelayMs, onCommit],
);
}
onCommit(normalizedValue);
return;
}

pendingCommitRef.current = normalizedValue;
if (commitTimeoutRef.current !== null) {
clearTimeout(commitTimeoutRef.current);
}
commitTimeoutRef.current = setTimeout(() => {
commitTimeoutRef.current = null;
const pendingCommit = pendingCommitRef.current;
pendingCommitRef.current = null;
if (pendingCommit !== null) {
onCommitRef.current(pendingCommit);
}
}, commitDelayMs);
};

const normalized = normalizeProviderAccentColor(optimisticValue);
const picker = (
Expand Down
Loading