anything-llm/embed/src/hooks/useOpen.js
timothycarambat 9fc45daf77 more style support
reopen if chat was last opened
2024-02-02 13:31:26 -08:00

17 lines
502 B
JavaScript

import { CHAT_UI_REOPEN } from "@/utils/constants";
import { useState } from "react";
export default function useOpenChat() {
const [isOpen, setOpen] = useState(
!!window?.localStorage?.getItem(CHAT_UI_REOPEN) || false
);
function toggleOpenChat(newValue) {
if (newValue === true) window.localStorage.setItem(CHAT_UI_REOPEN, "1");
if (newValue === false) window.localStorage.removeItem(CHAT_UI_REOPEN);
setOpen(newValue);
}
return { isChatOpen: isOpen, toggleOpenChat };
}