mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-22 19:01:49 +03:00
b0514d6149
* add libraries for traslation purposes * Add button and service for language selection * add spanish translation on login page * add spanish translation on upload page * Add spanish translations for explore page * Add translations on user page * Add translations for config page * Add spanish translations on chat page * add translations for brain page * fix GUI and save on local storage * fix (i18n) init and types * fix (i18n): typos * add translation on new brain modal * add translations on metadata * Add translations on home page * fixes types * fix(frontend-tests): use get by id instead of text --------- Co-authored-by: Gustavo Maciel <gustavo_m13@outlook.com>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { usePathname } from "next/navigation";
|
|
import { useEffect, useState } from "react";
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { useChatApi } from "@/lib/api/chat/useChatApi";
|
|
import { useChatsContext } from "@/lib/context/ChatsProvider/hooks/useChatsContext";
|
|
import { useToast } from "@/lib/hooks";
|
|
import { useDevice } from "@/lib/hooks/useDevice";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useChatsList = () => {
|
|
const { isMobile } = useDevice();
|
|
const [open, setOpen] = useState(!isMobile);
|
|
const { t } = useTranslation(['chat']);
|
|
|
|
const pathname = usePathname();
|
|
|
|
const { setAllChats } = useChatsContext();
|
|
const { publish } = useToast();
|
|
const { getChats } = useChatApi();
|
|
|
|
useEffect(() => {
|
|
const fetchAllChats = async () => {
|
|
try {
|
|
const response = await getChats();
|
|
setAllChats(response.reverse());
|
|
} catch (error) {
|
|
console.error(error);
|
|
publish({
|
|
variant: "danger",
|
|
text: t("errorFetching",{ ns : 'chat'})
|
|
});
|
|
}
|
|
};
|
|
void fetchAllChats();
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
setOpen(!isMobile);
|
|
}, [isMobile, pathname]);
|
|
|
|
return {
|
|
open,
|
|
setOpen,
|
|
};
|
|
};
|