mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-19 12:21:46 +03:00
0cc917ea9e
Issue: https://github.com/StanGirard/quivr/issues/1884 - Add new sidebar (Menu) - Add Menu to App level (shared accross all pages) and display it only on chat bar - Remove chatlist from sidebar (they are now accessible through Actions bar (plus button on right of chat input) - Move notification banner to App.tsx - Update translations Demo: https://github.com/StanGirard/quivr/assets/63923024/53b1bf3b-db1a-49d7-ae84-80423d66ec03
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { useCallback, useEffect, useState } from "react";
|
|
|
|
import { NOTIFICATION_BANNER_DATA_KEY } from "@/lib/api/cms/config";
|
|
import { useCmsApi } from "@/lib/api/cms/useCmsApi";
|
|
|
|
import {
|
|
clearLocalStorageNotificationBanner,
|
|
getNotificationFromLocalStorage,
|
|
setNotificationAsDismissedInLocalStorage,
|
|
} from "../utils";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useNotificationBanner = () => {
|
|
const [isDismissed, setIsDismissed] = useState(true);
|
|
|
|
const { getNotificationBanner } = useCmsApi();
|
|
const { data: notificationBanner } = useQuery({
|
|
queryKey: [NOTIFICATION_BANNER_DATA_KEY],
|
|
queryFn: getNotificationBanner,
|
|
});
|
|
|
|
const dismissNotification = useCallback(() => {
|
|
if (notificationBanner?.id === undefined) {
|
|
return;
|
|
}
|
|
setNotificationAsDismissedInLocalStorage(notificationBanner.id);
|
|
setIsDismissed(true);
|
|
}, [notificationBanner?.id]);
|
|
|
|
useEffect(() => {
|
|
const localStorageNotificationBanner = getNotificationFromLocalStorage();
|
|
if (notificationBanner === undefined) {
|
|
return;
|
|
}
|
|
if (localStorageNotificationBanner?.id !== notificationBanner.id) {
|
|
clearLocalStorageNotificationBanner();
|
|
setIsDismissed(false);
|
|
}
|
|
}, [dismissNotification, notificationBanner?.id]);
|
|
|
|
useEffect(() => {
|
|
const onUnmount = () => {
|
|
if (notificationBanner?.isSticky === undefined) {
|
|
return;
|
|
}
|
|
if (!notificationBanner.isSticky) {
|
|
dismissNotification();
|
|
}
|
|
};
|
|
|
|
return onUnmount;
|
|
}, [dismissNotification, notificationBanner?.isSticky]);
|
|
|
|
return {
|
|
notificationBanner,
|
|
dismissNotification,
|
|
isDismissed,
|
|
};
|
|
};
|