mirror of https://github.com/usememos/memos
chore: update memo filter styles
parent
cd38ec93ed
commit
c6a09d9353
@ -1,52 +0,0 @@
|
|||||||
import { Visibility } from "@/types/proto/api/v1/memo_service";
|
|
||||||
import store, { useAppSelector } from "..";
|
|
||||||
import { MemoPropertyFilter, setFilter, setMemoPropertyFilter } from "../reducer/filter";
|
|
||||||
|
|
||||||
export const useFilterStore = () => {
|
|
||||||
const state = useAppSelector((state) => state.filter);
|
|
||||||
|
|
||||||
return {
|
|
||||||
state,
|
|
||||||
getState: () => {
|
|
||||||
return store.getState().filter;
|
|
||||||
},
|
|
||||||
clearFilter: () => {
|
|
||||||
store.dispatch(
|
|
||||||
setFilter({
|
|
||||||
tag: undefined,
|
|
||||||
text: undefined,
|
|
||||||
visibility: undefined,
|
|
||||||
memoPropertyFilter: undefined,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
setTextFilter: (text?: string) => {
|
|
||||||
store.dispatch(
|
|
||||||
setFilter({
|
|
||||||
text: text,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
setTagFilter: (tag?: string) => {
|
|
||||||
store.dispatch(
|
|
||||||
setFilter({
|
|
||||||
tag: tag,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
setMemoVisibilityFilter: (visibility?: Visibility) => {
|
|
||||||
store.dispatch(
|
|
||||||
setFilter({
|
|
||||||
visibility: visibility,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
setMemoPropertyFilter: (memoPropertyFilter: Partial<MemoPropertyFilter>) => {
|
|
||||||
store.dispatch(
|
|
||||||
setMemoPropertyFilter({
|
|
||||||
...memoPropertyFilter,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
@ -1,2 +1 @@
|
|||||||
export * from "./filter";
|
|
||||||
export * from "./dialog";
|
export * from "./dialog";
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
||||||
import { Visibility } from "@/types/proto/api/v1/memo_service";
|
|
||||||
|
|
||||||
interface State {
|
|
||||||
tag?: string;
|
|
||||||
text?: string;
|
|
||||||
visibility?: Visibility;
|
|
||||||
memoPropertyFilter?: MemoPropertyFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MemoPropertyFilter {
|
|
||||||
hasLink?: boolean;
|
|
||||||
hasTaskList?: boolean;
|
|
||||||
hasCode?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
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: getInitialState(),
|
|
||||||
reducers: {
|
|
||||||
setFilter: (state, action: PayloadAction<Partial<State>>) => {
|
|
||||||
if (JSON.stringify(action.payload) === state) {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
...action.payload,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
setMemoPropertyFilter: (state, action: PayloadAction<Partial<MemoPropertyFilter>>) => {
|
|
||||||
if (JSON.stringify(action.payload) === state.memoPropertyFilter) {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
memoPropertyFilter: {
|
|
||||||
...state.memoPropertyFilter,
|
|
||||||
...action.payload,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const { setFilter, setMemoPropertyFilter } = filterSlice.actions;
|
|
||||||
|
|
||||||
export default filterSlice.reducer;
|
|
@ -1,47 +0,0 @@
|
|||||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
||||||
import { uniqBy } from "lodash-es";
|
|
||||||
import { Resource } from "@/types/proto/api/v1/resource_service";
|
|
||||||
|
|
||||||
interface State {
|
|
||||||
resources: Resource[];
|
|
||||||
}
|
|
||||||
|
|
||||||
const resourceSlice = createSlice({
|
|
||||||
name: "resource",
|
|
||||||
initialState: {
|
|
||||||
resources: [],
|
|
||||||
} as State,
|
|
||||||
reducers: {
|
|
||||||
setResources: (state, action: PayloadAction<Resource[]>) => {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
resources: action.payload,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
upsertResources: (state, action: PayloadAction<Resource[]>) => {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
resources: uniqBy([...action.payload, ...state.resources], "name"),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
patchResource: (state, action: PayloadAction<Partial<Resource>>) => {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
resources: state.resources.map((resource) => {
|
|
||||||
if (resource.name === action.payload.name) {
|
|
||||||
return {
|
|
||||||
...resource,
|
|
||||||
...action.payload,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const { setResources, upsertResources, patchResource } = resourceSlice.actions;
|
|
||||||
|
|
||||||
export default resourceSlice.reducer;
|
|
Loading…
Reference in New Issue