Skip to content

Commit

Permalink
Match History: Now displays sorted by finishedAt the matches
Browse files Browse the repository at this point in the history
  • Loading branch information
hanmpark committed Oct 18, 2024
1 parent 9e79abf commit b3909f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
13 changes: 3 additions & 10 deletions frontend/src/components/Game/remote/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import { formatUserData } from "../../../api/user";
import logger from "../../../api/logger";
import { PageContainer } from "../styles/Game.styled";

/*
** Lastmessage:
** MATH_JOIN = side and opponent could be null for the person who created the match
** PLAYER_JOIN = only concerning the opponent joining the match
*/

const Game = () => {
const navigate = useNavigate();
const location = useLocation();
Expand Down Expand Up @@ -65,12 +59,11 @@ const Game = () => {
}));
}, [sendMessage]);

const retreiveGameMode = () => {
console.log(location.pathname);
const retreiveGameMode = useCallback(() => {
if (location.pathname === '/game-ai') return 'ai';
if (location.pathname === '/game-classic') return '1v1';
return '';
}
}, [location.pathname]);

const handleHeartbeatAck = useCallback(() => {
heartbeatAckCount.current += 1;
Expand All @@ -80,7 +73,7 @@ const Game = () => {
d: { match_type: retreiveGameMode() }
}));
}
}, [sendMessage]);
}, [sendMessage, retreiveGameMode]);

// Send IDENTIFY message on connection open
useEffect(() => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Profile/content/MatchHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MatchCardTable, MatchHistoryContainer } from "../styles/Profile.styled"
const MatchHistory = ({ userID, matches }) => {
const [visibleRows, setVisibleRows] = useState([]);
const containerRef = useRef(null);
const sortedMatches = [...matches].sort((a, b) => new Date(b.finishedAt) - new Date(a.finishedAt));
const { t } = useTranslation();

const handleScroll = () => {
Expand Down Expand Up @@ -55,7 +56,7 @@ const MatchHistory = ({ userID, matches }) => {
</tbody>
) : (
<tbody ref={containerRef}>
{matches.map((match, index) => (
{sortedMatches.map((match, index) => (
<tr
key={index}
className={`match-card ${visibleRows.includes(index) ? "visible" : ""}`}
Expand Down

0 comments on commit b3909f5

Please sign in to comment.