Skip to content
Snippets Groups Projects
Commit a98ad176 authored by GOEPP THOMAS's avatar GOEPP THOMAS
Browse files

refactor: clean code

parent d5f85818
Branches
2 merge requests!132V4.0,!130Feature/136 add description on my runs
Pipeline #324385 passed with stages
in 15 seconds
import { Modal, View, Text, StyleSheet, TextInput } from "react-native";
import DefaultButton from "./buttons/DefaultButton";
import {useState} from "react";
import {useQuizService} from "../services/QuizService";
import HttpError from "../services/HttpError";
interface Props {
navigation: any;
modalVisible: boolean;
setModalVisible: (newModalVisible: boolean) => void;
}
export default function ModalJoinQuiz({ navigation, modalVisible, setModalVisible }: Props) {
const [isError, setIsError] = useState<boolean>(false);
const [errorMessage, setErrorMessage] = useState<string>("");
const [codeQuiz, setCodeQuiz] = useState<string>("");
const {remainingQuiz} = useQuizService();
const handleButtonClosePressed = () => {
setModalVisible(!modalVisible);
setIsError(false);
setErrorMessage("");
}
const handleButtonJoinQuizPressed = async () => {
const quiz = await remainingQuiz(codeQuiz);
if(HttpError.isHttpError(quiz)){
setIsError(true);
setErrorMessage("Code quiz invalide");
return;
}
navigation.reset({
index: 0,
routes: [
{
name: "PlayingQuiz",
params: {quizRecovered: quiz},
},
]
});
}
return (
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
setModalVisible(!modalVisible);
}}
>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<View style={styles.containerMenu}>
<Text style={styles.textMenu}>PLAY YOUR QUIZ</Text>
<DefaultButton text="X" handleButtonPressed={handleButtonClosePressed} buttonStyle={styles.buttonMenu} buttonText={styles.buttonTextMenu}/>
</View>
<View style={styles.containerCode}>
<Text style={styles.textCode}>ENTER THE QUIZ ID</Text>
{isError && <Text style={styles.textError}>{errorMessage}</Text>}
<TextInput placeholder="TYPE A CODE" style={styles.textInputCode} onChangeText={(text) => setCodeQuiz(text)}></TextInput>
<DefaultButton text="PLAY" handleButtonPressed={handleButtonJoinQuizPressed} buttonStyle={styles.buttonCode}/>
</View>
</View>
</View>
</Modal>
);
}
const styles = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
modalView: {
height: '35%',
width: '80%',
margin: '10%',
padding: '10%',
backgroundColor: 'white',
borderRadius: 20,
alignItems: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
},
containerMenu: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
height: '30%',
},
textMenu: {
flex: 1,
textAlign: 'center',
fontSize: 20,
fontWeight: 'bold',
},
buttonMenu: {
padding: 10,
backgroundColor: '#FFFFFF',
},
buttonTextMenu: {
color: '#D5D5D5',
fontSize: 24,
},
containerCode: {
height: '100%',
width: '100%',
},
textCode: {
fontSize: 14
},
textError: {
fontSize: 14,
color: "red"
},
textInputCode: {
borderColor: '#1FA9FF',
borderRadius: 10,
borderWidth: 2,
},
buttonCode: {
margin: 20
}
});
\ No newline at end of file
......@@ -5,6 +5,7 @@ export interface QuizInfoRun{
difficulty: Difficulty;
name?: string;
questionCount: string;
description: string;
}
export interface RunsInformationsAllRuns{
id: string;
......
......@@ -3,7 +3,6 @@ import DefaultButton from "../../components/buttons/DefaultButton";
import {useTranslation} from "react-i18next";
import { useState } from "react";
import { TextsStyles } from "../../styles/TextsStyles";
import ModalJoinQuiz from "../../components/ModalJoinQuiz";
import MenuButton from "../../components/buttons/MenuButton";
import {NavigationProp} from "@react-navigation/native";
import {useQuizService} from "../../services/QuizService";
......@@ -57,7 +56,6 @@ export default function HomeChild({navigation}: Props) {
<MenuButton text={"PLAY"} handleButtonPressed={handleButtonGeneratePressed}/>
<MenuButton text={"MY QUIZZES"} handleButtonPressed={handleButtonMyQuizzesPressed}/>
</View>
<ModalJoinQuiz modalVisible={modalVisible} setModalVisible={setModalVisible} navigation={navigation}/>
</View>
);
}
......
import {Image, StyleSheet, Text, View} from "react-native";
import {useTranslation} from "react-i18next";
import React, {useEffect, useState} from "react";
import ModalJoinQuiz from "../../components/ModalJoinQuiz";
import MenuButton from "../../components/buttons/MenuButton";
import {NavigationProp} from "@react-navigation/native";
import HttpError from "../../services/HttpError";
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment