Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
DEFAULT_SOUND_TYPE_KEY,
} from "./components/features/sound/sound";
import DynamicBackground from "./components/common/DynamicBackground";
import GameComponent from "./components/features/game";

function App() {
// localStorage persist theme setting
Expand Down Expand Up @@ -82,17 +83,27 @@ function App() {
false,
"IsInWordsCardMode"
);
const [isGameMode, setIsGameMode] = useLocalPersistState(
false,
"IsInGameMode"
);

const isWordGameMode =
gameMode === GAME_MODE_DEFAULT &&
!isCoffeeMode &&
!isTrainerMode &&
!isWordsCardMode && !isGameMode;
const isInGameMode =
gameMode === GAME_MODE &&
!isCoffeeMode &&
!isTrainerMode &&
!isWordsCardMode;
const isSentenceGameMode =
gameMode === GAME_MODE_SENTENCE &&
!isCoffeeMode &&
!isTrainerMode &&
!isWordsCardMode;
!isWordsCardMode &&
!isGameMode;

const handleThemeChange = (e) => {
window.localStorage.setItem("theme", JSON.stringify(e.value));
Expand All @@ -119,22 +130,11 @@ function App() {
setIsUltraZenMode(!isUltraZenMode);
};

const toggleCoffeeMode = () => {
setIsCoffeeMode(!isCoffeeMode);
setIsTrainerMode(false);
setIsWordsCardMode(false);
};

const toggleTrainerMode = () => {
setIsTrainerMode(!isTrainerMode);
setIsCoffeeMode(false);
setIsWordsCardMode(false);
};

const toggleWordsCardMode = () => {
setIsTrainerMode(false);
setIsCoffeeMode(false);
setIsWordsCardMode(!isWordsCardMode);
const toggleMode = (mode) => {
setIsTrainerMode( mode === "trainer" && !isTrainerMode);
setIsCoffeeMode( mode === "coffee" && !isCoffeeMode);
setIsWordsCardMode( mode === "wordsCard" && !isWordsCardMode);
setIsGameMode( mode === "game" && !isGameMode);
};

useEffect(() => {
Expand All @@ -159,6 +159,9 @@ function App() {
const focusSentenceInput = () => {
sentenceInputRef.current && sentenceInputRef.current.focus();
};
const focusGameInput = () => {
textInputRef.current && textInputRef.current.focus();
};

useEffect(() => {
if (isWordGameMode) {
Expand All @@ -173,6 +176,10 @@ function App() {
focusTextArea();
return;
}
if (isInGameMode) {
focusGameInput();
return;
}
return;
}, [
theme,
Expand All @@ -183,6 +190,7 @@ function App() {
isSentenceGameMode,
soundMode,
soundType,
isInGameMode
]);

return (
Expand All @@ -204,6 +212,20 @@ function App() {
handleInputFocus={() => focusTextInput()}
></TypeBox>
)}
{
isGameMode && (
<GameComponent
isUltraZenMode={isUltraZenMode}
textInputRef={textInputRef}
isFocusedMode={isFocusedMode}
soundMode={soundMode}
theme={theme}
soundType={soundType}
key="type-box"
handleInputFocus={() => focusTextInput()}
></GameComponent>
)
}
{isSentenceGameMode && (
<SentenceBox
sentenceInputRef={sentenceInputRef}
Expand Down Expand Up @@ -244,17 +266,16 @@ function App() {
handleThemeChange={handleThemeChange}
toggleFocusedMode={toggleFocusedMode}
toggleMusicMode={toggleMusicMode}
toggleCoffeeMode={toggleCoffeeMode}
isCoffeeMode={isCoffeeMode}
isMusicMode={isMusicMode}
isUltraZenMode={isUltraZenMode}
isFocusedMode={isFocusedMode}
gameMode={gameMode}
handleGameModeChange={handleGameModeChange}
isTrainerMode={isTrainerMode}
toggleTrainerMode={toggleTrainerMode}
isWordsCardMode={isWordsCardMode}
toggleWordsCardMode={toggleWordsCardMode}
isGameMode={isGameMode}
toggleMode={toggleMode}
></FooterMenu>
</div>
<MusicPlayerSnackbar
Expand Down
25 changes: 17 additions & 8 deletions src/components/common/FooterMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import IconButton from "@mui/material/IconButton";
import SelfImprovementIcon from "@mui/icons-material/SelfImprovement";
import VolumeUpIcon from "@mui/icons-material/VolumeUp";
import Select from "../utils/Select";
import SportsEsportsIcon from '@mui/icons-material/SportsEsports';
import {
FOCUS_MODE,
FREE_MODE,
Expand All @@ -18,6 +19,7 @@ import {
TRAINER_MODE,
WORDS_CARD_MODE,
ULTRA_ZEN_MODE,
GAME_MODE,
} from "../../constants/Constants";
import { Link } from "@mui/material";
import SupportMe from "../features/SupportMe";
Expand Down Expand Up @@ -49,21 +51,20 @@ const FooterMenu = ({
toggleMusicMode,
toggleUltraZenMode,
isUltraZenMode,
toggleCoffeeMode,
isMusicMode,
isFocusedMode,
isCoffeeMode,
gameMode,
handleGameModeChange,
isTrainerMode,
toggleTrainerMode,
isWordsCardMode,
isWordGameMode,
toggleWordsCardMode,
isGameMode,
toggleMode
}) => {
const isSiteInfoDisabled = isMusicMode || isFocusedMode;
const isBottomLogoEnabled = isFocusedMode && !isMusicMode;
const isTypeTestEnabled = !isCoffeeMode && !isTrainerMode && !isWordsCardMode;
const isTypeTestEnabled = !isCoffeeMode && !isTrainerMode && !isWordsCardMode && !isGameMode;

const getModeButtonClassName = (mode) => {
if (mode) {
Expand Down Expand Up @@ -96,7 +97,6 @@ const FooterMenu = ({
onChange={handleThemeChange}
menuPlacement="top"
></Select>

<IconButton onClick={toggleFocusedMode}>
<Tooltip title={FOCUS_MODE}>
<span className={getModeButtonClassName(isFocusedMode)}>
Expand All @@ -122,7 +122,7 @@ const FooterMenu = ({
menuPlacement="top"
></Select>
)}
<IconButton onClick={toggleWordsCardMode}>
<IconButton onClick={()=> {toggleMode("wordsCard")}}>
<Tooltip
title={
<span style={{ whiteSpace: "pre-line" }}>
Expand All @@ -135,7 +135,7 @@ const FooterMenu = ({
</span>
</Tooltip>
</IconButton>
<IconButton onClick={toggleCoffeeMode}>
<IconButton onClick={() => toggleMode("coffee")}>
<Tooltip
title={
<span style={{ whiteSpace: "pre-line" }}>{FREE_MODE}</span>
Expand All @@ -146,7 +146,7 @@ const FooterMenu = ({
</span>
</Tooltip>
</IconButton>
<IconButton onClick={toggleTrainerMode}>
<IconButton onClick={() => toggleMode("trainer")}>
<Tooltip title={TRAINER_MODE}>
<span className={getModeButtonClassName(isTrainerMode)}>
<KeyboardAltOutlinedIcon fontSize="medium"></KeyboardAltOutlinedIcon>
Expand All @@ -160,6 +160,15 @@ const FooterMenu = ({
</span>
</Tooltip>{" "}
</IconButton>
<IconButton onClick={()=> toggleMode("game")}>
<Tooltip title={
<span style={{ whiteSpace: "pre-line" }}>{GAME_MODE}</span>
}>
<span className={getModeButtonClassName(isGameMode)}>
<SportsEsportsIcon fontSize="medium"></SportsEsportsIcon>
</span>
</Tooltip>
</IconButton>
{isTypeTestEnabled && (
<>
<IconButton
Expand Down
27 changes: 13 additions & 14 deletions src/components/features/WordsCard/WordsCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const WordsCard = ({ soundType, soundMode }) => {

const [mode, setMode] = useLocalPersistState("vocab", "mode"); // selective, vocab

const [selectiveWord, setSelectiveWord] = useLocalPersistState("word","");
const [selectiveWord, setSelectiveWord] = useLocalPersistState("","word");

const [play] = useSound(SOUND_MAP[soundType], { volume: 0.5 });

Expand Down Expand Up @@ -489,18 +489,17 @@ const WordsCard = ({ soundType, soundMode }) => {
controlsList="nodownload nofullscreen noremoteplayback"
/>
</div>
{
mode === "vocab" &&
<div className="wordscard-UI-info">
{"Chapter " + currChapter.toUpperCase() + ": "} {index + 1} /{" "}
{currChapterCount}
</div>
}
{
mode === "selective" &&
<p>Selected Keys:</p>
}

{
mode === "vocab" &&
<div className="wordscard-UI-info">
{"Chapter " + currChapter.toUpperCase() + ": "} {index + 1} /{" "}
{currChapterCount}
</div>
}
{
mode === "selective" &&
<p>Selected Keys:</p>
}
<div className="restart-button" key="restart-button">
<Grid container justifyContent="center" alignItems="center">
{
Expand Down Expand Up @@ -567,7 +566,7 @@ const WordsCard = ({ soundType, soundMode }) => {
</Box>
}
</Grid>
<Box display="flex" flexDirection="row">
<Box display="flex" flexDirection="row" className="center-row">
<IconButton onClick={() => setMode("vocab")}>
<Tooltip title={VOCAB_MODE}>
<span className={getModeActivation("vocab")}>Vocab</span>
Expand Down
Loading