refactor InfoPanel

This commit is contained in:
Halit Aksoy 2022-07-23 00:28:12 +03:00
parent 1c830b0853
commit 3817a1fe09

View File

@ -3,6 +3,7 @@ import * as React from "react";
import { FunctionComponent } from "react";
import { Context } from "../context/context";
import { getColorByBrightness } from "../util/ColorUtil";
import CircularPanel from "./CircularPanel";
function getInfoPanelTextByGameState(params: {
context: Context;
@ -10,7 +11,6 @@ function getInfoPanelTextByGameState(params: {
crashMessage?: string;
userKey?: string;
userKeyWhoLeave?: string;
searchingOpponent: boolean;
}): string | undefined {
const {
context,
@ -18,11 +18,8 @@ function getInfoPanelTextByGameState(params: {
crashMessage,
userKey,
userKeyWhoLeave,
searchingOpponent,
} = params;
if (searchingOpponent) {
return context.texts.SearchingOpponent + " " + context.texts.PleaseWait;
} else if (crashMessage) {
if (crashMessage) {
return context.texts.GameCrashed + " " + crashMessage;
} else if (userKeyWhoLeave) {
let message = context.texts.OpponentLeavesTheGame;
@ -50,44 +47,24 @@ function getInfoPanelTextByGameState(params: {
return undefined;
}
const InfoPanelContainer: FunctionComponent<{
context: Context;
color: string;
}> = (props) => {
return (
<div
style={{
background: props.color
}}
>
<style jsx>{`
div {
padding: 1vw 2vw;
margin-top: 1vw;
border-radius: 10vw;
}
`}
</style>
{props.children}
</div>
);
};
const InfoPanel: FunctionComponent<{
context: Context;
game?: MancalaGame;
crashMessage?: string;
userKey?: string;
userKeyWhoLeave?: string;
searchingOpponent: boolean;
style?: React.CSSProperties;
visible?: boolean;
}> = ({
context,
game,
crashMessage,
userKey,
userKeyWhoLeave,
searchingOpponent,
style,
visible
}) => {
if (visible === false) return <></>;
const isUserTurn = userKey ? game?.checkIsPlayerTurn(userKey) : false;
const containerColor = isUserTurn
? context.themeManager.theme.playerTurnColor
@ -102,16 +79,15 @@ const InfoPanel: FunctionComponent<{
game,
crashMessage,
userKey,
userKeyWhoLeave,
searchingOpponent,
userKeyWhoLeave
});
if (text) {
return (
<InfoPanelContainer context={context} color={containerColor}>
<CircularPanel style={style} color={containerColor}>
<h4 style={{ margin: "0", color: textColor }}>
{text}
</h4>
</InfoPanelContainer>
</CircularPanel>
);
} else {
return (<div></div>)