mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-02 12:49:20 +01:00
35 lines
842 B
TypeScript
35 lines
842 B
TypeScript
"use client";
|
|
|
|
import { useCallback } from "react";
|
|
|
|
import type { RouterOutputs } from "@homarr/api";
|
|
import { clientApi } from "@homarr/api/client";
|
|
|
|
let boardName: string | null = null;
|
|
|
|
export const updateBoardName = (name: string | null) => {
|
|
boardName = name;
|
|
};
|
|
|
|
type UpdateCallback = (prev: RouterOutputs["board"]["getHomeBoard"]) => RouterOutputs["board"]["getHomeBoard"];
|
|
|
|
export const useUpdateBoard = () => {
|
|
const utils = clientApi.useUtils();
|
|
|
|
const updateBoard = useCallback(
|
|
(updaterWithoutUndefined: UpdateCallback) => {
|
|
if (!boardName) {
|
|
throw new Error("Board name is not set");
|
|
}
|
|
utils.board.getBoardByName.setData({ name: boardName }, (previous) =>
|
|
previous ? updaterWithoutUndefined(previous) : previous,
|
|
);
|
|
},
|
|
[utils],
|
|
);
|
|
|
|
return {
|
|
updateBoard,
|
|
};
|
|
};
|