Add notes to hosts, instances, users and other resources (#1000)

This commit is contained in:
Bastiaan authored and GitHub committed 2026-10-18 20:06:15 +03:00
1 parent ee39945c83
commit cbf2b10782
25 files changed
+830 -52

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
import { useCallback, useContext, useSyncExternalStore } from "react";
import ControlContext from "../components/ControlContext";
import * as lib from "@clusterio/lib";
export function useNote(resourceType: string, resourceId?: string | number) {
const [notes, synced] = useNotes();
const note = resourceId !== undefined ? notes.get(lib.Note.idFor(resourceType, resourceId)) : undefined;
return [note, synced] as const;
}
export function useNotes() {
const control = useContext(ControlContext);
const subscribe = useCallback((callback: () => void) => control.notes.subscribe(callback), [control]);
return useSyncExternalStore(subscribe, () => control.notes.getSnapshot());
}