Skip to content

Commit 7e7fd55

Browse files
authored
Making the search persistent again... (#154)
1 parent e82e5f9 commit 7e7fd55

File tree

6 files changed

+414
-390
lines changed

6 files changed

+414
-390
lines changed

my-app/firebase.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,20 @@ export async function connectToFirebase(model) {
5656
// also save filters to local storage
5757
//
5858
const options = JSON.parse(localStorage.getItem("filterOptions"));
59+
const search = localStorage.getItem("search");
5960
if (options) {
6061
model.setFilterOptions(options);
6162
}
63+
if(search){
64+
model.setCurrentSearchText(search);
65+
}
6266

63-
// automaticaly save filter options to local storage whenever they change
67+
// automaticaly save filter and search to local storage whenever they change
6468
reaction(
65-
() => ({ filterOptions: JSON.stringify(model.filterOptions) }),
66-
({ filterOptions }) => {
69+
() => ({ filterOptions: JSON.stringify(model.filterOptions), search: model.currentSearchText }),
70+
({ filterOptions, search }) => {
6771
localStorage.setItem("filterOptions", filterOptions);
72+
localStorage.setItem("search", search);
6873
}
6974
);
7075
/**
@@ -78,8 +83,10 @@ export async function connectToFirebase(model) {
7883
syncScrollPositionToFirebase(model);
7984
} else {
8085
model.setUser(null); // If no user, clear user-specific data
86+
model.setReady();
8187
}
8288
});
89+
8390
}
8491

8592
// fetches all relevant information to create the model
@@ -100,6 +107,7 @@ async function firebaseToModel(model) {
100107
return currentData; // Return the current data to avoid overwriting
101108
});
102109
});
110+
model.setReady();
103111
}
104112

105113
/**

my-app/src/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ createRoot(document.getElementById("root")).render(
4444
<RouterProvider router={makeRouter(reactiveModel)} />
4545
);
4646
// give user access for debugging purpose
47-
// window.myModel = reactiveModel;
47+
window.myModel = reactiveModel;

0 commit comments

Comments
 (0)