-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
57b33e3
commit 96d7874
Showing
3 changed files
with
114 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { useMemo } from 'react'; | ||
import { getAssortmentColors, getAssortmentLabels } from '../App'; | ||
import { Assortment } from '../lib/Assortment'; | ||
import { Card } from '../lib/Card'; | ||
import { IDeck, IPossibleCard } from '../lib/Deck'; | ||
import { useMutable } from '../lib/Mutable'; | ||
import { CardBase } from './CardBase'; | ||
|
||
export function DeckView({ | ||
deck, | ||
cardPrefix, | ||
}: { | ||
deck: IDeck; | ||
cardPrefix?: (card: IPossibleCard, index: number) => React.ReactNode; | ||
}) { | ||
const deckNonce = useMutable(deck); | ||
const groupedCards = useMemo( | ||
() => deck.cards, // groupByAssortment(deck.cards), | ||
[deckNonce] | ||
); | ||
|
||
const colors = useMemo(() => getAssortmentColors(deck.cards), [deckNonce]); | ||
const labels = useMemo(() => getAssortmentLabels(deck.cards), [deckNonce]); | ||
|
||
return ( | ||
<div> | ||
<ol> | ||
{groupedCards.map((card, index) => ( | ||
<li | ||
key={index} | ||
style={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '0.25rem', | ||
margin: '0.25rem 0', | ||
}} | ||
> | ||
{cardPrefix?.(card, index)} | ||
<CardBase | ||
style={{ | ||
flexGrow: 1, | ||
height: | ||
// (1 + Math.min(count, 6) * 0.75).toFixed(1) + | ||
'1.75rem', | ||
backgroundColor: | ||
card instanceof Assortment | ||
? colors.get(card) | ||
: undefined, | ||
}} | ||
> | ||
{card instanceof Card | ||
? card.name | ||
: `1 of ${Assortment.getTotalCardCount(card)}`} | ||
{card instanceof Assortment && ( | ||
<> Group {labels.get(card)}</> | ||
)} | ||
{/* x{count} */} | ||
{card instanceof Assortment && | ||
card.cards.size < 5 && ( | ||
<> | ||
{' '} | ||
( | ||
{[...card.cards.entries()] | ||
.map( | ||
([c, count]) => | ||
`${c.name}${ | ||
count > 1 | ||
? ` x${count}` | ||
: '' | ||
}` | ||
) | ||
.join(', ')} | ||
) | ||
</> | ||
)} | ||
</CardBase> | ||
</li> | ||
))} | ||
</ol> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
|
||
export function Popup({ | ||
visible, | ||
children, | ||
}: { | ||
visible: boolean; | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<div | ||
style={{ | ||
position: 'fixed', | ||
inset: 0, | ||
width: '100vw', | ||
height: '100vh', | ||
background: '#0008', | ||
display: visible ? 'flex' : 'none', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} |