bookmark.ts 524 B

123456789101112131415
  1. import useSWR, { SWRResponse } from 'swr';
  2. import { apiv3Get } from '../client/util/apiv3-client';
  3. import { IBookmarkInfo } from '../interfaces/bookmark-info';
  4. export const useSWRBookmarkInfo = (pageId: string | null): SWRResponse<IBookmarkInfo, Error> => {
  5. return useSWR(pageId != null
  6. ? `/bookmarks/info?pageId=${pageId}` : null,
  7. endpoint => apiv3Get(endpoint).then((response) => {
  8. return {
  9. sumOfBookmarks: response.data.sumOfBookmarks,
  10. isBookmarked: response.data.isBookmarked,
  11. };
  12. }));
  13. };