-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change UI for played cards, player cards and scores
- Loading branch information
Showing
10 changed files
with
371 additions
and
109 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
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,55 @@ | ||
import React from "react"; | ||
import * as R from "ramda"; | ||
import cs from "classnames"; | ||
|
||
import Card from "../../../components/Card"; | ||
import cards from "../../../utils/cards"; | ||
|
||
import styles from "./PlayedCards.module.scss"; | ||
|
||
const getCardZIndex = ({ card, cardsByPlayer, index }) => { | ||
return R.pipe( | ||
R.map(R.path(["cards", index])), | ||
() => R.find(R.propEq("card", card))(cards), | ||
R.prop("score") | ||
)(cardsByPlayer); | ||
}; | ||
|
||
export default function PlayedCards({ cardsPlayedByPlayer, userId }) { | ||
// Put current player last in the list | ||
const cardsByPlayer = R.pipe( | ||
R.map( | ||
R.when(R.propEq("playerId", userId), R.assoc("isCurrentPlayer", true)) | ||
), | ||
R.sortWith([R.ascend(R.propOr(false, "isCurrentPlayer"))]) | ||
)(cardsPlayedByPlayer); | ||
|
||
return ( | ||
<div className={styles.playedCards}> | ||
{cardsByPlayer.map(({ playerId, cards, isCurrentPlayer }) => ( | ||
<div | ||
key={playerId} | ||
className={cs(styles.playerCards, { | ||
[styles.isCurrentPlayer]: isCurrentPlayer | ||
})} | ||
> | ||
{cards.map((card, index) => ( | ||
<Card | ||
key={card} | ||
card={card} | ||
style={{ | ||
zIndex: getCardZIndex({ card, cardsByPlayer, index }), | ||
margin: 0 | ||
}} | ||
/> | ||
))} | ||
{Array(3 - cards.length) | ||
.fill(undefined) | ||
.map((_, i) => ( | ||
<Card key={i} isPlaceholder style={{ margin: 0 }} /> | ||
))} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
client/src/screens/Match/PlayedCards/PlayedCards.module.scss
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,19 @@ | ||
.playedCards { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
height: 244px; | ||
} | ||
|
||
.playerCards { | ||
display: flex; | ||
justify-content: space-between; | ||
width: 500px; | ||
|
||
&.isCurrentPlayer { | ||
position: relative; | ||
top: -120px; | ||
left: 40px; | ||
} | ||
} |
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,3 @@ | ||
import PlayedCards from "./PlayedCards"; | ||
|
||
export default PlayedCards; |
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
Oops, something went wrong.