-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(all): ✨ optimize generation of text and audio
Signed-off-by: Yunus Andréasson <yunus@edenmind.com>
- Loading branch information
1 parent
b5d24b0
commit 9a3eab9
Showing
17 changed files
with
202 additions
and
52 deletions.
There are no files selected for viewing
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
/* eslint-disable react-native/no-inline-styles */ | ||
/* eslint-disable react-native/no-color-literals */ | ||
import PropTypes from 'prop-types' | ||
import React, { useState, useMemo, useEffect } from 'react' | ||
import { View, FlatList, Pressable, StyleSheet } from 'react-native' | ||
import { Surface, Text, useTheme } from 'react-native-paper' | ||
|
||
import { ButtonAnswer } from '../components/button-answer.js' | ||
import Spinner from '../components/spinner.js' | ||
import { useWordsLogic } from '../hooks/use-words-logic.js' | ||
import { calculateFontSize } from '../services/ui-services.js' | ||
import { useSharedStyles } from '../styles/common.js' | ||
|
||
const styles = StyleSheet.create({ | ||
bottomList: { | ||
bottom: 25, | ||
left: 0, | ||
position: 'absolute', | ||
right: 0 | ||
} | ||
}) | ||
|
||
export const PracticeVocabulary = (props) => { | ||
const theme = useTheme() | ||
const sharedStyle = useSharedStyles(theme) | ||
|
||
const [currentWord, setCurrentWord] = useState(0) | ||
const [currentWordIndex, setCurrentWordIndex] = useState(0) | ||
|
||
const { arabic, buttonPositions, handleCorrectAnswer, handlePressOnWord, localWords } = useWordsLogic( | ||
currentWord, | ||
setCurrentWord, | ||
setCurrentWordIndex | ||
) | ||
|
||
const fontSize = useMemo(() => calculateFontSize(arabic), [arabic]) | ||
|
||
const generateAnswerButton = (text, onPress, isCorrect = false) => ( | ||
<ButtonAnswer text={text} onPress={onPress} correct={isCorrect} incorrect={!isCorrect} /> | ||
) | ||
|
||
useEffect(() => { | ||
if (currentWordIndex === localWords.length) { | ||
props.handleContinue() | ||
} | ||
}, [currentWordIndex]) | ||
|
||
const buttons = useMemo(() => { | ||
const mainButton = generateAnswerButton(localWords[currentWord]?.english, handleCorrectAnswer, true) | ||
const altButton1 = generateAnswerButton(localWords[currentWord]?.alternative1) | ||
const altButton2 = generateAnswerButton(localWords[currentWord]?.alternative2) | ||
|
||
return [ | ||
{ button: mainButton, position: buttonPositions[0] }, | ||
{ button: altButton1, position: buttonPositions[1] }, | ||
{ button: altButton2, position: buttonPositions[2] } | ||
].sort((a, b) => a.position - b.position) | ||
}, [localWords, currentWord, handleCorrectAnswer, buttonPositions]) | ||
|
||
const renderItem = ({ item }) => <>{item.button}</> | ||
|
||
return ( | ||
<> | ||
<Surface style={sharedStyle.wordSurface}> | ||
<View style={sharedStyle.wordCenteredView}> | ||
<Pressable onPress={handlePressOnWord}> | ||
<Text style={[sharedStyle.wordText, { color: theme.colors.secondary, fontSize }]}>{arabic}</Text> | ||
</Pressable> | ||
</View> | ||
</Surface> | ||
<FlatList | ||
style={[sharedStyle.wordContainer, styles.bottomList]} | ||
data={buttons} | ||
renderItem={renderItem} | ||
ListEmptyComponent={<Spinner />} | ||
keyExtractor={(item) => item.position.toString()} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
PracticeVocabulary.propTypes = { | ||
handleContinue: PropTypes.func.isRequired | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import { View, Image } from 'react-native' | ||
import { Text } from 'react-native-paper' | ||
|
||
import icon from '../assets/logo.png' | ||
import { pluralize } from '../services/ui-services.js' | ||
|
||
export const CompletedView = (props) => ( | ||
<View style={{ alignItems: 'center', flex: 1, justifyContent: 'center' }}> | ||
<Image source={icon} style={{ height: 100, width: 100 }} /> | ||
<Text variant="titleLarge" style={{ paddingTop: 10, textAlign: 'center' }}> | ||
Well Done | ||
</Text> | ||
<Text variant="bodyMedium" style={{ textAlign: 'center', width: 250 }}> | ||
You have finished the {pluralize(props.localWords.length, 'word')} that you had to review, mashaAllah! | ||
</Text> | ||
</View> | ||
) | ||
|
||
CompletedView.propTypes = { | ||
localWords: PropTypes.array.isRequired | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters