Skip to content

Commit

Permalink
Merge branch 'feat/various-quizzes'.
Browse files Browse the repository at this point in the history
  • Loading branch information
dleclercpro committed Mar 25, 2024
2 parents 702e48b + 0576f44 commit 48edd83
Show file tree
Hide file tree
Showing 81 changed files with 988 additions and 665 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
EMAIL=d.leclerc.pro@gmail.com
DOMAIN=liquors.dleclerc.me
PROXY_URL=http://liquors-quiz-app:8000
DOMAIN=quiz.dleclerc.me
PROXY_URL=http://quiz-app:8000
85 changes: 80 additions & 5 deletions Apps/Client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Apps/Client/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "liquors-quiz--client",
"name": "quiz--client",
"version": "latest",
"private": true,
"dependencies": {
Expand All @@ -10,6 +10,7 @@
"@reduxjs/toolkit": "^2.2.1",
"http-proxy-middleware": "^2.0.6",
"i18next": "^23.10.0",
"i18next-http-backend": "^2.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^14.0.5",
Expand All @@ -24,6 +25,7 @@
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
4 changes: 2 additions & 2 deletions Apps/Client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Liquors of the World - Quiz" />
<meta name="description" content="Demo online quiz app." />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<title>Liquors of the World</title>
<title>Quiz</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
4 changes: 2 additions & 2 deletions Apps/Client/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"short_name": "Liquors of the World",
"name": "Liquors of the World",
"short_name": "Quiz App",
"name": "Quiz App",
"icons": [
{
"src": "favicon.ico",
Expand Down
35 changes: 25 additions & 10 deletions Apps/Client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,48 @@ import './App.scss';
import HomePage from './pages/HomePage';
import QuizPage from './pages/QuizPage';
import ScoresPage from './pages/ScoresPage';
import { BACKGROUND_URLS, DEBUG } from './config';
import { DEBUG, SERVER_ROOT } from './config';
import TestPage from './pages/TestPage';
import AuthRoute from './routes/AuthRoute';
import LoadingOverlay from './components/overlays/LoadingOverlay';
import AnswerOverlay from './components/overlays/AnswerOverlay';
import { useEffect, useState } from 'react';
import { useDispatch } from './hooks/redux';
import { ping } from './actions/UserActions';
import { getRandom } from './utils/array';
import { useDispatch, useSelector } from './hooks/redux';
import { ping } from './actions/AuthActions';
import Nav from './components/Nav';
import ErrorPage from './pages/ErrorPage';
import { fetchVersion } from './actions/AppActions';
import { updateVersion } from './actions/AppActions';
import { fetchQuizNames } from './actions/DataActions';
import { CallGetBackgroundUrl } from './calls/data/CallGetBackgroundUrl';

function App() {
const [backgroundUrl, setBackgroundUrl] = useState('');

const dispatch = useDispatch();

// Check if user is logged in already
useEffect(() => {
setBackgroundUrl(`url(${getRandom(BACKGROUND_URLS)})`);

const quiz = useSelector((state) => state.quiz)

useEffect(() => {
dispatch(ping());

dispatch(fetchVersion());
dispatch(updateVersion());
dispatch(fetchQuizNames());
}, []);

useEffect(() => {
if (quiz.name === null) {
return;
}

new CallGetBackgroundUrl(quiz.name).execute()
.then(({ data: path }) => {
const url = `${SERVER_ROOT}${path}`;
setBackgroundUrl(`url(${url})`);
})
.catch((err) => console.error(err));

}, [quiz.name]);

return (
<div className='app' style={{ backgroundImage: backgroundUrl }}>
<div className='app-container'>
Expand Down
34 changes: 11 additions & 23 deletions Apps/Client/src/actions/AppActions.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import { createAsyncThunk } from '@reduxjs/toolkit';
import { VersionData } from '../types/DataTypes';
import { CallGetVersion } from '../calls/quiz/CallGetVersion';
import { setVersion } from '../reducers/AppReducer';
import { ThunkAPI, createServerAction } from './ServerActions';

export const fetchVersion = createAsyncThunk(
'app/version',
async (_, { dispatch, rejectWithValue }) => {
try {
const { data } = await new CallGetVersion().execute();
export const updateVersion = createServerAction<void, void>(
'app/updateVersion',
async (_, { dispatch }: ThunkAPI) => {
const { data } = await new CallGetVersion().execute();

if (!data) {
throw new Error('MISSING_DATA');
}

const { version } = data as VersionData;

dispatch(setVersion(version));
if (!data) {
throw new Error('MISSING_DATA');
}

} catch (err: unknown) {
let error = 'UNKNOWN_ERROR';

if (err instanceof Error) {
error = err.message;
}
const { version } = data as VersionData;

console.error(`Could not get app version: ${error}`);
return rejectWithValue(error);
}
}
dispatch(setVersion(version));
},
);
45 changes: 45 additions & 0 deletions Apps/Client/src/actions/AuthActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { CallLogIn } from '../calls/auth/CallLogIn';
import { LoginData, PingData, UserData } from '../types/DataTypes';
import { CallPing } from '../calls/auth/CallPing';
import { CallLogOut } from '../calls/auth/CallLogOut';
import { createServerAction } from './ServerActions';

export const login = createServerAction<LoginData, UserData>(
'auth/login',
async (args: LoginData) => {
const { quizId } = args;
const { data } = await new CallLogIn().execute(args);

if (!data) {
throw new Error('MISSING_DATA');
}

const user = data as UserData;

return {
username: user.username,
isAdmin: user.isAdmin,
quizId,
};
},
);

export const logout = createServerAction<void, void>(
'auth/logout',
async () => {
await new CallLogOut().execute();
},
);

export const ping = createServerAction<void, PingData>(
'auth/ping',
async () => {
const { data } = await new CallPing().execute();

if (!data) {
throw new Error('MISSING_DATA');
}

return data as PingData;
},
);
Loading

0 comments on commit 48edd83

Please sign in to comment.