mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 07:30:41 +09:00
Add notes to hosts, instances, users and other resources (#1000)
This commit is contained in:
1 parent
ee39945c83
commit
cbf2b10782
25 files changed
+830
-52
No files matched your search
@@ -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());
|
||||
}
|
||||
Reference in new issue
Block a user