generated from rohberg/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from collective/bookmarking-in-listings
Bookmarking in listings. Jotai instead of actions and redux.
- Loading branch information
Showing
23 changed files
with
5,492 additions
and
1,191 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
"package": "@plone/volto", | ||
"url": "[email protected]:plone/volto.git", | ||
"https": "https://github.com/plone/volto.git", | ||
"tag": "18.4.0" | ||
"tag": "18.8.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Bookmarking in listing and search block. @ksuess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
// https://github.com/ipenywis/redux-alternatives/blob/main/src/libraries/jotai.tsx#L27 | ||
import { atom } from 'jotai'; | ||
import { getBookmarks } from './actions'; | ||
|
||
// Jotai store for bookmarks of the current user | ||
export const allBookmarksAtom = atom({ items_total: 0, items: [] }); | ||
const bookmarksAtom = atom(null); | ||
|
||
export const fetchBookmarksAtom = atom( | ||
(get) => get(bookmarksAtom), | ||
async (get, set, value) => { | ||
if (value === null) { | ||
set(bookmarksAtom, null); | ||
} else { | ||
const result = await getBookmarks(value); | ||
set(bookmarksAtom, { | ||
items: result || [], | ||
items_total: (result || []).length, | ||
}); | ||
} | ||
}, | ||
); | ||
|
||
export const searchkitQueryAtom = atom(null); |
23 changes: 14 additions & 9 deletions
23
packages/volto-bookmarks/src/components/AppExtrasBookmarking.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
import React from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import React, { useEffect } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useSetAtom } from 'jotai'; | ||
import { fetchBookmarksAtom } from '@plone-collective/volto-bookmarks/atoms'; | ||
|
||
import { getAllBookmarks } from '@plone-collective/volto-bookmarks/actions'; | ||
const AppExtrasBookmarking = () => { | ||
const fetchBookmarks = useSetAtom(fetchBookmarksAtom); | ||
|
||
const FooComponent = () => { | ||
const token = useSelector((state) => state.userSession.token); | ||
const dispatch = useDispatch(); | ||
|
||
React.useEffect(() => { | ||
dispatch(getAllBookmarks()); | ||
}, [dispatch, token]); | ||
useEffect(() => { | ||
if (token) { | ||
fetchBookmarks(); | ||
} else { | ||
fetchBookmarks(null); | ||
} | ||
}, [fetchBookmarks, token]); | ||
|
||
return <React.Fragment></React.Fragment>; | ||
}; | ||
|
||
export default FooComponent; | ||
export default AppExtrasBookmarking; |
Oops, something went wrong.