mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
refactor(settings/sources): replace __default__ sentinel with null bucket
moveDeviceType now takes bucket: string | null where null means the global ladder. The function maps null to the canonical "default" key once at the top of the body and reads + writes that key uniformly, removing the two equal-shape if branches and the magic-string check that drove them. Callers pass null instead of "__default__".
This commit is contained in:
1 parent
8c929fc554
commit
ec484e0af2
1 file changed
+11
-13
@@ -192,26 +192,24 @@ export function SourcesSection() {
|
||||
}
|
||||
|
||||
function moveDeviceType(
|
||||
/** `__default__` for the global ladder, MeasurementType-enum string otherwise. */
|
||||
bucket: string,
|
||||
/** `null` for the global ladder, MeasurementType-enum string otherwise. */
|
||||
bucket: string | null,
|
||||
index: number,
|
||||
delta: -1 | 1,
|
||||
) {
|
||||
if (!priority) return;
|
||||
const current = bucket === "__default__"
|
||||
? priority.deviceTypePriority.default ?? [...DEFAULT_DEVICE_TYPE_PRIORITY]
|
||||
: priority.deviceTypePriority[bucket] ?? [...DEFAULT_DEVICE_TYPE_PRIORITY];
|
||||
const key = bucket ?? "default";
|
||||
const current =
|
||||
priority.deviceTypePriority[key] ?? [...DEFAULT_DEVICE_TYPE_PRIORITY];
|
||||
const list = [...current];
|
||||
const targetIdx = index + delta;
|
||||
if (targetIdx < 0 || targetIdx >= list.length) return;
|
||||
[list[index], list[targetIdx]] = [list[targetIdx], list[index]];
|
||||
|
||||
const nextDevicePriority: DeviceTypePriority = { ...priority.deviceTypePriority };
|
||||
if (bucket === "__default__") {
|
||||
nextDevicePriority.default = list;
|
||||
} else {
|
||||
nextDevicePriority[bucket] = list;
|
||||
}
|
||||
const nextDevicePriority: DeviceTypePriority = {
|
||||
...priority.deviceTypePriority,
|
||||
[key]: list,
|
||||
};
|
||||
setDraft({ ...priority, deviceTypePriority: nextDevicePriority });
|
||||
}
|
||||
|
||||
@@ -496,7 +494,7 @@ export function SourcesSection() {
|
||||
size="icon"
|
||||
className="h-11 w-11"
|
||||
onClick={() =>
|
||||
moveDeviceType("__default__", index, -1)
|
||||
moveDeviceType(null, index, -1)
|
||||
}
|
||||
disabled={index === 0 || saveMutation.isPending}
|
||||
aria-label={t("settings.sections.sources.moveUp")}
|
||||
@@ -508,7 +506,7 @@ export function SourcesSection() {
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-11 w-11"
|
||||
onClick={() => moveDeviceType("__default__", index, 1)}
|
||||
onClick={() => moveDeviceType(null, index, 1)}
|
||||
disabled={
|
||||
index === list.length - 1 || saveMutation.isPending
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user