-
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.
feat(ui): add GameStateCard, PolyButton components, extract hook useC…
…onfirmModal, add SavePage
- Loading branch information
1 parent
48f107a
commit 3ce2848
Showing
37 changed files
with
845 additions
and
224 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,60 @@ | ||
import { GameState } from "@/types"; | ||
|
||
import classes from "./game-state-card.module.scss"; | ||
import { clsx } from "clsx"; | ||
import { Link } from "wouter"; | ||
import { ThreeDotsMenu } from "@/client/ui/molecules/ThreeDotsMenu"; | ||
import { useTranslation } from "react-i18next"; | ||
import { syncMap } from "@/client/pages/MySaves/utils"; | ||
import { useConfirmModal } from "@/client/ui/hooks/useConfirmModal/useConfirmModal"; | ||
|
||
export type GameStateCardProps = { | ||
gameState: GameState; | ||
className?: string; | ||
onDelete?: (gameStateId: string) => void; | ||
href: string; | ||
}; | ||
|
||
export const GameStateCard = (props: GameStateCardProps) => { | ||
const { t } = useTranslation(undefined, { | ||
keyPrefix: "components.GameStateCard", | ||
}); | ||
|
||
const { modal, onClick: onDelete } = useConfirmModal({ | ||
onConfirm: () => props.onDelete?.(props.gameState.id), | ||
}); | ||
|
||
return ( | ||
<div | ||
className={clsx(classes.GameStateCard, props.className)} | ||
style={{ | ||
backgroundImage: `url(${props.gameState.gameIconURL})`, | ||
}} | ||
> | ||
<Link href={props.href} className={classes.GameStateLink}> | ||
<div className={classes.GameStateCardInner}> | ||
{props.onDelete && ( | ||
<ThreeDotsMenu | ||
className={classes.GameStateActions} | ||
menuItems={[ | ||
{ | ||
onClick: () => onDelete(), | ||
children: "Delete", | ||
key: "delete", | ||
}, | ||
]} | ||
/> | ||
)} | ||
{modal} | ||
|
||
<div className={classes.GameStateInfo}> | ||
<p>{props.gameState.name}</p> | ||
<p> | ||
{t("sync")}: {t(syncMap[props.gameState.sync])} | ||
</p> | ||
</div> | ||
</div> | ||
</Link> | ||
</div> | ||
); | ||
}; |
46 changes: 46 additions & 0 deletions
46
src/client/lib/components/GameStateCard/game-state-card.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,46 @@ | ||
.GameStateCard { | ||
min-width: 200px; | ||
min-height: 250px; | ||
display: flex; | ||
flex-direction: column; | ||
border-radius: 6px; | ||
overflow: hidden; | ||
} | ||
|
||
.GameStateLink { | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
text-decoration: none; | ||
} | ||
|
||
.GameStateCardInner { | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.25rem; | ||
padding: 0.75rem 0.75rem 1rem; | ||
|
||
background-image: linear-gradient( | ||
180deg, | ||
rgba(255, 255, 255, 0.2) 0%, | ||
rgba(0, 0, 0, 0.8) 60%, | ||
rgba(0, 0, 0, 0.9) 100% | ||
); | ||
background-position: 0% 50%; | ||
background-size: 200% 200%; | ||
transition: background-position 0.3s ease; | ||
|
||
&:hover { | ||
background-position: 0% 60%; | ||
} | ||
} | ||
|
||
.GameStateActions { | ||
margin-left: auto; | ||
} | ||
|
||
.GameStateInfo { | ||
margin-top: auto; | ||
color: white; | ||
} |
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 @@ | ||
export * from "./GameStateCard"; |
61 changes: 61 additions & 0 deletions
61
src/client/lib/components/ParametersView/ParametersView.tsx
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,61 @@ | ||
import classes from "./parameters-view.module.scss"; | ||
|
||
import { GameStateValue } from "@/types"; | ||
|
||
type ParametersViewProps = { | ||
gameStateValues: GameStateValue[]; | ||
}; | ||
|
||
export const ParametersView = (props: ParametersViewProps) => { | ||
return ( | ||
<div> | ||
{props.gameStateValues.map((field, idx) => ( | ||
<ParameterViewItem key={idx} {...field} /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
function formatTime(value: number, type: "seconds") { | ||
if (type === "seconds") { | ||
if (value < 60) { | ||
return `${value} seconds`; | ||
} | ||
const minutes = Math.floor(value / 60); | ||
|
||
if (minutes < 60) { | ||
return `${minutes} minutes`; | ||
} | ||
|
||
const hours = Math.floor(minutes / 60); | ||
|
||
return `${hours} hours`; | ||
} | ||
|
||
return `${value}`; | ||
} | ||
|
||
const ParameterViewItem = (props: { | ||
label: string; | ||
value: string; | ||
type: string; | ||
description: string; | ||
}) => { | ||
if (props.type === "seconds") { | ||
return ( | ||
<div> | ||
<span>{props.label}</span>:{" "} | ||
<span className={classes.ParameterValue}> | ||
{formatTime(parseFloat(props.value), props.type)} | ||
</span> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<span>{props.label}</span>:{" "} | ||
<span className={classes.ParameterValue}>{props.value.toString()}</span> | ||
</div> | ||
); | ||
}; |
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
src/client/lib/components/ParametersView/parameters-view.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,3 @@ | ||
.ParameterValue { | ||
font-weight: bold; | ||
} |
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,8 @@ | ||
{ | ||
"sync": "Sync", | ||
"every-hour": "Every hour", | ||
"every-day": "Every day", | ||
"every-week": "Every week", | ||
"every-month": "Every month", | ||
"no": "No" | ||
} |
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
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,8 @@ | ||
{ | ||
"sync": "Синхронизация", | ||
"every-hour": "Каждый час", | ||
"every-day": "Каждый день", | ||
"every-week": "Каждую неделю", | ||
"every-month": "Каждый месяц", | ||
"no": "Нет" | ||
} |
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
Oops, something went wrong.