diff --git a/src/shared/layouts/SidenavLayout/components/SidenavContent/components/UserInfo/components/MenuItems/MenuItems.tsx b/src/shared/layouts/SidenavLayout/components/SidenavContent/components/UserInfo/components/MenuItems/MenuItems.tsx index e86ada241..01c4bf85e 100644 --- a/src/shared/layouts/SidenavLayout/components/SidenavContent/components/UserInfo/components/MenuItems/MenuItems.tsx +++ b/src/shared/layouts/SidenavLayout/components/SidenavContent/components/UserInfo/components/MenuItems/MenuItems.tsx @@ -4,19 +4,15 @@ import { useLocation } from "react-router"; import classNames from "classnames"; import { Menu } from "@headlessui/react"; import { logOut } from "@/pages/Auth/store/actions"; -import { FeatureFlags } from "@/shared/constants"; import { useRoutesContext } from "@/shared/contexts"; -import { useFeatureFlag } from "@/shared/hooks/useFeatureFlag"; import { Avatar3Icon, BillingIcon, LogoutIcon, NotificationsIcon, } from "@/shared/icons"; -import ReportIcon from "@/shared/icons/report.icon"; import ThemeIcon from "@/shared/icons/theme.icon"; import { toggleTheme } from "@/shared/store/actions"; -import { clearFirestoreCache } from "@/shared/utils/firebase"; import { MenuItem } from "./components"; import { Item, ItemType } from "./types"; import styles from "./MenuItems.module.scss"; @@ -47,9 +43,6 @@ const MenuItems: FC = (props) => { const { pathname } = useLocation(); const isV04 = pathname.includes("-v04"); - const featureFlags = useFeatureFlag(); - const isHavingAnIssueEnabled = featureFlags?.get(FeatureFlags.HavingAnIssue); - const toggleThemeMenuItem = { key: "theme", type: ItemType.Button, @@ -93,20 +86,8 @@ const MenuItems: FC = (props) => { }, ]; - if (isHavingAnIssueEnabled) { - menuItems.push({ - key: "issue", - text: "Having an issue?", - icon: , - type: ItemType.Button, - onClick: () => { - clearFirestoreCache(); - }, - }); - } - return menuItems; - }, [isHavingAnIssueEnabled, isV04, toggleThemeMenuItem]); + }, [isV04, toggleThemeMenuItem]); return ( diff --git a/src/shared/utils/firebase.tsx b/src/shared/utils/firebase.tsx index 675511068..8e6d7f50f 100644 --- a/src/shared/utils/firebase.tsx +++ b/src/shared/utils/firebase.tsx @@ -9,79 +9,11 @@ import { local } from "@/config"; import { Environment, REACT_APP_ENV } from "@/shared/constants"; import config from "../../config"; -const CACHE_SIZE_LIMIT = 104857600; // 100 MB - interface FirebaseError extends Error { code: string; } const app = firebase.initializeApp(config.firebase); -let db = firebase.firestore(); - -enableUnlimitedCachePersistence(); -// Function to handle Firestore persistence errors -function handlePersistenceError(err: any) { - if (err.code === "failed-precondition") { - console.log("Multiple tabs open or other conflict."); - } else if (err.code === "unimplemented") { - console.log("Persistence is not supported in this browser."); - } else if (err.name === "QuotaExceededError") { - console.log("Storage quota exceeded. Consider clearing cache."); - clearFirestoreCache(); - } else { - console.error("Error enabling persistence:", err); - reinitializeFirestoreWithPersistence(); - } -} - -function reinitializeFirestoreWithPersistence() { - db = firebase.firestore(); // Reinitialize Firestore instance - const settings = { cacheSizeBytes: CACHE_SIZE_LIMIT }; - db.settings(settings); - - db.enablePersistence({ synchronizeTabs: true }) - .then(() => { - console.log("Persistence re-enabled."); - return; - }) - .catch(handlePersistenceError); -} - -// Function to clear Firestore cache and re-enable persistence -export function clearFirestoreCache() { - db.terminate() - .then(() => { - console.log("Firestore instance terminated."); - return db.clearPersistence(); // Safe to clear persistence now - }) - .then(() => { - console.log("Persistence cleared. Waiting before reinitializing..."); - return new Promise((resolve) => setTimeout(resolve, 2000)); // Wait 2 second - }) - .then(() => { - console.log("Cache cleared successfully."); - reinitializeFirestoreWithPersistence(); // Reinitialize Firestore - window.location.reload(); - return; - }) - .catch((err) => { - if (err.code === "failed-precondition") { - console.log("Cannot clear persistence: Firestore is still running."); - } else { - console.error("Error clearing persistence cache:", err); - } - }); -} - -// Enable Firestore persistence with unlimited cache size and error handling -function enableUnlimitedCachePersistence() { - const settings = { - cacheSizeBytes: CACHE_SIZE_LIMIT, - }; - db.settings(settings); - - db.enablePersistence({ synchronizeTabs: true }).catch(handlePersistenceError); -} // Enable persistence in the local environment (with Firestore and Auth emulators) if (REACT_APP_ENV === Environment.Local) {