bookmark-utils.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import type { IRevision, Ref } from '@growi/core';
  2. import type { BookmarkFolderItems, BookmarkedPage } from '~/interfaces/bookmark-info';
  3. import { apiv3Delete, apiv3Post, apiv3Put } from './apiv3-client';
  4. // Check if bookmark folder item has children or bookmarks
  5. export const hasChildren = ({ children, bookmarks }: { children?: BookmarkFolderItems[], bookmarks?: BookmarkedPage[] }): boolean => {
  6. return !!((children && children.length > 0) || (bookmarks && bookmarks.length > 0));
  7. };
  8. // Add new folder helper
  9. export const addNewFolder = async(name: string, parent: string | null): Promise<void> => {
  10. await apiv3Post('/bookmark-folder', { name, parent });
  11. };
  12. // Put bookmark to a folder
  13. export const addBookmarkToFolder = async(pageId: string, folderId: string | null): Promise<void> => {
  14. await apiv3Post('/bookmark-folder/add-boookmark-to-folder', { pageId, folderId });
  15. };
  16. // Delete bookmark folder
  17. export const deleteBookmarkFolder = async(bookmarkFolderId: string): Promise<void> => {
  18. await apiv3Delete(`/bookmark-folder/${bookmarkFolderId}`);
  19. };
  20. // Rename page from bookmark item control
  21. export const renamePage = async(pageId: string, revisionId: Ref<IRevision> | undefined, newPagePath: string): Promise<void> => {
  22. await apiv3Put('/pages/rename', { pageId, revisionId, newPagePath });
  23. };
  24. // Update bookmark by isBookmarked status
  25. export const toggleBookmark = async(pageId: string, status: boolean): Promise<void> => {
  26. await apiv3Put('/bookmark-folder/update-bookmark', { pageId, status });
  27. };
  28. // Update Bookmark folder
  29. export const updateBookmarkFolder = async(bookmarkFolderId: string, name: string, parent: string | null, children: BookmarkFolderItems[]): Promise<void> => {
  30. await apiv3Put('/bookmark-folder', {
  31. bookmarkFolderId, name, parent, children,
  32. });
  33. };