mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-20 22:07:15 +00:00
chore: update list collections api
This commit is contained in:
parent
fbc089569d
commit
92635fe395
@ -16,13 +16,27 @@ import (
|
|||||||
|
|
||||||
func (s *APIV2Service) ListCollections(ctx context.Context, _ *apiv2pb.ListCollectionsRequest) (*apiv2pb.ListCollectionsResponse, error) {
|
func (s *APIV2Service) ListCollections(ctx context.Context, _ *apiv2pb.ListCollectionsRequest) (*apiv2pb.ListCollectionsResponse, error) {
|
||||||
userID := ctx.Value(userIDContextKey).(int32)
|
userID := ctx.Value(userIDContextKey).(int32)
|
||||||
find := &store.FindCollection{}
|
collections, err := s.Store.ListCollections(ctx, &store.FindCollection{
|
||||||
find.CreatorID = &userID
|
CreatorID: &userID,
|
||||||
collections, err := s.Store.ListCollections(ctx, find)
|
VisibilityList: []store.Visibility{
|
||||||
|
store.VisibilityPrivate,
|
||||||
|
},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "failed to get collection list, err: %v", err)
|
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{}
|
convertedCollections := []*apiv2pb.Collection{}
|
||||||
for _, collection := range collections {
|
for _, collection := range collections {
|
||||||
convertedCollections = append(convertedCollections, convertCollectionFromStore(collection))
|
convertedCollections = append(convertedCollections, convertCollectionFromStore(collection))
|
||||||
|
@ -9,6 +9,7 @@ import useNavigateTo from "@/hooks/useNavigateTo";
|
|||||||
import useResponsiveWidth from "@/hooks/useResponsiveWidth";
|
import useResponsiveWidth from "@/hooks/useResponsiveWidth";
|
||||||
import { useAppSelector } from "@/stores";
|
import { useAppSelector } from "@/stores";
|
||||||
import useCollectionStore from "@/stores/v1/collection";
|
import useCollectionStore from "@/stores/v1/collection";
|
||||||
|
import useUserStore from "@/stores/v1/user";
|
||||||
import { Collection } from "@/types/proto/api/v2/collection_service";
|
import { Collection } from "@/types/proto/api/v2/collection_service";
|
||||||
import { showCommonDialog } from "./Alert";
|
import { showCommonDialog } from "./Alert";
|
||||||
import CreateCollectionDialog from "./CreateCollectionDrawer";
|
import CreateCollectionDialog from "./CreateCollectionDrawer";
|
||||||
@ -25,12 +26,14 @@ const CollectionView = (props: Props) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { sm } = useResponsiveWidth();
|
const { sm } = useResponsiveWidth();
|
||||||
const navigateTo = useNavigateTo();
|
const navigateTo = useNavigateTo();
|
||||||
|
const currentUser = useUserStore().getCurrentUser();
|
||||||
const collectionStore = useCollectionStore();
|
const collectionStore = useCollectionStore();
|
||||||
const { shortcutList } = useAppSelector((state) => state.shortcut);
|
const { shortcutList } = useAppSelector((state) => state.shortcut);
|
||||||
const [showEditDialog, setShowEditDialog] = useState<boolean>(false);
|
const [showEditDialog, setShowEditDialog] = useState<boolean>(false);
|
||||||
const shortcuts = collection.shortcutIds
|
const shortcuts = collection.shortcutIds
|
||||||
.map((shortcutId) => shortcutList.find((shortcut) => shortcut?.id === shortcutId))
|
.map((shortcutId) => shortcutList.find((shortcut) => shortcut?.id === shortcutId))
|
||||||
.filter(Boolean) as any as Shortcut[];
|
.filter(Boolean) as any as Shortcut[];
|
||||||
|
const showAdminActions = currentUser.id === collection.creatorId;
|
||||||
|
|
||||||
const handleCopyCollectionLink = () => {
|
const handleCopyCollectionLink = () => {
|
||||||
copy(absolutifyLink(`/c/${collection.name}`));
|
copy(absolutifyLink(`/c/${collection.name}`));
|
||||||
@ -65,29 +68,36 @@ const CollectionView = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-row justify-end items-center shrink-0">
|
<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}`}>
|
<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>
|
</Link>
|
||||||
<Dropdown
|
{showAdminActions && (
|
||||||
actionsClassName="!w-28 dark:text-gray-500"
|
<Dropdown
|
||||||
actions={
|
trigger={
|
||||||
<>
|
<button className="flex flex-row justify-center items-center rounded text-gray-400 cursor-pointer hover:text-gray-500">
|
||||||
<button
|
<Icon.MoreVertical className="w-5 h-auto" />
|
||||||
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>
|
||||||
<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"
|
actionsClassName="!w-28 dark:text-gray-500"
|
||||||
onClick={() => {
|
actions={
|
||||||
handleDeleteCollectionButtonClick();
|
<>
|
||||||
}}
|
<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"
|
||||||
<Icon.Trash className="w-4 h-auto mr-2" /> {t("common.delete")}
|
onClick={() => setShowEditDialog(true)}
|
||||||
</button>
|
>
|
||||||
</>
|
<Icon.Edit className="w-4 h-auto mr-2" /> {t("common.edit")}
|
||||||
}
|
</button>
|
||||||
></Dropdown>
|
<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>
|
</div>
|
||||||
<div className="w-full p-3 flex flex-row justify-start items-start flex-wrap gap-3">
|
<div className="w-full p-3 flex flex-row justify-start items-start flex-wrap gap-3">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user