|
|
|
@ -11,25 +11,37 @@ const shortcutSlice = createSlice({
|
|
|
|
|
} as State,
|
|
|
|
|
reducers: {
|
|
|
|
|
setShortcuts: (state, action: PayloadAction<Shortcut[]>) => {
|
|
|
|
|
state.shortcuts = action.payload;
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
shortcuts: action.payload,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
createShortcut: (state, action: PayloadAction<Shortcut>) => {
|
|
|
|
|
state.shortcuts = state.shortcuts.concat(action.payload);
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
shortcuts: state.shortcuts.concat(action.payload).sort((a, b) => b.createdTs - a.createdTs),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
patchShortcut: (state, action: PayloadAction<Partial<Shortcut>>) => {
|
|
|
|
|
state.shortcuts = state.shortcuts.map((s) => {
|
|
|
|
|
if (s.id === action.payload.id) {
|
|
|
|
|
return {
|
|
|
|
|
...s,
|
|
|
|
|
...action.payload,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
shortcuts: state.shortcuts.map((s) => {
|
|
|
|
|
if (s.id === action.payload.id) {
|
|
|
|
|
return {
|
|
|
|
|
...s,
|
|
|
|
|
...action.payload,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
deleteShortcut: (state, action: PayloadAction<ShortcutId>) => {
|
|
|
|
|
state.shortcuts = [...state.shortcuts].filter((shortcut) => shortcut.id !== action.payload);
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
shortcuts: [...state.shortcuts].filter((shortcut) => shortcut.id !== action.payload),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|