Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions my-app/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,20 @@ export async function connectToFirebase(model) {
// also save filters to local storage
//
const options = JSON.parse(localStorage.getItem("filterOptions"));
const search = localStorage.getItem("search");
if (options) {
model.setFilterOptions(options);
}
if(search){
model.setCurrentSearchText(search);
}

// automaticaly save filter options to local storage whenever they change
// automaticaly save filter and search to local storage whenever they change
reaction(
() => ({ filterOptions: JSON.stringify(model.filterOptions) }),
({ filterOptions }) => {
() => ({ filterOptions: JSON.stringify(model.filterOptions), search: model.currentSearchText }),
({ filterOptions, search }) => {
localStorage.setItem("filterOptions", filterOptions);
localStorage.setItem("search", search);
}
);
/**
Expand All @@ -78,8 +83,10 @@ export async function connectToFirebase(model) {
syncScrollPositionToFirebase(model);
} else {
model.setUser(null); // If no user, clear user-specific data
model.setReady();
}
});

}

// fetches all relevant information to create the model
Expand All @@ -100,6 +107,7 @@ async function firebaseToModel(model) {
return currentData; // Return the current data to avoid overwriting
});
});
model.setReady();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion my-app/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ createRoot(document.getElementById("root")).render(
<RouterProvider router={makeRouter(reactiveModel)} />
);
// give user access for debugging purpose
// window.myModel = reactiveModel;
window.myModel = reactiveModel;
Loading