Skip to content

Commit

Permalink
Removed unnessecarily complex props from collection and resolved a bu…
Browse files Browse the repository at this point in the history
…g when saving an existing deck
  • Loading branch information
eviterin committed Feb 27, 2024
1 parent 60aff3f commit 3cf1f44
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/webapp/src/components/collection/deckPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface DeckConstructionPanelProps {
onClick={() => onCardSelect(card)}
>
<div className="flex items-center space-x-3">
<Image src={testCards.find(tc => tc.id === card.id)?.image || '/card_art/1.jpg'} alt="Card art" width={40} height={40} className="object-cover rounded-full" />
<Image src={testCards.find(tc => tc.id === Number(card.id))?.image || '/card_art/1.jpg'} alt="Card art" width={40} height={40} className="object-cover rounded-full" />
<span className="font-medium">{card.lore.name}</span>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Toaster } from "src/components/ui/sonner"
* Make pages in the app conform to this type.
* See [@link useIsHydrated] for more info on the meaning of the `isHydrated` prop.
*/
export type FablePage = NextPage<{ decks: Deck[], isHydrated: boolean, setDecks: Dispatch<SetStateAction<Deck[]>> }>
export type FablePage = NextPage<{ isHydrated: boolean }>

// =================================================================================================

Expand Down
13 changes: 4 additions & 9 deletions packages/webapp/src/pages/collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ const initialEffectMap = Object.assign({}, ...effects.map(name => ({[name]: fals
const types = ['Creature', 'Magic', 'Weapon']
const initialTypeMap = Object.assign({}, ...types.map(name => ({[name]: false})))

interface CollectionSpecificProps {
decks: Deck[]
setDecks: (decks: Deck[]) => void
isHydrated: boolean
}
type CollectionProps = FablePage & CollectionSpecificProps

const Collection: React.FC<CollectionProps> = ({ decks, setDecks, isHydrated }) => {
const Collection: FablePage = ({ isHydrated }) => {

const router = useRouter()
const { address } = useAccount()
Expand All @@ -50,6 +43,8 @@ const Collection: React.FC<CollectionProps> = ({ decks, setDecks, isHydrated })

// Deck Collection Display
const [ editingDeckIndex, setEditingDeckIndex ] = useState<number|null>(null)
const [decks, setDecks] = useState<Deck[]>([])

// Deck Construction Panel
const [ currentDeck, setCurrentDeck] = useState<Deck|null>(null)
const [ selectedCards, setSelectedCards ] = useState<Card[]>([])
Expand Down Expand Up @@ -100,7 +95,7 @@ const Collection: React.FC<CollectionProps> = ({ decks, setDecks, isHydrated })
}

const handleSaveDeck = (updatedDeck: Deck) => {
const updatedDecks = [...decks]
const updatedDecks = [...(decks || [])]
if (editingDeckIndex !== null) {
// Update existing deck
updatedDecks[editingDeckIndex] = updatedDeck
Expand Down

0 comments on commit 3cf1f44

Please sign in to comment.