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

fix: link to video, add settings popover to dictionary #48

Merged
merged 4 commits into from
Apr 14, 2021
Merged
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
2 changes: 1 addition & 1 deletion src/components/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const MainPage: React.FC = () => {
playing={false}
width="100%"
height="500px"
url="https://www.youtube.com/watch?v=pCjBetzC8ME"
url="https://www.youtube.com/watch?v=48zbCLQa5MA"
controls
className={classes.video}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/MemoryGame/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ControlPanel: React.FC = () => {
const gameWords = useSelector((state: IAppState) => state.memoryGame.words);
const isLoggedIn = useSelector((state: IAppState) => state.user.isLoggedIn);
const userData = useSelector((state: IAppState) => state.user.data);
const volume = useSelector((state: IAppState) => state.settings.soundsVolume);
const { soundsVolume } = useSelector((state: IAppState) => state.settings);
const userDictionary = useSelector((state: IAppState) => state.userDictionary);
const userWords = [...userDictionary.learningWords, ...userDictionary.deletedWords];
const userWordsWords = userWords.map((uw) => uw.word);
Expand Down Expand Up @@ -68,7 +68,7 @@ const ControlPanel: React.FC = () => {

function playSound(audio: string) {
const player = new Audio(audio);
player.volume = volume / 100;
player.volume = soundsVolume / 100;
player.play();
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/MemoryGame/GameCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { get } from 'lodash';
import { Card, Typography } from '@material-ui/core';
import { showGameCard } from '../../store/actions/memoryGameActions';
import backendUrl, { GAMES, MEMORY } from '../../constants';
import backendUrl, { GAMES } from '../../constants';
import { ICardProps } from './types';
import { IAppState } from '../../store/types';
import { IMemoryGameCard } from '../../store/reducers/memoryGameReducer/types';
Expand All @@ -13,7 +13,7 @@ const GameCard: React.FC<ICardProps> = (props: ICardProps) => {
const classes = useStyles();
const dispatch = useDispatch();
const isGameStared = useSelector((state: IAppState) => state.memoryGame.isStarted);
const volume = useSelector((state: IAppState) => state.memoryGame.wordsVolume);
const soundsVolume = useSelector((state: IAppState) => state.settings.soundsVolume);

const handleGameMove = (event: React.SyntheticEvent) => {
if (!props.disabled && isGameStared) {
Expand All @@ -35,7 +35,7 @@ const GameCard: React.FC<ICardProps> = (props: ICardProps) => {

function handleAutoplay(audio: string) {
const player = new Audio(audio);
player.volume = volume / MEMORY.gameWordsMaxVolumeLevel;
player.volume = soundsVolume / 100;
player.play();
}

Expand Down
11 changes: 6 additions & 5 deletions src/components/MemoryGame/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import {
Typography,
} from '@material-ui/core';
import { VolumeUp, Settings } from '@material-ui/icons';
import { initiateGameField, setWordsVolumeLevel } from '../../store/actions/memoryGameActions';
import { initiateGameField } from '../../store/actions/memoryGameActions';
import { WORDBOOK_GROUPS, GAMES, MEMORY } from '../../constants';
import { SELECT_ROUNDS } from '../GameSavannah/constants';
import { IAppState } from '../../store/types';
import useStyles from './styles';
import { changeVolumeSounds } from '../../store/actions/settingsActions';

type Anchor = 'left';

Expand Down Expand Up @@ -51,7 +52,7 @@ const SideMenu: React.FC = () => {
GAMES.memory.difficulty[gameLevelFromSettings].label
);

const wordsVolumeLevel = useSelector((state: IAppState) => state.memoryGame.wordsVolume);
const { soundsVolume } = useSelector((state: IAppState) => state.settings);

const handleChangeGameMode = (event: React.ChangeEvent<HTMLInputElement>) => {
setMode(event.target.checked ? 'image' : 'translation');
Expand Down Expand Up @@ -95,11 +96,11 @@ const SideMenu: React.FC = () => {
};

const handleVolumeLevelChange = (event: React.ChangeEvent<{}>, value: Number | Array<Number>) => {
dispatch(setWordsVolumeLevel(Number(value)));
dispatch(changeVolumeSounds(Number(value)));
};

const handleMaxVolume = () => {
dispatch(setWordsVolumeLevel(MEMORY.gameWordsMaxVolumeLevel));
dispatch(changeVolumeSounds(MEMORY.gameWordsMaxVolumeLevel));
};

useEffect(() => {
Expand Down Expand Up @@ -152,7 +153,7 @@ const SideMenu: React.FC = () => {
<Slider
min={MEMORY.gameWordsMinimalVolumeLevel}
max={MEMORY.gameWordsMaxVolumeLevel}
value={wordsVolumeLevel}
value={soundsVolume}
onChange={handleVolumeLevelChange}
aria-labelledby="continuous-slider"
/>
Expand Down
3 changes: 2 additions & 1 deletion src/components/UserDictionary/UserDictionary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppBar, Tab, Tabs, Typography, useTheme } from '@material-ui/core';
import UserDictionarySection from './UserDictionarySection';
import Header from '../Header';
import Footer from '../Footer';
import SettingsPopover from '../SettingsPopover';
import { fetchDictionary } from '../../store/actions/dictionaryActions';
import { IAppState } from '../../store/types';
import { TabPanelProps } from './types';
Expand Down Expand Up @@ -48,7 +49,7 @@ const UserDictionary: React.FC = () => {
<Header />
<main className={classes.main}>
<Typography variant="h5" className={classes.title}>
Мой словарь
Мой словарь <SettingsPopover />
</Typography>
{userData.userId ? (
<div className={classes.root}>
Expand Down
1 change: 1 addition & 0 deletions src/components/UserDictionary/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const useStyles = makeStyles((theme: Theme) => {
margin: '1rem 0',
textTransform: 'uppercase',
fontWeight: 500,
position: 'relative',
},
dictionary: {
display: 'flex',
Expand Down
9 changes: 8 additions & 1 deletion src/components/WordCard/WordCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import backendUrl, {
WORDBOOK_GROUPS,
WORDCARD_APPEAR_GAP,
} from '../../constants';
import { IAppState, IUserWord } from '../../store/types';
import { IAppState, IUserWord, IWord } from '../../store/types';
import { IWordCardButton, IWordCardProps } from './types';
import useStyles, { defaultImageSize, transitionStyles } from './styles';

Expand Down Expand Up @@ -60,6 +60,9 @@ const WordCard: React.FC<IWordCardProps> = ({
const colorOfDifficult = theme.palette.secondary.main;
const dispatch = useDispatch();

const { deletedWords } = useSelector((state: IAppState) => state.userDictionary);
const isInDeletedWords = deletedWords.map((el: IWord) => el.word).includes(word.word);

const textStyle = {
word: playingAudioIndex === 0 ? highlightStyle : {},
meaning: playingAudioIndex === 1 ? highlightStyle : {},
Expand Down Expand Up @@ -215,6 +218,10 @@ const WordCard: React.FC<IWordCardProps> = ({
};
}, []);

useEffect(() => {
setIsDeleted(isInDeletedWords);
}, [isInDeletedWords]);

return (
<Transition in={isMounted && !isLoading} timeout={APPEAR_DURATION} unmountOnExit>
{(state: TransitionStatus) => (
Expand Down