chore: update list collections api

This commit is contained in:
Steven 2023-11-15 23:31:47 +08:00
parent fbc089569d
commit 92635fe395
2 changed files with 48 additions and 24 deletions

View File

@ -16,13 +16,27 @@ import (
func (s *APIV2Service) ListCollections(ctx context.Context, _ *apiv2pb.ListCollectionsRequest) (*apiv2pb.ListCollectionsResponse, error) {
userID := ctx.Value(userIDContextKey).(int32)
find := &store.FindCollection{}
find.CreatorID = &userID
collections, err := s.Store.ListCollections(ctx, find)
collections, err := s.Store.ListCollections(ctx, &store.FindCollection{
CreatorID: &userID,
VisibilityList: []store.Visibility{
store.VisibilityPrivate,
},
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get collection list, err: %v", err)
}
sharedCollections, err := s.Store.ListCollections(ctx, &store.FindCollection{
VisibilityList: []store.Visibility{
store.VisibilityWorkspace,
store.VisibilityPublic,
},
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get collection list, err: %v", err)
}
collections = append(collections, sharedCollections...)
convertedCollections := []*apiv2pb.Collection{}
for _, collection := range collections {
convertedCollections = append(convertedCollections, convertCollectionFromStore(collection))

View File

@ -9,6 +9,7 @@ import useNavigateTo from "@/hooks/useNavigateTo";
import useResponsiveWidth from "@/hooks/useResponsiveWidth";
import { useAppSelector } from "@/stores";
import useCollectionStore from "@/stores/v1/collection";
import useUserStore from "@/stores/v1/user";
import { Collection } from "@/types/proto/api/v2/collection_service";
import { showCommonDialog } from "./Alert";
import CreateCollectionDialog from "./CreateCollectionDrawer";
@ -25,12 +26,14 @@ const CollectionView = (props: Props) => {
const { t } = useTranslation();
const { sm } = useResponsiveWidth();
const navigateTo = useNavigateTo();
const currentUser = useUserStore().getCurrentUser();
const collectionStore = useCollectionStore();
const { shortcutList } = useAppSelector((state) => state.shortcut);
const [showEditDialog, setShowEditDialog] = useState<boolean>(false);
const shortcuts = collection.shortcutIds
.map((shortcutId) => shortcutList.find((shortcut) => shortcut?.id === shortcutId))
.filter(Boolean) as any as Shortcut[];
const showAdminActions = currentUser.id === collection.creatorId;
const handleCopyCollectionLink = () => {
copy(absolutifyLink(`/c/${collection.name}`));
@ -65,29 +68,36 @@ const CollectionView = (props: Props) => {
</div>
<div className="flex flex-row justify-end items-center shrink-0">
<Link className="w-full text-gray-400 cursor-pointer hover:text-gray-500" to={`/c/${collection.name}`}>
<Icon.Share className="w-4 h-auto mr-2" />
<Icon.Share className="w-5 h-auto mr-2" />
</Link>
<Dropdown
actionsClassName="!w-28 dark:text-gray-500"
actions={
<>
<button
className="w-full px-2 flex flex-row justify-start items-center text-left leading-8 cursor-pointer rounded hover:bg-gray-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:opacity-60 dark:hover:bg-zinc-800"
onClick={() => setShowEditDialog(true)}
>
<Icon.Edit className="w-4 h-auto mr-2" /> {t("common.edit")}
{showAdminActions && (
<Dropdown
trigger={
<button className="flex flex-row justify-center items-center rounded text-gray-400 cursor-pointer hover:text-gray-500">
<Icon.MoreVertical className="w-5 h-auto" />
</button>
<button
className="w-full px-2 flex flex-row justify-start items-center text-left leading-8 cursor-pointer rounded text-red-600 hover:bg-gray-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:opacity-60 dark:hover:bg-zinc-800"
onClick={() => {
handleDeleteCollectionButtonClick();
}}
>
<Icon.Trash className="w-4 h-auto mr-2" /> {t("common.delete")}
</button>
</>
}
></Dropdown>
}
actionsClassName="!w-28 dark:text-gray-500"
actions={
<>
<button
className="w-full px-2 flex flex-row justify-start items-center text-left leading-8 cursor-pointer rounded hover:bg-gray-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:opacity-60 dark:hover:bg-zinc-800"
onClick={() => setShowEditDialog(true)}
>
<Icon.Edit className="w-4 h-auto mr-2" /> {t("common.edit")}
</button>
<button
className="w-full px-2 flex flex-row justify-start items-center text-left leading-8 cursor-pointer rounded text-red-600 hover:bg-gray-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:opacity-60 dark:hover:bg-zinc-800"
onClick={() => {
handleDeleteCollectionButtonClick();
}}
>
<Icon.Trash className="w-4 h-auto mr-2" /> {t("common.delete")}
</button>
</>
}
></Dropdown>
)}
</div>
</div>
<div className="w-full p-3 flex flex-row justify-start items-start flex-wrap gap-3">