Skip to content

Commit 81ccd3c

Browse files
authored
Searchbar fix (#158)
* Making the search persistent again... * Removing the debug model access * Make a hacky fix * only use cache on startup * and one one more hacky fix
1 parent 15b4616 commit 81ccd3c

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

my-app/firebase.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,18 @@ export async function connectToFirebase(model) {
5555
// setting missing
5656
// also save filters to local storage
5757
//
58-
const options = JSON.parse(localStorage.getItem("filterOptions"));
59-
if (options) {
60-
model.setFilterOptions(options);
61-
}
62-
if (!model?.currentSearchText) {
63-
const search = localStorage.getItem("search");
64-
if (search) {
65-
model.setCurrentSearchText(search);
66-
}
58+
// we dont restore for the expo...
59+
//
60+
// const options = JSON.parse(localStorage.getItem("filterOptions"));
61+
// if (options) {
62+
// model.setFilterOptions(options);
63+
// }
64+
const search = localStorage.getItem("search");
65+
if (search) {
66+
model.setCurrentSearchText(search);
6767
}
6868

6969
// automaticaly save filter and search to local storage whenever they change
70-
reaction(
71-
() => ({
72-
filterOptions: JSON.stringify(model.filterOptions),
73-
search: model.currentSearchText,
74-
}),
75-
({ filterOptions, search }) => {
76-
localStorage.setItem("filterOptions", filterOptions);
77-
localStorage.setItem("search", search);
78-
}
79-
);
8070
/**
8171
* Hook to start synchronization when user is authenticated.
8272
*/
@@ -91,6 +81,16 @@ export async function connectToFirebase(model) {
9181
model.setReady();
9282
}
9383
});
84+
reaction(
85+
() => ({
86+
filterOptions: JSON.stringify(model.filterOptions),
87+
search: model.currentSearchText,
88+
}),
89+
({ filterOptions, search }) => {
90+
localStorage.setItem("filterOptions", filterOptions);
91+
localStorage.setItem("search", search);
92+
}
93+
);
9494
}
9595

9696
// fetches all relevant information to create the model
@@ -104,8 +104,8 @@ async function firebaseToModel(model) {
104104
await runTransaction(userRef, (currentData) => {
105105
if (currentData) {
106106
if (data?.favourites) model.setFavourite(data.favourites);
107-
if (data?.currentSearchText)
108-
model.setCurrentSearchText(data.currentSearchText);
107+
// if (data?.currentSearchText)
108+
// model.setCurrentSearchText(data.currentSearchText);
109109
// Add other fields as needed
110110
}
111111
return currentData; // Return the current data to avoid overwriting
@@ -123,7 +123,7 @@ export function syncModelToFirebase(model) {
123123
() => ({
124124
userId: model?.user.uid,
125125
favourites: toJS(model.favourites),
126-
currentSearchText: toJS(model.currentSearchText),
126+
//currentSearchText: toJS(model.currentSearchText),
127127
}),
128128
async ({ userId, favourites, currentSearchText }) => {
129129
if (!userId) return;
@@ -134,7 +134,7 @@ export function syncModelToFirebase(model) {
134134
return {
135135
...currentData,
136136
favourites,
137-
currentSearchText,
137+
//currentSearchText,
138138
};
139139
}).catch((error) => {
140140
console.error("Error syncing model to Firebase:", error);

my-app/src/index.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import App from "./pages/App.jsx";
77
import "./styles.css";
88

99
import SharedView from "./pages/SharedView.jsx";
10-
import { JsonToDatabase } from "./presenters/Tests/JsonToDatabase";
11-
import { AllCoursesPresenter } from "./presenters/Tests/AllCoursesPresenter.jsx";
1210

1311

1412
configure({ enforceActions: "never", reactionScheduler: (f) => setTimeout(f, 0),});

my-app/src/pages/App.jsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ import { slide as Menu } from "react-burger-menu";
1515
function App({ model }) {
1616
const [sidebarIsOpen, setSidebarIsOpen] = useState(model.sidebarIsOpen);
1717

18-
useEffect(() => {
19-
const clearStorageOnUnload = () => {
20-
localStorage.removeItem("filterOptions");
21-
};
22-
23-
// window.addEventListener("unload", clearStorageOnUnload);
24-
25-
return () => {
26-
window.removeEventListener("unload", clearStorageOnUnload);
27-
};
28-
}, []);
29-
3018
useState(() => {
3119
if (window.innerWidth < 700) {
3220
setSidebarIsOpen(false);

0 commit comments

Comments
 (0)