Skip to content

Commit

Permalink
adjective quiz option to toggle romaji hint
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismitch committed Oct 31, 2019
1 parent e9f70c0 commit f038a69
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/components/quizes/Adjectives.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
import React, { useState } from 'react';
import { Helmet } from 'react-helmet';
import styled from '@emotion/styled';
import useCookie from 'react-use-cookie';
import VocabularyQuiz from '../VocabularyQuiz';
import QuizIntro from '../QuizIntro';
import adjectives from '../../lib/adjectives.json';

interface SettingObject {
showRomaji?: boolean;
}

const OptionsForm = styled.form`
margin-bottom: 1em;
`;

const OptionCheck = styled.input`
margin-right: 1em;
margin-bottom: 1em;
`;

const getInitialSettings = (): string => {
return JSON.stringify({
showRomaji: true,
});
};

const Adjectives = () => {
const [startQuiz, setStartQuiz] = useState(false);
const [settings, setSettings] = useCookie('vocabularyQuiz', getInitialSettings());
const settingsObj = JSON.parse(settings);

const randomizedAdjectives = adjectives.vocabulary.sort(
() => 0.5 - Math.random()
);

const setSettingsOption = (setting: SettingObject) => {
setSettings(
JSON.stringify({
...settingsObj,
...setting,
})
);
};

return (
<>
<Helmet>
Expand All @@ -20,7 +53,7 @@ const Adjectives = () => {
words={randomizedAdjectives}
placeholder="Enter english translation"
question="hiragana"
hint="romaji"
hint={settingsObj.showRomaji ? "romaji" : ""}
/>
) : (
<QuizIntro
Expand All @@ -33,7 +66,26 @@ const Adjectives = () => {
</span>
}
onStart={() => setStartQuiz(true)}
/>
>

<OptionsForm>
<div>
<label>
<OptionCheck
name="showRomaji"
type="checkbox"
checked={settingsObj.showRomaji}
onChange={() =>
setSettingsOption({
showRomaji: !settingsObj.showRomaji,
})
}
/>
<strong>Show Romaji</strong>
</label>
</div>
</OptionsForm>
</QuizIntro>
)}
</>
);
Expand Down

0 comments on commit f038a69

Please sign in to comment.