2023-08-01 17:25:02 +03:00
|
|
|
import { ChatConfig } from "@/lib/context/ChatProvider/types";
|
2023-09-26 19:41:02 +03:00
|
|
|
const chatConfigLocalStorageKey = "chat-config";
|
2023-12-01 00:08:36 +03:00
|
|
|
|
|
|
|
type PartialChatConfig = Partial<ChatConfig>;
|
|
|
|
|
|
|
|
export const saveChatsConfigInLocalStorage = (
|
|
|
|
chatConfig: PartialChatConfig
|
|
|
|
): void => {
|
2023-09-26 19:41:02 +03:00
|
|
|
localStorage.setItem(chatConfigLocalStorageKey, JSON.stringify(chatConfig));
|
2023-08-01 17:25:02 +03:00
|
|
|
};
|
|
|
|
|
2023-12-01 00:08:36 +03:00
|
|
|
export const getChatsConfigFromLocalStorage = ():
|
|
|
|
| PartialChatConfig
|
|
|
|
| undefined => {
|
|
|
|
try {
|
|
|
|
const config = localStorage.getItem(chatConfigLocalStorageKey);
|
2023-08-01 17:25:02 +03:00
|
|
|
|
2023-12-01 00:08:36 +03:00
|
|
|
if (config === null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JSON.parse(config) as PartialChatConfig;
|
|
|
|
} catch (error) {
|
2023-08-01 17:25:02 +03:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
};
|