Skip to content

Commit

Permalink
first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
surpri6e committed Mar 28, 2024
1 parent 97cf881 commit fdc5964
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
50 changes: 47 additions & 3 deletions screens/QuestionsScreen/QuestionsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
QuestionScreenMainAnswerText,
QuestionScreenMainButton,
QuestionScreenMainText,
QuestionScreenStatingMessage,
QuestionScreenTitleMessage,
QuestionsScreenAnswer,
QuestionsScreenMainBoldText,
} from './QuestionsScreenStyles';
Expand All @@ -21,6 +21,9 @@ const QuestionsScreen: FC<IQuestionsScreen> = ({ navigation, route }) => {
const [questionIndex, setQuestionIndex] = useState(0);

const [currentAnswer, setCurrentAnswer] = useState(0);
const [answersResult, setAnswersResult] = useState<boolean[]>([]);

const [scores, setScores] = useState(0);

useEffect(() => {
navigation.setOptions({ title });
Expand All @@ -33,6 +36,18 @@ const QuestionsScreen: FC<IQuestionsScreen> = ({ navigation, route }) => {
}
}, [isStart]);

useEffect(() => {
let result = 0;

answersResult.forEach((elem) => {
if (elem) {
result += 1;
}
});

setScores(result);
}, [answersResult]);

return (
// If user alredy started the marathon
<Container>
Expand Down Expand Up @@ -61,12 +76,41 @@ const QuestionsScreen: FC<IQuestionsScreen> = ({ navigation, route }) => {
</QuestionsScreenAnswer>
))}

<QuestionScreenMainButton>Далее</QuestionScreenMainButton>
{questions.length - 1 != questionIndex ? (
<TouchableOpacity
onPress={() => {
setAnswersResult([...answersResult, answers[questionIndex][currentAnswer][1]]);
setQuestionIndex(questionIndex + 1);
}}
>
<QuestionScreenMainButton>Далее</QuestionScreenMainButton>
</TouchableOpacity>
) : (
<TouchableOpacity
onPress={() => {
setAnswersResult([...answersResult, answers[questionIndex][currentAnswer][1]]);
setIsStart(false);
setIsEnd(true);
}}
>
<QuestionScreenMainButton>Закончить</QuestionScreenMainButton>
</TouchableOpacity>
)}
</>
) : isEnd ? (
<>
<QuestionScreenTitleMessage>Поздравляем вы набрали</QuestionScreenTitleMessage>
<QuestionScreenMainText>
{scores} из {answersResult.length} очков.
</QuestionScreenMainText>
<TouchableOpacity onPress={() => navigation.navigate('MainScreen')}>
<QuestionScreenMainButton>На главную старницу</QuestionScreenMainButton>
</TouchableOpacity>
</>
) : (
// If user has not yet started the marathon
<>
<QuestionScreenStatingMessage>{title}</QuestionScreenStatingMessage>
<QuestionScreenTitleMessage>{title}</QuestionScreenTitleMessage>
<QuestionScreenMainText>
Сейчас вам предстоит пройти марафон состоящий из {questions.length} вопросов. Когда будете готовы нажмите соответствующую кнопку. Время
у вас неограниченное, задания требуется выполнять по порядку. В конце вы узнаете свой результат и краткие рекомендации.
Expand Down
2 changes: 1 addition & 1 deletion screens/QuestionsScreen/QuestionsScreenStyles.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from 'styled-components/native';

export const QuestionScreenStatingMessage = styled.Text`
export const QuestionScreenTitleMessage = styled.Text`
font-size: 20px;
font-weight: 800;
margin-bottom: 20px;
Expand Down

0 comments on commit fdc5964

Please sign in to comment.