mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-06 07:38:46 +00:00
more ui/ux enhancements around labels and tables
This commit is contained in:
21
src/hooks/useLocalLabels.ts
Normal file
21
src/hooks/useLocalLabels.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { SelectedLabel } from "@app/components/labels-selector";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useLocalLabels(
|
||||
serverLabels: SelectedLabel[] | undefined,
|
||||
entityId: number
|
||||
) {
|
||||
const labels = serverLabels ?? [];
|
||||
const [localLabels, setLocalLabels] = useState(labels);
|
||||
|
||||
const serverLabelIds = labels
|
||||
.map((label) => label.labelId)
|
||||
.sort((a, b) => a - b)
|
||||
.join(",");
|
||||
|
||||
useEffect(() => {
|
||||
setLocalLabels(serverLabels ?? []);
|
||||
}, [entityId, serverLabelIds]);
|
||||
|
||||
return [localLabels, setLocalLabels] as const;
|
||||
}
|
||||
Reference in New Issue
Block a user