Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/OpentypeV2 #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
50 changes: 28 additions & 22 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { useDetectDevice } from './hooks/useDetectDevice';
import { useSystem } from './hooks/useSystem';
import { useThemeContext } from './hooks/useTheme';
import { useDetectDevice } from "./hooks/useDetectDevice";
import { useSystem } from "./hooks/useSystem";
import { useThemeContext } from "./hooks/useTheme";

import AboutPage from './components/About';
import Countdown from './components/Countdown';
import Footer from './components/Footer';
import Header from './components/Header';
import ModalComponent from './components/Modal';
import ModalContent from './components/ModalContent';
import Restart from './components/Restart';
import TimeCategory from './components/TimeCategory';
import UserTyped from './components/UserTyped';
import WordContainer from './components/WordContainer';
import WordWrapper from './components/WordWrapper';
import MobileNotSupported from './components/MobileNotSupported';
import AboutPage from "./components/About";
import Countdown from "./components/Countdown";
import Footer from "./components/Footer";
import Header from "./components/Header";
import ModalComponent from "./components/Modal";
import ModalContent from "./components/ModalContent";
import TimeCategory from "./components/TimeCategory";
import UserTyped from "./components/UserTyped";
import WordContainer from "./components/WordContainer";
import WordWrapper from "./components/WordWrapper";
import MobileNotSupported from "./components/MobileNotSupported";
import Wordschange from "./components/Restart";

function App() {
const { systemTheme } = useThemeContext();

const {
level,
charTyped,
countdown,
word,
Expand All @@ -35,20 +37,22 @@ function App() {
closeModal,
openModal,
setTime,
changeParagraph,
increaseLevel,
decreaseLevel,
} = useSystem();

const isMobile = useDetectDevice();

return (
<div
className='h-screen w-full overflow-y-auto'
className="h-screen w-full overflow-y-auto"
style={{
backgroundColor: systemTheme.background.primary,
color: systemTheme.text.primary,
}}
>
<main
className=' mx-auto flex h-full max-w-5xl flex-col gap-4 px-4 xl:px-0'
className=" mx-auto flex h-full max-w-5xl flex-col gap-4 px-4 xl:px-0"
style={{}}
>
{isMobile ? (
Expand All @@ -61,10 +65,13 @@ function App() {
closeAboutModal={closeModal}
/>
<TimeCategory
level={level}
time={time}
setLocalStorage={setLocalStorageValue}
setTime={setTime}
restart={restartTest}
increaseLevel={increaseLevel}
decreaseLevel={decreaseLevel}
/>
<Countdown countdown={countdown} reset={resetCountdown} />
<WordWrapper
Expand All @@ -78,10 +85,10 @@ function App() {
charTyped={charTyped}
/>
</WordWrapper>
<Restart restart={restartTest} />
<Wordschange restart={restartTest} changeWords={changeParagraph} />
<Footer />
<ModalComponent
type='result'
type="result"
isOpen={modalIsOpen}
onRequestClose={closeModal}
>
Expand All @@ -91,9 +98,8 @@ function App() {
history={history}
/>
</ModalComponent>

<ModalComponent
type='about'
type="about"
isOpen={aboutModal}
onRequestClose={closeModal}
>
Expand Down
30 changes: 16 additions & 14 deletions src/components/Restart.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import styled from 'styled-components';
import { MdRestartAlt } from 'react-icons/md';
import styled from "styled-components";
import { MdRestartAlt } from "react-icons/md";

import { useThemeContext } from '../hooks/useTheme';
import { useThemeContext } from "../hooks/useTheme";

import Tooltip from './Tooltip';
import Tooltip from "./Tooltip";

type RestartProps = {
type Wordschangeprops = {
restart: () => void;
changeWords: () => void;
};

const StyledButton = styled.button`
Expand All @@ -16,28 +17,29 @@ const StyledButton = styled.button`
}
`;

const Restart = ({ restart }: RestartProps) => {
const Wordschange = ({ restart, changeWords }: Wordschangeprops) => {
const { systemTheme } = useThemeContext();
return (
<div className='mt-10'>
<Tooltip tooltipId='Restart' delayHide={200}>
<div className='flex items-center justify-center'>
<div className="mt-10">
<Tooltip tooltipId="Restart" delayHide={200}>
<div className="flex items-center justify-center">
<StyledButton
theme={systemTheme}
onClick={() => {
restart();
changeWords();
}}
className={`rotate-0 rounded-full p-3 transition delay-200 ease-out hover:rotate-180 `}
data-tooltip-id='Restart'
data-tooltip-content='Restart Test'
data-tooltip-place='bottom'
data-tooltip-id="Restart"
data-tooltip-content="Change Words"
data-tooltip-place="bottom"
>
<MdRestartAlt className='text-2xl lg:text-3xl ' />
<MdRestartAlt className="text-2xl lg:text-3xl " />
</StyledButton>
</div>
</Tooltip>
</div>
);
};

export default Restart;
export default Wordschange;
81 changes: 65 additions & 16 deletions src/components/TimeCategory.tsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,128 @@
import { useContext } from 'react';
import { useContext } from "react";

import { BiTimer } from 'react-icons/bi';
import { BiTimer } from "react-icons/bi";

import { ThemeContext } from '../context/ThemeContext';
import { Theme } from '../types';
import { ThemeContext } from "../context/ThemeContext";
import { Theme } from "../types";

type TimeCategoryProps = {
level: number;
time: number;
setTime: (value: number) => void;
setLocalStorage: (key: string, value: number | Theme) => void;
restart: () => void;
increaseLevel: () => void;
decreaseLevel: () => void;
};

const TimeCategory = ({
level,
time,
setTime,
restart,
setLocalStorage,
increaseLevel,
decreaseLevel,
}: TimeCategoryProps) => {
const { systemTheme } = useContext(ThemeContext);

return (
<div className='flex items-center justify-center gap-3'>
<BiTimer className='text-3xl' />
<div className="flex items-center justify-center gap-3">
<BiTimer className="text-3xl" />
<div
className='flex gap-4 rounded-lg'
className="rounded-xlg flex gap-4 pl-2 pr-2"
style={{
backgroundColor: systemTheme.background.secondary,
}}
>
<button
className={`category ${
level === 30 ? "font-bold underline" : ""
} hover:underline`}
onClick={() => {
decreaseLevel();
restart();
}}
style={{
color: level === 30 ? systemTheme.text.secondary : "",
}}
>
Easy
</button>
<span
className={`category ${
time === 15000 ? 'font-bold underline' : ''
time === 15000 ? "font-bold underline" : ""
} hover:underline`}
onClick={() => {
setTime(15000);
setLocalStorage('time', 15000);
setLocalStorage("time", 15000);
restart();
}}
style={{
color: time === 15000 ? systemTheme.text.secondary : '',
color: time === 15000 ? systemTheme.text.secondary : "",
}}
>
15s
</span>
<span
className={`category ${
time === 30000 ? 'font-bold underline' : ''
time === 30000 ? "font-bold underline" : ""
} hover:underline`}
onClick={() => {
setTime(30000);
setLocalStorage('time', 30000);
setLocalStorage("time", 30000);
restart();
}}
style={{
color: time === 30000 ? systemTheme.text.secondary : '',
color: time === 30000 ? systemTheme.text.secondary : "",
}}
>
30s
</span>
<span
className={`category ${
time === 60000 ? 'font-bold underline' : ''
time === 60000 ? "font-bold underline" : ""
} hover:underline`}
onClick={() => {
setTime(60000);
setLocalStorage('time', 60000);
setLocalStorage("time", 60000);
restart();
}}
style={{
color: time === 60000 ? systemTheme.text.secondary : '',
color: time === 60000 ? systemTheme.text.secondary : "",
}}
>
60s
</span>
<span
className={`category ${
time === 120000 ? "font-bold underline" : ""
} hover:underline`}
onClick={() => {
setTime(120000);
setLocalStorage("time", 120000);
restart();
}}
style={{
color: time === 120000 ? systemTheme.text.secondary : "",
}}
>
120s
</span>
<button
className={`category ${
level === 50 ? "font-bold underline" : ""
} hover:underline`}
onClick={() => {
increaseLevel();
restart();
}}
style={{
color: level === 50 ? systemTheme.text.secondary : "",
}}
>
Hard
</button>
</div>
</div>
);
Expand Down
18 changes: 11 additions & 7 deletions src/components/UserTyped.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useMemo } from 'react';
import styled from 'styled-components';
import { useMemo } from "react";
import styled from "styled-components";

import { useThemeContext } from '../hooks/useTheme';
import Character from './Character';
import { useThemeContext } from "../hooks/useTheme";
import Character from "./Character";

type UserTypedProps = {
charTyped: string;
Expand All @@ -20,19 +20,23 @@ const StyledDiv = styled.div`

const UserTyped = ({ check, charTyped, word }: UserTypedProps) => {
const characters = useMemo(() => {
return charTyped.split('');
return charTyped.split("");
}, [charTyped]);

const { systemTheme } = useThemeContext();

return (
<StyledDiv
className='md:character absolute left-0 top-0 z-10 break-all font-mono text-xl lg:text-2xl'
className="md:character absolute left-0 top-0 z-10 break-all font-mono text-xl lg:text-2xl"
theme={systemTheme}
>
{characters.map((_, index) => {
return (
<Character character={word.charAt(index)} state={check(index)} />
<Character
key={index}
character={word.charAt(index)}
state={check(index)}
/>
);
})}
</StyledDiv>
Expand Down
Loading