Skip to content

Commit 3caf6c8

Browse files
authored
Added Focus Mode (#179)
1 parent 1e59401 commit 3caf6c8

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

src/App.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function App() {
8989
);
9090
const [volume, setVolume] = useStorage("volume", "on");
9191
const [notifications, setNotifications] = useStorage("notifications", "on");
92+
const [focusMode, setFocusMode] = useStorage("focusMode", "off");
9293

9394
useEffect(() => {
9495
return firebase.auth().onAuthStateChanged((user) => {
@@ -162,6 +163,8 @@ function App() {
162163
setVolume,
163164
notifications,
164165
setNotifications,
166+
focusMode,
167+
setFocusMode,
165168
layoutOrientation,
166169
setLayoutOrientation,
167170
cardOrientation,

src/components/Navbar.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ function Navbar() {
115115
);
116116
}
117117

118+
function handleChangeFocusMode() {
119+
settings.setFocusMode((focusMode) => (focusMode === "on" ? "off" : "on"));
120+
}
121+
118122
useKeydown((event) => {
119123
if (getModifierState(event) === "Control") {
120124
if (event.key === "s") {
@@ -221,6 +225,14 @@ function Navbar() {
221225
{settings.notifications === "on" ? "Disable" : "Enable"}{" "}
222226
notifications
223227
</MenuItem>
228+
<MenuItem
229+
onClick={() => {
230+
handleChangeFocusMode();
231+
handleCloseMenu();
232+
}}
233+
>
234+
{settings.focusMode === "on" ? "Disable" : "Enable"} focus mode
235+
</MenuItem>
224236
<MenuItem
225237
onClick={() => {
226238
handleChangeTheme();

src/pages/GamePage.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function ensureConnected() {
111111

112112
function GamePage({ match }) {
113113
const user = useContext(UserContext);
114-
const { volume, notifications } = useContext(SettingsContext);
114+
const { volume, notifications, focusMode } = useContext(SettingsContext);
115115
const gameId = match.params.id;
116116
const nextGameId = useMemo(() => getNextGameId(gameId), [gameId]);
117117
const classes = useStyles();
@@ -432,16 +432,18 @@ function GamePage({ match }) {
432432
<Grid container spacing={2}>
433433
<Box clone order={{ xs: 3, sm: 1 }}>
434434
<Grid item xs={12} sm={4} md={3} className={classes.sideColumn}>
435-
<Paper style={{ display: "flex", height: "100%", padding: 8 }}>
436-
<Chat
437-
title="Game Chat"
438-
messageLimit={200}
439-
gameId={gameId}
440-
history={history}
441-
startedAt={game.startedAt}
442-
gameMode={gameMode}
443-
/>
444-
</Paper>
435+
{(focusMode !== "on" || gameEnded) && (
436+
<Paper style={{ display: "flex", height: "100%", padding: 8 }}>
437+
<Chat
438+
title="Game Chat"
439+
messageLimit={200}
440+
gameId={gameId}
441+
history={history}
442+
startedAt={game.startedAt}
443+
gameMode={gameMode}
444+
/>
445+
</Paper>
446+
)}
445447
</Grid>
446448
</Box>
447449
<Box clone order={{ xs: 1, sm: 2 }} position="relative">
@@ -510,21 +512,23 @@ function GamePage({ match }) {
510512
</Box>
511513
<Box clone order={{ xs: 2, sm: 3 }}>
512514
<Grid item xs={12} md={3} className={classes.sideColumn}>
513-
<Box order={{ xs: 2, md: 1 }} style={{ maxHeight: "100%" }}>
514-
<GameSidebar
515-
game={game}
516-
scores={scores}
517-
leaderboard={leaderboard}
518-
pause={gameData.pause}
519-
endedAt={
520-
game.status === "done"
521-
? game.endedAt
522-
: !answer && history.length > 0
523-
? history[history.length - 1].time
524-
: 0
525-
}
526-
/>
527-
</Box>
515+
{(focusMode !== "on" || gameEnded) && (
516+
<Box order={{ xs: 2, md: 1 }} style={{ maxHeight: "100%" }}>
517+
<GameSidebar
518+
game={game}
519+
scores={scores}
520+
leaderboard={leaderboard}
521+
pause={gameData.pause}
522+
endedAt={
523+
game.status === "done"
524+
? game.endedAt
525+
: !answer && history.length > 0
526+
? history[history.length - 1].time
527+
: 0
528+
}
529+
/>
530+
</Box>
531+
)}
528532
{game.enableHint && (
529533
<Box order={{ xs: 1, md: 2 }}>
530534
<Box mt={{ xs: 0, md: 2 }} mb={1}>

0 commit comments

Comments
 (0)