diff --git a/my-app/firebase.js b/my-app/firebase.js index c48d595..3e018b2 100644 --- a/my-app/firebase.js +++ b/my-app/firebase.js @@ -55,28 +55,18 @@ export async function connectToFirebase(model) { // setting missing // also save filters to local storage // - const options = JSON.parse(localStorage.getItem("filterOptions")); - if (options) { - model.setFilterOptions(options); - } - if (!model?.currentSearchText) { - const search = localStorage.getItem("search"); - if (search) { - model.setCurrentSearchText(search); - } + // we dont restore for the expo... + // + // const options = JSON.parse(localStorage.getItem("filterOptions")); + // if (options) { + // model.setFilterOptions(options); + // } + const search = localStorage.getItem("search"); + if (search) { + model.setCurrentSearchText(search); } // automaticaly save filter and search to local storage whenever they change - reaction( - () => ({ - filterOptions: JSON.stringify(model.filterOptions), - search: model.currentSearchText, - }), - ({ filterOptions, search }) => { - localStorage.setItem("filterOptions", filterOptions); - localStorage.setItem("search", search); - } - ); /** * Hook to start synchronization when user is authenticated. */ @@ -91,6 +81,16 @@ export async function connectToFirebase(model) { model.setReady(); } }); + reaction( + () => ({ + filterOptions: JSON.stringify(model.filterOptions), + search: model.currentSearchText, + }), + ({ filterOptions, search }) => { + localStorage.setItem("filterOptions", filterOptions); + localStorage.setItem("search", search); + } + ); } // fetches all relevant information to create the model @@ -104,8 +104,8 @@ async function firebaseToModel(model) { await runTransaction(userRef, (currentData) => { if (currentData) { if (data?.favourites) model.setFavourite(data.favourites); - if (data?.currentSearchText) - model.setCurrentSearchText(data.currentSearchText); + // if (data?.currentSearchText) + // model.setCurrentSearchText(data.currentSearchText); // Add other fields as needed } return currentData; // Return the current data to avoid overwriting @@ -123,7 +123,7 @@ export function syncModelToFirebase(model) { () => ({ userId: model?.user.uid, favourites: toJS(model.favourites), - currentSearchText: toJS(model.currentSearchText), + //currentSearchText: toJS(model.currentSearchText), }), async ({ userId, favourites, currentSearchText }) => { if (!userId) return; @@ -134,7 +134,7 @@ export function syncModelToFirebase(model) { return { ...currentData, favourites, - currentSearchText, + //currentSearchText, }; }).catch((error) => { console.error("Error syncing model to Firebase:", error); diff --git a/my-app/src/index.jsx b/my-app/src/index.jsx index e3a866c..eea708a 100644 --- a/my-app/src/index.jsx +++ b/my-app/src/index.jsx @@ -7,8 +7,6 @@ import App from "./pages/App.jsx"; import "./styles.css"; import SharedView from "./pages/SharedView.jsx"; -import { JsonToDatabase } from "./presenters/Tests/JsonToDatabase"; -import { AllCoursesPresenter } from "./presenters/Tests/AllCoursesPresenter.jsx"; configure({ enforceActions: "never", reactionScheduler: (f) => setTimeout(f, 0),}); diff --git a/my-app/src/pages/App.jsx b/my-app/src/pages/App.jsx index bd75350..2212474 100644 --- a/my-app/src/pages/App.jsx +++ b/my-app/src/pages/App.jsx @@ -15,18 +15,6 @@ import { slide as Menu } from "react-burger-menu"; function App({ model }) { const [sidebarIsOpen, setSidebarIsOpen] = useState(model.sidebarIsOpen); - useEffect(() => { - const clearStorageOnUnload = () => { - localStorage.removeItem("filterOptions"); - }; - - // window.addEventListener("unload", clearStorageOnUnload); - - return () => { - window.removeEventListener("unload", clearStorageOnUnload); - }; - }, []); - useState(() => { if (window.innerWidth < 700) { setSidebarIsOpen(false);