Skip to content

Commit

Permalink
Russian bible sentences
Browse files Browse the repository at this point in the history
  • Loading branch information
nluka committed Mar 12, 2023
1 parent 5a9d181 commit 5622206
Show file tree
Hide file tree
Showing 16 changed files with 31,825 additions and 2,628 deletions.
5,935 changes: 3,360 additions & 2,575 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "keycap-client",
"version": "1.0.2",
"version": "2.2.0",
"directories": {
"doc": "docs"
},
Expand Down
28,259 changes: 28,259 additions & 0 deletions public/russian-bible-sentences.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import React from 'react';
import { useAppSelector } from '../../../../../../redux/hooks';
import { PRACTICE_SETTINGS_QUOTE_LENGTH_LIMITS } from '../../../../../../utility/constants';
import { PRACTICE_SETTINGS_ENGLISH_QUOTE_LENGTH_RANGE_LIMITS } from '../../../../../../utility/constants';
import convertNumberRangeToQuoteLength from '../../../../../../utility/functions/convertNumberRangeToQuoteLength';
import convertQuoteLengthToNumberRange from '../../../../../../utility/functions/convertQuoteLengthToNumberRange';
import PracticeSettingsBasicCardInputNumberRange from '../Input/NumberRange/PracticeSettingsBasicCardInputNumberRange';
import PracticeSettingsBasicCard from '../PracticeSettingsBasicCard';

export default function PracticeSettingsBasicCardQuoteLength() {
export default function PracticeSettingsBasicCardEnglishQuoteLengthRange() {
return (
<PracticeSettingsBasicCard name="quoteLength" title="Quote Length">
<PracticeSettingsBasicCard
name="englishQuoteLengthRange"
title={
<>
English Quote
<br />
Length Range
</>
}
>
<Input />
</PracticeSettingsBasicCard>
);
}

function Input() {
const quoteLength = useAppSelector(
(state) => state.practice.settings.current.quoteLength,
(state) => state.practice.settings.current.englishQuoteLengthRange,
);

return (
Expand All @@ -28,8 +37,8 @@ function Input() {
>
<PracticeSettingsBasicCardInputNumberRange
converter={convertNumberRangeToQuoteLength}
limits={PRACTICE_SETTINGS_QUOTE_LENGTH_LIMITS}
name="quoteLength"
limits={PRACTICE_SETTINGS_ENGLISH_QUOTE_LENGTH_RANGE_LIMITS}
name="englishQuoteLengthRange"
step={1}
value={convertQuoteLengthToNumberRange(quoteLength)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { useAppSelector } from '../../../../../../redux/hooks';
import { PRACTICE_SETTINGS_RUSSIAN_QUOTE_SENTENCES_LIMITS } from '../../../../../../utility/constants';
import PracticeSettingsBasicCardInputNumber from '../Input/Number/PracticeSettingsBasicCardInputNumber';
import PracticeSettingsBasicCard from '../PracticeSettingsBasicCard';

export default function PracticeSettingsBasicCardRussianQuoteSentences() {
return (
<PracticeSettingsBasicCard
name="russianQuoteSentences"
title={
<>
Russian
<br />
Quote
<br />
Sentences
</>
}
>
<Input />
</PracticeSettingsBasicCard>
);
}

function Input() {
const sentences = useAppSelector(
(state) => state.practice.settings.current.russianQuoteSentences,
);

return (
<div className="d-grid gap-2">
<PracticeSettingsBasicCardInputNumber
limits={PRACTICE_SETTINGS_RUSSIAN_QUOTE_SENTENCES_LIMITS}
name="russianQuoteSentences"
step={1}
value={sentences}
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Input() {
return (
<PracticeSettingsBasicCardInputRadio
name="textType"
options={['quote', 'medley', 'custom']}
options={['English quote', 'Russian bible', 'medley', 'custom']}
value={textType}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import PracticeSettingsBasicCardMedleyCollectionsActive from './Medley/Collectio
import PracticeSettingsBasicCardMedleyWordCount from './Medley/WordCount/PracticeSettingsBasicCardMedleyWordCount';
import PracticeSettingsBasicCardMedleyPunctuationFrequency from './Medley/PunctuationFrequency/PracticeSettingsBasicCardMedleyPunctuationFrequency';
import PracticeSettingsBasicCardMistakeHighlightStyle from './MistakeHighlightStyle/PracticeSettingsBasicCardMistakeHighlightStyle';
import PracticeSettingsBasicCardQuoteLength from './QuoteLength/PracticeSettingsBasicCardQuoteLength';
import PracticeSettingsBasicCardEnglishQuoteLengthRange from './EnglishQuoteLength/PracticeSettingsBasicCardEnglishQuoteLengthRange';
import PracticeSettingsBasicCardTextCasing from './Text/Casing/PracticeSettingsBasicCardTextCasing';
import PracticeSettingsBasicCardTextType from './Text/Type/PracticeSettingsBasicCardTextType';
import PracticeSettingsBasicCardSoundVolume from './SoundVolume/PracticeSettingsBasicCardSoundVolume';
import PracticeSettingsBasicCardRussianQuoteSentences from './RussianSentences/PracticeSettingsBasicCardRussianQuoteSentences';

interface IPracticeSettingBasicCard {
element: JSX.Element;
Expand All @@ -32,13 +33,15 @@ const practiceSettingNameBasicToCardMap = new Map<
tags: ['text type', 'gameplay'],
},
],

[
'textCasing',
{
element: <PracticeSettingsBasicCardTextCasing key={v4()} />,
tags: ['text casing', 'text case', 'text capitalization', 'gameplay'],
},
],

[
'isPunctuationEnabled',
{
Expand All @@ -51,20 +54,31 @@ const practiceSettingNameBasicToCardMap = new Map<
],
},
],

[
'englishQuoteLengthRange',
{
element: <PracticeSettingsBasicCardEnglishQuoteLengthRange key={v4()} />,
tags: ['english quote length range', 'quote characters', 'gameplay'],
},
],

[
'quoteLength',
'russianQuoteSentences',
{
element: <PracticeSettingsBasicCardQuoteLength key={v4()} />,
tags: ['quote length', 'quote characters', 'gameplay'],
element: <PracticeSettingsBasicCardRussianQuoteSentences key={v4()} />,
tags: ['russian quote length range', 'quote characters', 'gameplay'],
},
],

[
'medleyCollectionsActive',
{
element: <PracticeSettingsBasicCardMedleyCollectionsActive key={v4()} />,
tags: ['active medley collections', 'active collections', 'gameplay'],
},
],

[
'medleyWordCount',
{
Expand All @@ -78,6 +92,7 @@ const practiceSettingNameBasicToCardMap = new Map<
],
},
],

[
'medleyPunctuationFrequency',
{
Expand All @@ -87,29 +102,35 @@ const practiceSettingNameBasicToCardMap = new Map<
tags: ['medley punctuation frequency', 'gameplay'],
},
],

[
'customTextActive',
{
element: <PracticeSettingsBasicCardCustomTextActive key={v4()} />,
tags: ['active custom text', 'gameplay'],
},
],

// TODO: isInstantDeathEnabled

[
'isResultRecordingEnabled',
{
element: <PracticeSettingsBasicCardIsResultRecordingEnabled key={v4()} />,
tags: ['countdown length', 'countdown time', 'gameplay'],
},
],

// TODO: isKeyboardVisualEnabled

[
'countdownLength',
{
element: <PracticeSettingsBasicCardCountdownLength key={v4()} />,
tags: ['countdown length', 'countdown time', 'gameplay'],
},
],

[
'caretStyle',
{
Expand All @@ -123,6 +144,7 @@ const practiceSettingNameBasicToCardMap = new Map<
],
},
],

[
'caretDelay',
{
Expand All @@ -136,6 +158,7 @@ const practiceSettingNameBasicToCardMap = new Map<
],
},
],

[
'mistakeHighlightStyle',
{
Expand All @@ -149,6 +172,7 @@ const practiceSettingNameBasicToCardMap = new Map<
],
},
],

[
'soundVolume',
{
Expand Down
6 changes: 3 additions & 3 deletions src/core/quotable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ interface IQuoteableApiQuote {
tags: string[];
}

export async function fetchRandQuote(config: IPracticeConfig) {
export async function fetchRandEnglishQuote(config: IPracticeConfig) {
// API docs: https://github.com/lukePeavey/quotable

const url = getUrlWithAppendedQueryParams('https://api.quotable.io/random', {
minLength: config.quoteLength.min,
maxLength: config.quoteLength.max,
minLength: config.englishQuoteLengthRange.min,
maxLength: config.englishQuoteLengthRange.max,
});

try {
Expand Down
34 changes: 18 additions & 16 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,24 @@ import {
import storage from './local-storage';
import isEnvironmentProduction from './utility/functions/isEnvironmentProduction';

console.log(`%cEnvironment = ${import.meta.env.MODE}`, INFO_MESSAGE_STYLES);
(function main() {
console.log(`%cEnvironment = ${import.meta.env.MODE}`, INFO_MESSAGE_STYLES);

try {
render();
} catch (err: any) {
storage.setPracticeSettings(DEFAULT_PRACTICE_SETTINGS);
render();
}

if (!isEnvironmentProduction()) {
// Hot Module Replacement (HMR) - Remove this snippet to remove HMR.
// Learn more: https://snowpack.dev/concepts/hot-module-replacement
if (import.meta.hot) {
import.meta.hot.accept();
}
}
})();

function render() {
ReactDOM.render(
Expand All @@ -25,18 +42,3 @@ function render() {
document.getElementById('root'),
);
}

try {
render();
} catch (err: any) {
storage.setPracticeSettings(DEFAULT_PRACTICE_SETTINGS);
render();
}

if (!isEnvironmentProduction()) {
// Hot Module Replacement (HMR) - Remove this snippet to remove HMR.
// Learn more: https://snowpack.dev/concepts/hot-module-replacement
if (import.meta.hot) {
import.meta.hot.accept();
}
}
25 changes: 25 additions & 0 deletions src/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const items = {
isPanelCollapsedProfileDangerZone: 'isPanelCollapsedProfileDangerZone',
isPanelCollapsedProfilePracticeResults:
'isPanelCollapsedProfilePracticeResults',
russianBibleSentences: 'russianBibleSentences',
};
Object.freeze(items);

Expand Down Expand Up @@ -102,6 +103,27 @@ function setBool(key: string, value: boolean) {
localStorage.setItem(key, JSON.stringify(value));
}

function hasRussianBibleSentenceData() {
return localStorage.getItem(items.russianBibleSentences) !== null;
}

async function downloadRussianBibleSentenceData() {
const fileName = 'russian-bible-sentences.txt';
try {
const res = await fetch(`/${fileName}`);
const text = await res.text();
localStorage.setItem(items.russianBibleSentences, text);
return text;
} catch (err: any) {
console.error(`Failed to fetch file "${fileName}":`, err);
throw new Error(`Failed to fetch file "${fileName}"`);
}
}

function getRussianBibleSentenceData() {
return localStorage.getItem(items.russianBibleSentences);
}

const exports = {
items,
getPracticeSettings,
Expand All @@ -113,6 +135,9 @@ const exports = {
addAbortedRound,
getBool,
setBool,
hasRussianBibleSentenceData,
downloadRussianBibleSentenceData,
getRussianBibleSentenceData,
};

export default exports;
Loading

0 comments on commit 5622206

Please sign in to comment.