@@ -31,7 +31,7 @@ function addLastSet(board, lastSet) {
3131 if ( lastSet ?. length ) {
3232 const n = lastSet ?. length % 3 ;
3333 if ( n > 0 ) {
34- lastSet = lastSet . concat ( [ null ] ) ;
34+ lastSet = [ ... lastSet , null ] ;
3535 if ( n === 1 ) lastSet . splice ( - 3 , 0 , null ) ;
3636 }
3737 board = lastSet . concat ( board ) ;
@@ -57,13 +57,13 @@ function Game({
5757 const isHorizontal = cardOrientation === "horizontal" ;
5858 const isLandscape = layoutOrientation === "landscape" ;
5959 const [ gameDimensions , gameEl ] = useDimensions ( ) ;
60- const [ highlightCards , setHighlightCards ] = useState ( null ) ;
60+ const [ movingCards , setMovingCards ] = useState ( null ) ;
6161
6262 const lastKeptCards = lastKeptSet ?. join ( "|" ) ;
6363 useEffect ( ( ) => {
64- setHighlightCards ( lastKeptCards ?. split ( "|" ) ) ;
64+ setMovingCards ( lastKeptCards ?. split ( "|" ) . map ( ( card ) => " " + card ) ) ;
6565 if ( lastKeptCards ) {
66- const timer = setTimeout ( ( ) => setHighlightCards ( null ) , 300 ) ;
66+ const timer = setTimeout ( ( ) => setMovingCards ( null ) , 0 ) ;
6767 return ( ) => clearTimeout ( timer ) ;
6868 }
6969 } , [ lastKeptCards ] ) ;
@@ -117,7 +117,7 @@ function Game({
117117 // NOTE: put rotate into useTransition() instead of adding it to the style
118118 // outside to get a nice animation when cardOrientation changes.
119119 const cardProps = ( card ) => {
120- const i = board . indexOf ( card ) ;
120+ const i = board . indexOf ( card ?. trimLeft ( ) ) ;
121121 let positionX , positionY ;
122122 let r , c ;
123123 if ( ! isLandscape ) {
@@ -145,13 +145,16 @@ function Game({
145145 opacity : 1 ,
146146 } ;
147147 } ;
148- const transitions = useTransition ( board , {
149- from : {
150- left : - cardWidth ,
151- top : gameHeight / 2 - cardHeight / 2 ,
152- rotate : rotateAmount ,
153- opacity : 0 ,
154- } ,
148+ const transitions = useTransition ( movingCards ?. concat ( board ) || board , {
149+ from : ( card ) =>
150+ card ?. startsWith ( " " )
151+ ? cardProps ( card )
152+ : {
153+ left : - cardWidth ,
154+ top : gameHeight / 2 - cardHeight / 2 ,
155+ rotate : rotateAmount ,
156+ opacity : 0 ,
157+ } ,
155158 enter : cardProps ,
156159 update : cardProps ,
157160 leave : {
@@ -244,7 +247,6 @@ function Game({
244247 ( style , card ) =>
245248 card && (
246249 < animated . div
247- key = { card }
248250 className = { to ( [ style . left , style . top ] , ( ) =>
249251 style . left . idle && style . top . idle
250252 ? classes . staticCard
@@ -273,11 +275,10 @@ function Game({
273275 </ div >
274276 ) : (
275277 < ResponsiveSetCard
276- value = { card }
278+ value = { card . trimLeft ( ) }
277279 width = { cardWidth }
278280 hinted = { answer ?. includes ( card ) }
279281 active = { selected ?. includes ( card ) }
280- highlight = { highlightCards ?. includes ( card ) }
281282 faceDown = {
282283 faceDown === "all" ||
283284 ( faceDown &&
0 commit comments