diff --git a/src/components/flags/FlagsApi.js b/src/components/flags/FlagsApi.js index 51384b7..b335b5c 100644 --- a/src/components/flags/FlagsApi.js +++ b/src/components/flags/FlagsApi.js @@ -160,11 +160,11 @@ class FlagsApi extends React.Component { } async showFlags() { - await this.handleClick('api').then(() => - { + await this.handleClick('api').then(() => { + if (!this.state.paused) { this.restartTimer(); } - ).then(() => this.prepareStat()) + }).then(() => this.prepareStat()) .then(() => { this.answerLocked = false; }); diff --git a/src/components/flags/Profile.js b/src/components/flags/Profile.js index 33aeef6..10962b3 100644 --- a/src/components/flags/Profile.js +++ b/src/components/flags/Profile.js @@ -2,12 +2,8 @@ import React, { useEffect, useState } from 'react'; import axios from "axios"; import api from "../../config/Api"; import Table from "react-bootstrap/Table"; -import Card from "react-bootstrap/Card"; -import ListGroup from "react-bootstrap/ListGroup"; -import ListGroupItem from "react-bootstrap/ListGroupItem"; import Tab from "react-bootstrap/Tab"; import Tabs from "react-bootstrap/Tabs"; -import Alert from "react-bootstrap/Alert"; import { useHistory } from 'react-router-dom'; import "../home/styles.css"; @@ -44,48 +40,41 @@ const Profile = () => { }, []); - // Show a loader if user data hasn't arrived yet if (!user) { - return
Loading Profile Data...
; + return
Loading...
; } - // Filter for Learn tab: < 75% guess rate, exclude never shown, sorted by rate ASC (lowest first) const learnData = statsData .filter(item => item.times_shown > 0 && item.rate < 75) .sort((a, b) => a.rate - b.rate); - // Stats tab: all data sorted by guess rate DESC const allStats = [...statsData].sort((a, b) => b.rate - a.rate); const renderStatsTable = (data, emptyMessage) => ( - +
- + {data.length > 0 ? data.map((item, index) => ( - + )) : } @@ -93,68 +82,88 @@ const Profile = () => {
Flag Country Shown CorrectGuess RateRate
{item.flag}{item.flag} {item.country} {item.times_shown} {item.times_guessed} - {item.times_shown > 0 ? ( - = 75 ? '#28a745' : item.rate >= 50 ? '#ffc107' : '#dc3545', - fontWeight: 'bold' - }}> - {item.rate}% - - ) : ( - n/a - )} + = 75 ? '#28a745' : item.rate >= 50 ? '#ffc107' : '#dc3545', + fontWeight: 'bold' + }}> + {item.rate}% +
{emptyMessage}
); - const handleClose = () => { - history.push('/'); - }; - return ( -
- -
- - - - - {user.firstName} {user.lastName} - {user.telegramUsername ? ` (@${user.telegramUsername})` : ''} - - +
+
+ + +
+
+ {user.firstName} {user.lastName} +
+ {user.telegramUsername && ( +
@{user.telegramUsername}
+ )}
+
- - - High score: - {user.highScore} - - - Best time: - {user.bestTime}s - - - Total games: - {user.gamesTotal} - - - Time total: - {formatTime(user.timeTotal)} - - - +
+ {[ + { label: 'High Score', value: user.highScore }, + { label: 'Best Time', value: `${user.bestTime}s` }, + { label: 'Games', value: user.gamesTotal }, + { label: 'Total Time', value: formatTime(user.timeTotal) } + ].map((stat, i) => ( +
+
{stat.value}
+
{stat.label}
+
+ ))} +
setKey(k)} - className="mt-3" + className="mt-2" + style={{ paddingLeft: '1rem' }} > - - Practice these flags to improve your score! Focus on the ones you miss most often. - - {renderStatsTable(learnData, "Great job! No flags need extra practice.")} +
+ Flags below 75% - practice these! +
+ {renderStatsTable(learnData, "No flags need practice.")}
- - {renderStatsTable(allStats, "No guesses recorded yet. Start playing!")} + + {renderStatsTable(allStats, "No data yet.")}
diff --git a/src/hooks/useOAuth.js b/src/hooks/useOAuth.js index 303c295..762f338 100644 --- a/src/hooks/useOAuth.js +++ b/src/hooks/useOAuth.js @@ -38,13 +38,14 @@ export const useOAuth = () => { if (refresh_token) { localStorage.setItem('refreshToken', refresh_token); } - - // Store expiration time if provided +console.log(expires_in, refresh_token, access_token); + // Store expiration time if provided if (expires_in) { const expiresAt = Date.now() + (expires_in); localStorage.setItem('tokenExpiresAt', expiresAt.toString()); } + // Set axios default header axios.defaults.headers.common = { 'Authorization': `Bearer ${access_token}`