bookmark-utils.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 childFolder or bookmarks
  5. export const hasChildren = ({ childFolder, bookmarks }: { childFolder?: BookmarkFolderItems[], bookmarks?: BookmarkedPage[] }): boolean => {
  6. return !!((childFolder && childFolder.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-bookmark-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(
  30. bookmarkFolderId: string, name: string, parent: string | null, childFolder: BookmarkFolderItems[],
  31. ): Promise<void> => {
  32. await apiv3Put('/bookmark-folder', {
  33. bookmarkFolderId, name, parent, childFolder,
  34. });
  35. };