import React from "react"; import styled from "styled-components"; import { Link } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { getBestTranslationFromConfig } from "../utils/api"; const Game = styled.li` position: relative; padding: 0em; margin: 0px; margin-bottom: 3em; flex: 1; & .game-name { max-width: 80%; line-height: 1.2em; overflow: hidden; margin-bottom: 3px; margin: 0.2em 0 0.5em 0; font-size: 2.5vw; } & .unpublished { position: absolute; top: 0.5em; right: 0.5em; padding: 0em; } & .button.play { margin: 0 2px; background-color: var(--color-secondary); } & .play { position: absolute; bottom: 0.5em; right: 0.5em; } & .extra-actions { position: absolute; top: 0.5em; right: 0.5em; display: none; } &:hover .extra-actions { display: block; } & .img { width: 100%; min-width: 300px; max-width: 600px; background-color: #333; border-radius: 5px; } & .details { display: flex; flex-direction: row; color: var(--font-color2); font-size: 14px; padding-top: 1em; } & .details > span { display: flex; align-items: center; padding-right: 5px; margin-right: 5px; border-right: 1px solid var(--font-color2); } & .details > span:last-child { border: none; } & .details img { margin-right: 0.5em; } `; const GameListItem = ({ game: { published, owner, id, minAge, materialLanguage, duration, playerCount, imageUrl, }, game, userId, }) => { const { t, i18n } = useTranslation(); const translation = React.useMemo( () => getBestTranslationFromConfig(game, i18n.languages), [game, i18n.languages] ); let playerCountDisplay = undefined; if (playerCount && playerCount.length) { const [min, max] = playerCount; if (min === max) { if (max === 9) { playerCountDisplay = ["9+"]; } else { playerCountDisplay = [max]; } } else { if (max === 9) { playerCountDisplay = [min, "9+"]; } else { playerCountDisplay = [min, max]; } } } let durationDisplay = undefined; if (duration && duration.length) { const [min, max] = duration; if (min === max) { if (max === 90) { durationDisplay = "90+"; } else { durationDisplay = `~${max}`; } } else { if (max === 90) { durationDisplay = `${min}~90+`; } else { durationDisplay = `${min}~${max}`; } } } let materialLanguageDisplay = t(materialLanguage); console.log(playerCountDisplay, playerCount); return ( {imageUrl ? ( ) : ( )} {!published && ( {t("Unpublished")} )}
{playerCountDisplay && ( {playerCountDisplay.length === 2 && t("{{min}} - {{max}} players", { min: playerCountDisplay[0], max: playerCountDisplay[1], })} {playerCountDisplay.length === 1 && t("{{count}} player", { count: playerCountDisplay[0], })} )} {durationDisplay && {durationDisplay} mins} {minAge && age {minAge}+} {materialLanguageDisplay && {materialLanguageDisplay}}

{translation.name}

{userId && (userId === owner || !owner) && (
{t("Edit")}
)}
); }; export default GameListItem;