Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: fix filter initial state

Steven374f3f7d9684
diff --git a/web/src/store/module/filter.ts b/web/src/store/module/filter.ts
index 0fc1847f2..e07d3ab09 100644
--- a/web/src/store/module/filter.ts
+++ b/web/src/store/module/filter.ts
@@ -1,5 +1,5 @@
import store, { useAppSelector } from "..";
-import { Filter, setFilter } from "../reducer/filter";
+import { setFilter } from "../reducer/filter";
export const useFilterStore = () => {
const state = useAppSelector((state) => state.filter);
@@ -9,9 +9,6 @@ export const useFilterStore = () => {
getState: () => {
return store.getState().filter;
},
- setFilter: (filter: Filter) => {
- store.dispatch(setFilter(filter));
- },
clearFilter: () => {
store.dispatch(
setFilter({
diff --git a/web/src/store/reducer/filter.ts b/web/src/store/reducer/filter.ts
index bb4ab3e98..af8c23238 100644
--- a/web/src/store/reducer/filter.ts
+++ b/web/src/store/reducer/filter.ts
@@ -8,9 +8,23 @@ interface State {
export type Filter = State;
+const getInitialState = (): State => {
+ const state: State = {};
+ const urlParams = new URLSearchParams(location.search);
+ const tag = urlParams.get("tag");
+ const text = urlParams.get("text");
+ if (tag) {
+ state.tag = tag;
+ }
+ if (text) {
+ state.text = text;
+ }
+ return state;
+};
+
const filterSlice = createSlice({
name: "filter",
- initialState: {} as State,
+ initialState: getInitialState(),
reducers: {
setFilter: (state, action: PayloadAction<Partial<State>>) => {
if (JSON.stringify(action.payload) === state) {