latest changes before server transfer
Some checks failed
Deploy to Firebase Hosting on merge / build_and_deploy (push) Has been cancelled
Some checks failed
Deploy to Firebase Hosting on merge / build_and_deploy (push) Has been cancelled
This commit is contained in:
13
src/App.jsx
13
src/App.jsx
@@ -8,10 +8,10 @@ import {
|
||||
import Lobby from './components/Lobby';
|
||||
import VotingTable from './components/VotingTable';
|
||||
import UserSessionListener from './components/UserSessionListener';
|
||||
import axios from 'axios';
|
||||
import cyarenLogo from './assets/images/CyarenLogo.png';
|
||||
import cardLogo from './assets/images/logo.png';
|
||||
import styles from './App.module.css';
|
||||
import api from './services/api';
|
||||
|
||||
const App = () => {
|
||||
const [userId, setUserId] = useState('');
|
||||
@@ -24,16 +24,16 @@ const App = () => {
|
||||
|
||||
useEffect(() => {
|
||||
// Check if there's a user session by making a request to the backend
|
||||
axios
|
||||
.get('/api/auth/session')
|
||||
api
|
||||
.get('/auth/session')
|
||||
.then((response) => {
|
||||
const { userId } = response.data;
|
||||
if (userId) {
|
||||
setUserId(userId); // User is logged in
|
||||
} else {
|
||||
// If no user session exists, create an anonymous user session
|
||||
axios
|
||||
.post('/api/auth/signin-anonymous')
|
||||
api
|
||||
.post('/auth/signin-anonymous')
|
||||
.then((response) => {
|
||||
setUserId(response.data.userId);
|
||||
})
|
||||
@@ -65,7 +65,8 @@ const App = () => {
|
||||
path="/session/:sessionId"
|
||||
element={<VotingTable userId={userId} />}
|
||||
/>
|
||||
<Route path="*" element={<Navigate to={`/lobby`} />} />
|
||||
<Route path="/" element={<Navigate to={`/lobby`} />} />
|
||||
<Route path="*" element={<div>Not Found</div>} />
|
||||
</Routes>
|
||||
</section>
|
||||
<section className={styles.footer}>
|
||||
|
||||
@@ -20,7 +20,7 @@ const Lobby = ({ onJoinSession = () => {} }) => {
|
||||
} else {
|
||||
// Fetch users in the session
|
||||
api
|
||||
.get(`/api/session/${sessionId}/users`)
|
||||
.get(`/session/${sessionId}/users`)
|
||||
.then((response) => {
|
||||
setUsers(response.data);
|
||||
})
|
||||
@@ -41,7 +41,7 @@ const Lobby = ({ onJoinSession = () => {} }) => {
|
||||
|
||||
// Add the user to the session
|
||||
try {
|
||||
await api.post(`/api/session/${sessionId}/user`, { userId, username });
|
||||
await api.post(`/session/${sessionId}/user`, { userId, username });
|
||||
|
||||
// Call the onJoinSession callback with the username
|
||||
onJoinSession(userId);
|
||||
|
||||
@@ -41,11 +41,11 @@ const VotingTable = ({ userId }) => {
|
||||
const handleDropUser = async (userId) => {
|
||||
try {
|
||||
// Remove user vote and user from session via API calls
|
||||
await api.delete(`/api/session/${sessionId}/votes/${userId}`);
|
||||
await api.delete(`/api/session/${sessionId}/users/${userId}`);
|
||||
await api.delete(`/session/${sessionId}/votes/${userId}`);
|
||||
await api.delete(`/session/${sessionId}/users/${userId}`);
|
||||
|
||||
// Fetch updated session data after user removal
|
||||
const sessionResponse = await api.get(`/api/session/${sessionId}`);
|
||||
const sessionResponse = await api.get(`/session/${sessionId}`);
|
||||
const sessionData = sessionResponse.data;
|
||||
|
||||
if (!sessionData) return;
|
||||
@@ -62,7 +62,7 @@ const VotingTable = ({ userId }) => {
|
||||
setVotes(sessionData.votes || {});
|
||||
|
||||
// Redirect the dropped user to the lobby
|
||||
await api.post(`/api/users/${userId}`, {
|
||||
await api.post(`/users/${userId}`, {
|
||||
currentSessionId: `lobby/${sessionId}`,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -73,7 +73,7 @@ const VotingTable = ({ userId }) => {
|
||||
const handleFinalizeVoting = async () => {
|
||||
try {
|
||||
// Finalize voting by setting the isFinal flag in the session via API call
|
||||
await api.post(`/api/session/${sessionId}/finalize`, {
|
||||
await api.post(`/session/${sessionId}/finalize`, {
|
||||
isFinal: true,
|
||||
});
|
||||
setIsFinal(true);
|
||||
@@ -85,7 +85,7 @@ const VotingTable = ({ userId }) => {
|
||||
const handleResetVoting = async () => {
|
||||
try {
|
||||
// Reset the session's votes and isFinal flag via API call
|
||||
await api.post(`/api/session/${sessionId}/reset`, {
|
||||
await api.post(`/session/${sessionId}/reset`, {
|
||||
votes: {},
|
||||
isFinal: false,
|
||||
});
|
||||
@@ -101,12 +101,12 @@ const VotingTable = ({ userId }) => {
|
||||
const fetchSessionData = async () => {
|
||||
try {
|
||||
// Fetch session data from the API
|
||||
const sessionResponse = await api.get(`/api/session/${sessionId}`);
|
||||
const sessionResponse = await api.get(`/session/${sessionId}`);
|
||||
const sessionData = sessionResponse.data;
|
||||
|
||||
if (!sessionData) {
|
||||
// Initialize the session if it doesn't exist
|
||||
await api.post(`/api/session/${sessionId}`, {
|
||||
await api.post(`/session/${sessionId}`, {
|
||||
votes: {},
|
||||
maxUsers: maxUsers,
|
||||
isFinal: false,
|
||||
|
||||
@@ -21,7 +21,7 @@ api.interceptors.response.use(
|
||||
|
||||
// Try refreshing the token
|
||||
try {
|
||||
await api.post('/api/auth/refresh-token');
|
||||
await api.post('/auth/refresh-token');
|
||||
// Retry the original request with the new token
|
||||
return api(originalRequest);
|
||||
} catch (refreshError) {
|
||||
|
||||
Reference in New Issue
Block a user