mirror of
https://github.com/responsively-org/responsively-app
synced 2024-11-10 14:54:12 +00:00
feat: rename the bookmark w/o creation of copies
This commit is contained in:
parent
ffb83c07bf
commit
fff8a5db27
1 changed files with 13 additions and 6 deletions
|
@ -22,18 +22,25 @@ export const bookmarksSlice = createSlice({
|
|||
reducers: {
|
||||
addBookmark: (state, action: PayloadAction<IBookmarks>) => {
|
||||
const bookmarks: IBookmarks[] = window.electron.store.get('bookmarks');
|
||||
const updatedPayload = {
|
||||
id: uuidv4(),
|
||||
...action.payload,
|
||||
};
|
||||
bookmarks.push(updatedPayload);
|
||||
if (action.payload.id) {
|
||||
const index = bookmarks.findIndex(
|
||||
(bookmark) => bookmark.id === action.payload.id
|
||||
);
|
||||
bookmarks[index] = action.payload;
|
||||
} else {
|
||||
const updatedPayload = {
|
||||
...action.payload,
|
||||
id: uuidv4(),
|
||||
};
|
||||
bookmarks.push(updatedPayload);
|
||||
}
|
||||
state.bookmarks = bookmarks;
|
||||
window.electron.store.set('bookmarks', bookmarks);
|
||||
},
|
||||
removeBookmark: (state, action) => {
|
||||
const bookmarks = window.electron.store.get('bookmarks');
|
||||
const bookmarkIndex = state.bookmarks.findIndex(
|
||||
(bookmark) => bookmark.address === action.payload.address
|
||||
(bookmark) => bookmark.id === action.payload.id
|
||||
);
|
||||
if (bookmarkIndex === -1) {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue