👁️
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix card ref facet, refactor pt2

+27 -4
+3 -1
src/components/richtext/CombinedAutocomplete.tsx
··· 4 4 closeAutocomplete, 5 5 } from "prosemirror-autocomplete"; 6 6 import type { Plugin } from "prosemirror-state"; 7 + import type { OracleId, ScryfallId } from "@/lib/scryfall-types"; 7 8 import type { AutocompleteCallbacks } from "./useEditorAutocomplete"; 8 9 9 10 export interface MentionOption { ··· 13 14 14 15 export interface CardOption { 15 16 name: string; 16 - scryfallId: string; 17 + scryfallId: ScryfallId; 18 + oracleId: OracleId; 17 19 } 18 20 19 21 export interface TagOption {
+8 -3
src/components/richtext/ProseMirrorEditor.tsx
··· 28 28 } from "./CombinedAutocomplete"; 29 29 import { buildInputRules } from "./inputRules"; 30 30 import { createUpdatePlugin } from "./plugins"; 31 - import { schema } from "./schema"; 31 + import { createCardRefNode, schema } from "./schema"; 32 32 import { Toolbar } from "./Toolbar"; 33 33 import { useEditorAutocomplete } from "./useEditorAutocomplete"; 34 34 ··· 110 110 state: { range: { from: number; to: number } }, 111 111 view: EditorView, 112 112 ) => { 113 - const cardRefNode = schema.nodes.cardRef.create({ 113 + const cardRefNode = createCardRefNode({ 114 114 name: option.name, 115 115 scryfallId: option.scryfallId, 116 + oracleId: option.oracleId, 116 117 }); 117 118 118 119 const tr = view.state.tr ··· 130 131 (query: string) => ({ 131 132 ...searchCardsQueryOptions(query, undefined, 10), 132 133 select: (result: { cards: Card[]; totalCount: number }): CardOption[] => 133 - result.cards.map((c) => ({ name: c.name, scryfallId: c.id })), 134 + result.cards.map((c) => ({ 135 + name: c.name, 136 + scryfallId: c.id, 137 + oracleId: c.oracle_id, 138 + })), 134 139 }), 135 140 [], 136 141 );
+16
src/components/richtext/schema.ts
··· 1 1 import type { MarkSpec, NodeSpec } from "prosemirror-model"; 2 2 import { Schema } from "prosemirror-model"; 3 + import type { OracleId, ScryfallId } from "@/lib/scryfall-types"; 3 4 4 5 /** 5 6 * Vendored and customized schema based on prosemirror-markdown. ··· 374 375 }; 375 376 376 377 export const schema = new Schema({ nodes, marks }); 378 + 379 + /** 380 + * Required attrs for cardRef node creation. 381 + * Using branded types ensures TypeScript catches missing/wrong fields. 382 + */ 383 + export interface CardRefAttrs { 384 + name: string; 385 + scryfallId: ScryfallId; 386 + oracleId: OracleId; 387 + } 388 + 389 + /** Type-safe cardRef node creation - use this instead of schema.nodes.cardRef.create() */ 390 + export function createCardRefNode(attrs: CardRefAttrs) { 391 + return schema.nodes.cardRef.create(attrs); 392 + }