Shun Miyazawa 2 سال پیش
والد
کامیت
0008d45c8b

+ 9 - 2
apps/app/src/components/Bookmarks/BookmarkFolderTree.tsx

@@ -23,7 +23,14 @@ import styles from './BookmarkFolderTree.module.scss';
 //   parentFolder: BookmarkFolderItems | null
 //   parentFolder: BookmarkFolderItems | null
 //  } & IPageHasId
 //  } & IPageHasId
 
 
-export const BookmarkFolderTree: React.FC<{isUserHomePage?: boolean}> = ({ isUserHomePage }) => {
+type Props = {
+  isUserHomePage?: boolean,
+  userId?: string,
+}
+
+export const BookmarkFolderTree: React.FC<Props> = (props: Props) => {
+  const { isUserHomePage, userId } = props;
+
   // const acceptedTypes: DragItemType[] = [DRAG_ITEM_TYPE.FOLDER, DRAG_ITEM_TYPE.BOOKMARK];
   // const acceptedTypes: DragItemType[] = [DRAG_ITEM_TYPE.FOLDER, DRAG_ITEM_TYPE.BOOKMARK];
   const { t } = useTranslation();
   const { t } = useTranslation();
 
 
@@ -31,7 +38,7 @@ export const BookmarkFolderTree: React.FC<{isUserHomePage?: boolean}> = ({ isUse
   const { data: currentPage } = useSWRxCurrentPage();
   const { data: currentPage } = useSWRxCurrentPage();
   const { mutate: mutateBookmarkInfo } = useSWRBookmarkInfo(currentPage?._id);
   const { mutate: mutateBookmarkInfo } = useSWRBookmarkInfo(currentPage?._id);
   const { data: bookmarkFolders, mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild();
   const { data: bookmarkFolders, mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild();
-  const { data: userBookmarks, mutate: mutateUserBookmarks } = useSWRxCurrentUserBookmarks();
+  const { data: userBookmarks, mutate: mutateUserBookmarks } = useSWRxCurrentUserBookmarks(userId);
   const { open: openDeleteModal } = usePageDeleteModal();
   const { open: openDeleteModal } = usePageDeleteModal();
 
 
   const bookmarkFolderTreeMutation = useCallback(() => {
   const bookmarkFolderTreeMutation = useCallback(() => {

+ 4 - 1
apps/app/src/components/Sidebar/Bookmarks/BookmarkContents.tsx

@@ -8,11 +8,14 @@ import { BookmarkFolderNameInput } from '~/components/Bookmarks/BookmarkFolderNa
 import { BookmarkFolderTree } from '~/components/Bookmarks/BookmarkFolderTree';
 import { BookmarkFolderTree } from '~/components/Bookmarks/BookmarkFolderTree';
 import { FolderPlusIcon } from '~/components/Icons/FolderPlusIcon';
 import { FolderPlusIcon } from '~/components/Icons/FolderPlusIcon';
 import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
 import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
+import { useCurrentUser } from '~/stores/context';
 
 
 export const BookmarkContents = (): JSX.Element => {
 export const BookmarkContents = (): JSX.Element => {
 
 
   const { t } = useTranslation();
   const { t } = useTranslation();
   const [isCreateAction, setIsCreateAction] = useState<boolean>(false);
   const [isCreateAction, setIsCreateAction] = useState<boolean>(false);
+
+  const { data: currentUser } = useCurrentUser();
   const { mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild();
   const { mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild();
 
 
   const onClickNewBookmarkFolder = useCallback(() => {
   const onClickNewBookmarkFolder = useCallback(() => {
@@ -53,7 +56,7 @@ export const BookmarkContents = (): JSX.Element => {
           />
           />
         </div>
         </div>
       )}
       )}
-      <BookmarkFolderTree />
+      <BookmarkFolderTree userId={currentUser?._id} />
     </>
     </>
   );
   );
 };
 };

+ 1 - 1
apps/app/src/components/UsersHomePageFooter.tsx

@@ -39,7 +39,7 @@ export const UsersHomePageFooter = (props: UsersHomePageFooterProps): JSX.Elemen
         </h2>
         </h2>
         {/* TODO: In bookmark folders v1, the button to create a new folder does not exist. The button should be included in the bookmark component. */}
         {/* TODO: In bookmark folders v1, the button to create a new folder does not exist. The button should be included in the bookmark component. */}
         <div className={`${isExpanded ? `${styles['grw-bookarks-contents-expanded']}` : `${styles['grw-bookarks-contents-compressed']}`}`}>
         <div className={`${isExpanded ? `${styles['grw-bookarks-contents-expanded']}` : `${styles['grw-bookarks-contents-compressed']}`}`}>
-          <BookmarkFolderTree isUserHomePage={true} />
+          <BookmarkFolderTree isUserHomePage={true} userId={creatorId} />
         </div>
         </div>
       </div>
       </div>
       <div className="grw-user-page-list-m mt-5 d-edit-none">
       <div className="grw-user-page-list-m mt-5 d-edit-none">

+ 4 - 6
apps/app/src/stores/bookmark.ts

@@ -7,8 +7,6 @@ import { IPageHasId } from '~/interfaces/page';
 import { apiv3Get } from '../client/util/apiv3-client';
 import { apiv3Get } from '../client/util/apiv3-client';
 import { IBookmarkInfo } from '../interfaces/bookmark-info';
 import { IBookmarkInfo } from '../interfaces/bookmark-info';
 
 
-import { useCurrentUser } from './context';
-
 export const useSWRBookmarkInfo = (pageId: string | null | undefined): SWRResponse<IBookmarkInfo, Error> => {
 export const useSWRBookmarkInfo = (pageId: string | null | undefined): SWRResponse<IBookmarkInfo, Error> => {
   return useSWRImmutable(
   return useSWRImmutable(
     pageId != null ? `/bookmarks/info?pageId=${pageId}` : null,
     pageId != null ? `/bookmarks/info?pageId=${pageId}` : null,
@@ -22,11 +20,11 @@ export const useSWRBookmarkInfo = (pageId: string | null | undefined): SWRRespon
   );
   );
 };
 };
 
 
-export const useSWRxCurrentUserBookmarks = (): SWRResponse<IPageHasId[], Error> => {
-  const { data: currentUser } = useCurrentUser();
-  const user = currentUser as IUserHasId;
+export const useSWRxCurrentUserBookmarks = (userId?: string): SWRResponse<IPageHasId[], Error> => {
+  // const { data: currentUser } = useCurrentUser();
+  // const user = currentUser as IUserHasId;
   return useSWRImmutable(
   return useSWRImmutable(
-    currentUser != null ? `/bookmarks/${user._id}` : null,
+    userId != null ? `/bookmarks/${userId}` : null,
     endpoint => apiv3Get(endpoint).then((response) => {
     endpoint => apiv3Get(endpoint).then((response) => {
       const { userRootBookmarks } = response.data;
       const { userRootBookmarks } = response.data;
       return userRootBookmarks.map((item) => {
       return userRootBookmarks.map((item) => {