little fixes
This commit is contained in:
parent
6c466d95a1
commit
69c1ca8359
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import cls from './App.module.scss';
|
import cls from './App.module.scss';
|
||||||
import MatchGame from './components/MatchGame/MatchGame';
|
import MatchGame from 'components/MatchGame/MatchGame';
|
||||||
import { MatchGameProvider } from './context/MatchGameContext';
|
import { MatchGameProvider } from 'context/MatchGameContext';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import { useMatchGame } from '../../context/MatchGameContext';
|
import { useMatchGame } from 'context/MatchGameContext';
|
||||||
import Button from '../UI/Button/Button';
|
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import Timer from '../UI/Timer/Timer';
|
|
||||||
|
import Button from 'components/UI/Button/Button';
|
||||||
|
import Timer from 'components/UI/Timer/Timer';
|
||||||
|
|
||||||
import cls from './BottomPanel.module.scss';
|
import cls from './BottomPanel.module.scss';
|
||||||
|
|
||||||
type BottomPanelProps = {
|
type BottomPanelProps = {
|
||||||
@ -17,6 +19,7 @@ const BottomPanel: React.FC<BottomPanelProps> = (props) => {
|
|||||||
const [isTimerStarted, setIsTimerStarted] = useState(false);
|
const [isTimerStarted, setIsTimerStarted] = useState(false);
|
||||||
const [isTimerStopped, setIsTimerStopped] = useState(false);
|
const [isTimerStopped, setIsTimerStopped] = useState(false);
|
||||||
const [panelState, setPanelState] = useState<PanelState>('start');
|
const [panelState, setPanelState] = useState<PanelState>('start');
|
||||||
|
const {changeGameTime} = useMatchGame();
|
||||||
|
|
||||||
function onStartBtnClickHandler(event: React.MouseEvent<HTMLButtonElement>) {
|
function onStartBtnClickHandler(event: React.MouseEvent<HTMLButtonElement>) {
|
||||||
setIsTimerStarted(true);
|
setIsTimerStarted(true);
|
||||||
@ -51,7 +54,7 @@ const BottomPanel: React.FC<BottomPanelProps> = (props) => {
|
|||||||
|
|
||||||
function renderStartStatePanel() {
|
function renderStartStatePanel() {
|
||||||
return isTimerStarted
|
return isTimerStarted
|
||||||
? <Timer isStarted={isTimerStarted} startTime={0} isFinished={isTimerStopped}/>
|
? <Timer isStarted={isTimerStarted} startTime={0} isFinished={isTimerStopped} changeTime={changeGameTime}/>
|
||||||
: <>
|
: <>
|
||||||
<Button onClick={onStartBtnClickHandler}>START</Button>
|
<Button onClick={onStartBtnClickHandler}>START</Button>
|
||||||
<Button onClick={onShuffleBtnClickHandler}>SHUFFLE</Button>
|
<Button onClick={onShuffleBtnClickHandler}>SHUFFLE</Button>
|
||||||
|
|||||||
@ -40,7 +40,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.backside {
|
.backside {
|
||||||
//background: #aee571;
|
|
||||||
transform: rotateY(180deg);
|
transform: rotateY(180deg);
|
||||||
font-size: 40px;
|
font-size: 40px;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import React, { useMemo, useState } from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import cls from './Card.module.scss'
|
import cls from './Card.module.scss'
|
||||||
|
|
||||||
export type CardComponentProps = {
|
export type CardComponentProps = {
|
||||||
@ -27,7 +28,7 @@ const Card: React.FC<CardComponentProps> = (props) => {
|
|||||||
style={{opacity: props.isMatched ? 0 : 1}}
|
style={{opacity: props.isMatched ? 0 : 1}}
|
||||||
onClick={() => cardClickHandler(props.id)}
|
onClick={() => cardClickHandler(props.id)}
|
||||||
>
|
>
|
||||||
<div className={classes.join(' ')}>
|
<div className={classes.join(' ')} tabIndex={-1}>
|
||||||
<div className={cls.frontside}>{props.title}</div>
|
<div className={cls.frontside}>{props.title}</div>
|
||||||
<div className={cls.backside}>
|
<div className={cls.backside}>
|
||||||
<img src={props.imageURL} alt={props.title}/>
|
<img src={props.imageURL} alt={props.title}/>
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { useMatchGame } from '../../context/MatchGameContext';
|
|
||||||
import Card, { CardComponentProps } from '../Card/Card';
|
import { useMatchGame } from 'context/MatchGameContext';
|
||||||
|
import Card, { CardComponentProps } from 'components/Card/Card';
|
||||||
|
|
||||||
import cls from './CardsField.module.scss';
|
import cls from './CardsField.module.scss';
|
||||||
|
|
||||||
type CardProps = {
|
type CardProps = {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useMatchGame } from '../../context/MatchGameContext';
|
|
||||||
import cls from './FinishedField.module.scss';
|
import cls from './FinishedField.module.scss';
|
||||||
|
|
||||||
type FinishedFieldProps = {
|
type FinishedFieldProps = {
|
||||||
@ -8,8 +8,6 @@ type FinishedFieldProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const FinishedField: React.FC<FinishedFieldProps> = ({mistakesCount, gameTime}) => {
|
const FinishedField: React.FC<FinishedFieldProps> = ({mistakesCount, gameTime}) => {
|
||||||
// const {mistakesCount, gameTime} = useMatchGame();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cls.FinishedField}>
|
<div className={cls.FinishedField}>
|
||||||
<h1>GAME IS FINISHED !</h1>
|
<h1>GAME IS FINISHED !</h1>
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { cardImages } from '../../constants';
|
|
||||||
import { useMatchGame } from '../../context/MatchGameContext';
|
import BottomPanel from 'components/BottomPanel/BottomPanel';
|
||||||
import { randomizeElementInArray } from '../../utils';
|
import CardsField from 'components/CardsField/CardsField';
|
||||||
import BottomPanel from '../BottomPanel/BottomPanel';
|
import FinishedField from 'components/FinishedField/FinishedField';
|
||||||
import CardsField from '../CardsField/CardsField';
|
import { cardImages } from 'src/constants';
|
||||||
import FinishedField from '../FinishedField/FinishedField';
|
import { randomizeElementInArray } from 'src/utils';
|
||||||
import cls from './MatchGame.module.scss';
|
import { useMatchGame } from 'context/MatchGameContext';
|
||||||
|
|
||||||
|
import cls from './MatchGame.module.scss'
|
||||||
|
|
||||||
const MatchGame: React.FC = () => {
|
const MatchGame: React.FC = () => {
|
||||||
// TODO replace to CardsField
|
// TODO replace to CardsField
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
box-shadow: 0 8px 15px rgba(0, 0, 0, .1);
|
box-shadow: 0 8px 15px rgba(0, 0, 0, .1);
|
||||||
transition: .3s;
|
transition: .3s;
|
||||||
|
|
||||||
&:hover {
|
&:hover, &:focus {
|
||||||
background: #7986cb;
|
background: #7986cb;
|
||||||
box-shadow: 0 15px 20px rgba(121, 134, 203, 0.4);
|
box-shadow: 0 15px 20px rgba(121, 134, 203, 0.4);
|
||||||
color: white;
|
color: white;
|
||||||
|
|||||||
@ -1,18 +1,20 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useMatchGame } from '../../../context/MatchGameContext';
|
|
||||||
import { getTimeString } from '../../../utils';
|
import { useMatchGame } from 'context/MatchGameContext';
|
||||||
|
import { getTimeString } from 'src/utils';
|
||||||
|
|
||||||
import cls from './Timer.module.scss'
|
import cls from './Timer.module.scss'
|
||||||
|
|
||||||
type TimerProps = {
|
type TimerProps = {
|
||||||
startTime: number;
|
startTime: number;
|
||||||
isStarted: boolean;
|
isStarted: boolean;
|
||||||
isFinished: boolean;
|
isFinished: boolean;
|
||||||
|
changeTime?: (time: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Timer: React.FC<TimerProps> = ({startTime, isStarted, isFinished}) => {
|
const Timer: React.FC<TimerProps> = ({startTime, isStarted, isFinished, changeTime}) => {
|
||||||
const [time, setTime] = useState(startTime);
|
const [time, setTime] = useState(startTime);
|
||||||
const [timeInterval, setTimeInterval] = useState<NodeJS.Timer | null>(null)
|
const [timeInterval, setTimeInterval] = useState<NodeJS.Timer | null>(null)
|
||||||
const {changeGameTime} = useMatchGame();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isStarted) return;
|
if (!isStarted) return;
|
||||||
@ -25,7 +27,7 @@ const Timer: React.FC<TimerProps> = ({startTime, isStarted, isFinished}) => {
|
|||||||
}, [isFinished])
|
}, [isFinished])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changeGameTime?.(time);
|
changeTime?.(time);
|
||||||
}, [time])
|
}, [time])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import React, { useContext, useState } from 'react';
|
import React, { useContext, useState } from 'react';
|
||||||
import { getTimeString } from '../utils';
|
import { getTimeString } from 'src/utils';
|
||||||
|
|
||||||
type MatchGameContextType = {
|
type MatchGameContextType = {
|
||||||
mistakesCount?: number;
|
mistakesCount?: number;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user