Merge pull request #11 from jhalitaksoy/fix/theme-switch-issue

fix/theme switch issue
This commit is contained in:
Halit Aksoy 2022-07-09 13:20:15 +03:00 committed by GitHub
commit 466ca96406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,7 @@ import { Menu, MenuButton, MenuItem } from "@szhsin/react-menu";
import "@szhsin/react-menu/dist/index.css";
import "@szhsin/react-menu/dist/transitions/slide.css";
import { getColorByLuminance } from "./util/ColorUtil";
import { Theme } from "./theme/Theme";
type ConnectionState = "connecting" | "error" | "connected" | "reconnecting";
@ -45,6 +46,8 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
const [pitAnimator, setPitAnimator] = useState<PitAnimator>();
const [theme, setTheme] = useState<Theme | undefined>(undefined);
const onConnectionDone = () => {
setConnetionState("connected");
};
@ -111,6 +114,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
};
React.useEffect(() => {
setTheme(context.themeManager.theme);
const pitAnimator = new PitAnimator(context, updateBoardViewModel);
setPitAnimator(pitAnimator);
listenMessages(pitAnimator);
@ -121,8 +125,9 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
}, []);
React.useEffect(() => {
context.themeManager.onThemeChange = () => {
updateBoardViewModel(pitAnimator.getBoardViewModelFromGame(game));
context.themeManager.onThemeChange = (theme) => {
setTheme(theme);
pitAnimator && updateBoardViewModel(pitAnimator.getBoardViewModelFromGame(game));
};
}, [boardViewModel]);
@ -206,7 +211,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
display: "flex",
flexDirection: "column",
alignItems: "center",
background: context.themeManager.theme.background,
background: theme?.background,
flex: "1",
}}
>