diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0bda143..ee3bc4d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,47 +5,47 @@ on: types: [published] jobs: - # unit-tests: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - uses: actions/setup-node@v4 - # with: - # node-version: 20 - # - run: npm --prefix users/authservice ci - # - run: npm --prefix users/userservice ci - # - run: npm --prefix gatewayservice ci - # - run: npm --prefix webapp ci - # - run: npm --prefix users/authservice test -- --coverage - # - run: npm --prefix users/userservice test -- --coverage - # - run: npm --prefix gatewayservice test -- --coverage - # - run: npm --prefix webapp test -- --coverage - # - name: Analyze with SonarCloud - # uses: sonarsource/sonarcloud-github-action@master - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - # e2e-tests: - # needs: [unit-tests] - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - uses: actions/setup-node@v4 - # with: - # node-version: 20 - # - run: npm --prefix users/authservice install - # - run: npm --prefix users/userservice install - # - run: npm --prefix gatewayservice install - # - run: npm --prefix webapp install - # - run: npm --prefix webapp run build - # - run: npm --prefix webapp run test:e2e + unit-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm --prefix users/authservice ci + - run: npm --prefix users/userservice ci + - run: npm --prefix gatewayservice ci + - run: npm --prefix webapp ci + - run: npm --prefix users/authservice test -- --coverage + - run: npm --prefix users/userservice test -- --coverage + - run: npm --prefix gatewayservice test -- --coverage + - run: npm --prefix webapp test -- --coverage + - name: Analyze with SonarCloud + uses: sonarsource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + e2e-tests: + needs: [unit-tests] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm --prefix users/authservice install + - run: npm --prefix users/userservice install + - run: npm --prefix gatewayservice install + - run: npm --prefix webapp install + - run: npm --prefix webapp run build + - run: npm --prefix webapp run test:e2e docker-push-webapp: name: Push webapp Docker Image to GitHub Packages runs-on: ARM64 permissions: contents: read packages: write - #needs: [e2e-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -65,7 +65,7 @@ jobs: permissions: contents: read packages: write - # needs: [e2e-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -82,7 +82,7 @@ jobs: permissions: contents: read packages: write - #needs: [e2e-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -99,7 +99,7 @@ jobs: permissions: contents: read packages: write - #needs: [e2e-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -116,7 +116,7 @@ jobs: permissions: contents: read packages: write - #needs: [e2e-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry diff --git a/webapp/src/components/AddUser.jsx b/webapp/src/components/AddUser.jsx index 80f3d9b..09dcdba 100644 --- a/webapp/src/components/AddUser.jsx +++ b/webapp/src/components/AddUser.jsx @@ -3,7 +3,7 @@ import React, { useState } from 'react'; import axios from 'axios'; import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; import { Link } from 'react-router-dom'; - +import { useNavigate } from 'react-router-dom'; const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; const AddUser = () => { @@ -13,6 +13,7 @@ const AddUser = () => { const [cpassword, setcPassword] = useState(''); const [error, setError] = useState(''); const [openSnackbar, setOpenSnackbar] = useState(false); + const { navigate } = useNavigate(); const addUser = async () => { try { @@ -22,6 +23,7 @@ const AddUser = () => { } await axios.post(`${apiEndpoint}/adduser`, { username, email, password }); setOpenSnackbar(true); + navigate('/login'); } catch (error) { setError(error.response.data.error); } diff --git a/webapp/src/components/Question.jsx b/webapp/src/components/Question.jsx index 3ee1ff8..930be01 100644 --- a/webapp/src/components/Question.jsx +++ b/webapp/src/components/Question.jsx @@ -2,15 +2,36 @@ import React, { useState, useEffect } from "react"; import axios from "axios"; const Question = (props) => { - const apiEndpoint = process.env.REACT_APP_API_ENDPOINT ||'http://localhost:8000'; + const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; const [question, setQuestion] = useState([]); const [loading, setLoading] = useState(true); + const [counter, setCounter] = useState(0); + + useEffect(() => { + const interval = setInterval(() => { + setCounter((prevCounter) => prevCounter + 0.4); + }, 40); + + return () => clearInterval(interval); + }, []); + + useEffect(() => { + if (counter >= 100) { + setLoading(true); + fetchQuestion(); + } + }, [counter]); + + const fetchQuestion = async () => { try { + const res = await axios.get(`${apiEndpoint}/${props.type}/${props.category}/question`); setQuestion(res.data); setLoading(false); + setCounter(0); + } catch (error) { console.error('Error fetching question:', error); } @@ -19,10 +40,11 @@ const Question = (props) => { const answerQuestion = async (answer) => { try { setLoading(true); - const result = await axios.post(`${apiEndpoint}/${props.type}/answer`, {answer}); + const result = await axios.post(`${apiEndpoint}/${props.type}/answer`, { answer }); const res = await axios.get(`${apiEndpoint}/${props.type}/${props.category}/question`); setQuestion(res.data); setLoading(false); + setCounter(0); } catch (error) { console.log(error); @@ -31,25 +53,33 @@ const Question = (props) => { useEffect(() => { fetchQuestion(); - }, []); + + }, []); return (
- { loading ? ( -

Loading...

- ) : ( - <> + {loading ? ( +

+
+

+ ) : ( + <> +

{question.question}

+
+
+
- {question.images.map( image => ( - - ))} + {question.images.map(image => ( + + ))}
- - )} + + )}
) }; diff --git a/webapp/src/index.js b/webapp/src/index.js index 1eadf1c..f8988c5 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -17,14 +17,14 @@ const store = createStore({ }); root.render( - + // - + // ); // If you want to start measuring performance in your app, pass a function