@solid-data-modules/bookmarks-soukai
v0.0.3
Published
See [Docs](https://solid-contrib.github.io/data-modules/bookmarks-soukai/index.html) for more information about this module.
Downloads
5
Readme
Bookmarks Data Module for Soukai
See Docs for more information about this module.
Development
Make sure you have node v. 20.10.0 installed.
git clone https://github.com/solid-contrib/data-modules
cd data-modules
cd bookmarks/soukai
npm install
npm run test
Demo app
Assuming you just ran the 'development' steps above and are now in the bookmarks/soukai folder.
npm run build
cd demo
npm install
npm run dev
Explanation of the demo app
First of all, the login and booting is handled by src/utils.js
.
Once up and running, the demo app instantiates the BookmarkFactory inside a React useEffect
callback. After that, it simply calls factory.getAll()
to retrieve all bookmarks that are discoverable through
the private type index on the Solid pod of the currently authenticated user. The setBookmarks(bookmarks)
call hands the fetched items over to React.
The factory.get
and factory.remove
functions take the url
of a bookmark as the primary key.
And factory.create
takes an object with three string fields: label
, topic
and link
.
And finally there is factory.update
which takes the url
as a primary key, and then an object with the same three string fields as the second argument.
Boot Engine
bootSolidModels();
bootModels({ Bookmark: Bookmark });
get Factory instance (it's a singleton)
const factory = await BookmarkFactory.getInstance(
{
webId: userSession?.info.webId,
fetch: userSession?.fetch,
isPrivate: true,
},
"bookmarks/" // you can optionally pass a path to override typeRegistration
);
use factory instance to CRUD over bookmarks
const bookmarks = await bookmarkFactory.getAll();
const bookmark = await bookmarkFactory.get("<pk>");
const bookmark = await bookmarkFactory.create({ label: "example", link: "https://example.com", hasTopic: "Topic" });
const bookmark = await bookmarkFactory.remove("<pk>");
const bookmark = await bookmarkFactory.update("<pk>", { label: "example", link: "https://example.com", hasTopic: "Topic" });