Skip to content

Commit

Permalink
works, but needs reviewing (where to instantiate Api): Use @plone/vol…
Browse files Browse the repository at this point in the history
…to/helpers/Api to fetch.
  • Loading branch information
ksuess committed Feb 8, 2025
1 parent 36326c7 commit 7caeb18
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions packages/volto-bookmarks/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Bookmark actions
*/

import Api from '@plone/volto/helpers/Api/Api';
import { sortQuerystring } from '../helpers';

import config from '@plone/volto/registry';

function getApiPath() {
function _getApiPath() {
const { settings } = config;
const apiSuffix = settings.legacyTraverse ? '' : '/++api++';
const apiPath = settings.internalApiPath ?? settings.apiPath;
Expand All @@ -28,20 +28,17 @@ export async function addBookmark(
querystring = null,
payload = {},
) {
const myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json');

const response = await fetch(`${getApiPath()}/@bookmark`, {
method: 'POST',
body: JSON.stringify({
const api = new Api();
const path = `${_getApiPath()}/@bookmark`;
const result = await api['post'](path, {
data: {
uid,
group,
queryparams: sortQuerystring(querystring),
payload,
}),
headers: myHeaders,
},
});
return response;
return result;
}

/**
Expand All @@ -51,29 +48,26 @@ export async function addBookmark(
* @param {Object} queryObjectStringified
*/
export async function deleteBookmark(uid, group, querystring = null) {
const myHeaders = new Headers();
myHeaders.append('Accept', 'application/json');
myHeaders.append('Content-Type', 'application/json');

const response = await fetch(`${getApiPath()}/@bookmark`, {
method: 'DELETE',
body: JSON.stringify({
const api = new Api();
const path = `${_getApiPath()}/@bookmark`;
const result = await api['del'](path, {
data: {
uid,
group,
queryparams: sortQuerystring(querystring),
}),
headers: myHeaders,
},
});
return response;
return result;
}

/**
* getBookmarks
* Get list of bookmarks
* @param {string} group
*/
export async function getBookmarks(group) {
const response = await fetch(
`${getApiPath()}/@bookmarks` + (group ? `?group=${group}` : ``),
);
return response;
const api = new Api();
const path = `${_getApiPath()}/@bookmarks` + (group ? `?group=${group}` : ``);
const result = await api['get'](path);
return result;
}

0 comments on commit 7caeb18

Please sign in to comment.