Просмотр исходного кода

Add bookmarks as items in folder

satof3 2 лет назад
Родитель
Сommit
f9badbbd1a

+ 4 - 10
apps/app/src/client/util/bookmark-utils.ts

@@ -1,18 +1,12 @@
 import type { IRevision, Ref } from '@growi/core';
 import type { IRevision, Ref } from '@growi/core';
 
 
-import type { BookmarkFolderItems } from '~/interfaces/bookmark-info';
+import type { BookmarkFolderItems, BookmarkedPage } from '~/interfaces/bookmark-info';
 
 
 import { apiv3Delete, apiv3Post, apiv3Put } from './apiv3-client';
 import { apiv3Delete, apiv3Post, apiv3Put } from './apiv3-client';
 
 
-// Check if bookmark folder item has children
-export const hasChildren = (item: BookmarkFolderItems | BookmarkFolderItems[]): boolean => {
-  if (item === null) {
-    return false;
-  }
-  if (Array.isArray(item)) {
-    return item.length > 0;
-  }
-  return item.children && item.children.length > 0;
+// Check if bookmark folder item has children or bookmarks
+export const hasChildren = ({ children, bookmarks }: { children?: BookmarkFolderItems[], bookmarks?: BookmarkedPage[] }): boolean => {
+  return !!((children && children.length > 0) || (bookmarks && bookmarks.length > 0));
 };
 };
 
 
 // Add new folder helper
 // Add new folder helper

+ 1 - 1
apps/app/src/components/Bookmarks/BookmarkFolderItem.tsx

@@ -50,7 +50,7 @@ export const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkF
 
 
   const { open: openDeleteBookmarkFolderModal } = useBookmarkFolderDeleteModal();
   const { open: openDeleteBookmarkFolderModal } = useBookmarkFolderDeleteModal();
 
 
-  const childrenExists = hasChildren(children);
+  const childrenExists = hasChildren({ children, bookmarks });
 
 
   const paddingLeft = BASE_FOLDER_PADDING * level;
   const paddingLeft = BASE_FOLDER_PADDING * level;