···11import { Bookmark } from "lucide-react";
22import { useState } from "react";
33-import type { DeckItemUri } from "@/lib/constellation-queries";
33+import type { SaveItem } from "@/lib/collection-list-types";
44+import type { SocialItemUri } from "@/lib/constellation-queries";
45import { useItemSocialStats } from "@/lib/constellation-queries";
55-import type { OracleId, OracleUri, ScryfallId } from "@/lib/scryfall-types";
66import { toOracleUri } from "@/lib/scryfall-types";
77import { useAuth } from "@/lib/useAuth";
88import { SaveToListDialog } from "../list/SaveToListDialog";
991010-export type SocialItem =
1111- | { type: "card"; scryfallId: ScryfallId; oracleId: OracleId }
1212- | { type: "deck"; deckUri: DeckItemUri };
1313-1410interface SocialStatsProps {
1515- item: SocialItem;
1111+ item: SaveItem;
1612 itemName?: string;
1713 showCount?: boolean;
1814 className?: string;
1915}
20162121-function getItemUri(item: SocialItem): OracleUri | DeckItemUri {
1717+function getItemUri(item: SaveItem): SocialItemUri {
2218 return item.type === "card" ? toOracleUri(item.oracleId) : item.deckUri;
2319}
2420
+36-6
src/lib/collection-list-queries.ts
···33 * Provides query options and mutations for saving cards/decks to lists
44 */
5566-import type { Did } from "@atcute/lexicons";
66+import type { Did, ResourceUri } from "@atcute/lexicons";
77import {
88 type InfiniteData,
99 infiniteQueryOptions,
···2626 isCardItem,
2727 isDeckItem,
2828 type ListItem,
2929+ type SaveItem,
2930} from "./collection-list-types";
3031import { getPdsForDid } from "./identity";
3132import type { ComDeckbelcherCollectionList } from "./lexicons/index";
···132133 staleTime: 60 * 1000,
133134 });
134135136136+interface CreateListParams {
137137+ name: string;
138138+ initialItem?: SaveItem;
139139+}
140140+135141/**
136142 * Mutation for creating a new collection list
143143+ * Optionally adds an initial item to the list
137144 */
138145export function useCreateCollectionListMutation() {
139146 const { agent, session } = useAuth();
140147 const queryClient = useQueryClient();
141148142149 return useMutationWithToast({
143143- mutationFn: async (list: { name: string }) => {
150150+ mutationFn: async ({ name, initialItem }: CreateListParams) => {
144151 if (!agent || !session) {
145152 throw new Error("Must be authenticated to create a list");
146153 }
147154155155+ const items: ComDeckbelcherCollectionList.Main["items"] = [];
156156+ if (initialItem) {
157157+ const addedAt = new Date().toISOString();
158158+ if (initialItem.type === "card") {
159159+ items.push({
160160+ $type: "com.deckbelcher.collection.list#cardItem",
161161+ addedAt,
162162+ ref: {
163163+ scryfallUri: toScryfallUri(initialItem.scryfallId),
164164+ oracleUri: toOracleUri(initialItem.oracleId),
165165+ },
166166+ });
167167+ } else {
168168+ items.push({
169169+ $type: "com.deckbelcher.collection.list#deckItem",
170170+ addedAt,
171171+ deckUri: initialItem.deckUri as ResourceUri,
172172+ });
173173+ }
174174+ }
175175+148176 const result = await createCollectionListRecord(agent, {
149177 $type: "com.deckbelcher.collection.list",
150150- name: list.name,
151151- items: [],
178178+ name,
179179+ items,
152180 createdAt: new Date().toISOString(),
153181 });
154182···158186159187 return result.data;
160188 },
161161- onSuccess: () => {
162162- toast.success("List created");
189189+ onSuccess: (_data, { initialItem }) => {
190190+ toast.success(
191191+ initialItem ? "List created and item saved" : "List created",
192192+ );
163193164194 if (!session) return;
165195
+9
src/lib/collection-list-types.ts
···44 */
5566import type { ResourceUri } from "@atcute/lexicons";
77+import type { DeckItemUri } from "./constellation-queries";
78import type { ComDeckbelcherCollectionList } from "./lexicons/index";
89import type { OracleId, ScryfallId } from "./scryfall-types";
1010+1111+/**
1212+ * Item to save to a list (card or deck)
1313+ * Shared by SaveToListDialog and SocialStats
1414+ */
1515+export type SaveItem =
1616+ | { type: "card"; scryfallId: ScryfallId; oracleId: OracleId }
1717+ | { type: "deck"; deckUri: DeckItemUri };
9181019/**
1120 * App-side card item with flat typed IDs.