All files / pages LeaderboardPage.js

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103                                28x 28x             28x                                   28x                         28x     28x 28x                                         1x                                            
import React from "react";
 
import { useParams } from "react-router-dom";
import { hasRole } from "main/utils/currentUser";
 
import LeaderboardTable from "main/components/Leaderboard/LeaderboardTable";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
 
import { useBackend } from "main/utils/useBackend";
import { useCurrentUser } from "main/utils/currentUser";
import Background from "../../assets/PlayPageBackground.png";
 
import { useNavigate } from "react-router-dom";
import { Button } from "react-bootstrap";
 
export default function LeaderboardPage() {
    const { commonsId } = useParams();
    const { data: currentUser } = useCurrentUser();
 
    // Stryker disable all
    const {
        data: userCommons,
        error: _error,
        status: _status,
    } = useBackend(
        [`/api/usercommons/commons/all?commonsId=${commonsId}`],
        {
            method: "GET",
            url: "/api/usercommons/commons/all",
            params: {
                commonsId: commonsId,
            },
        },
        []
    );
    // Stryker restore all
 
    // Stryker disable all
    const {
        data: commons,
        error: _commonsError,
        status: _commonsStatus,
    } = useBackend(
        [`/api/commons?id=${commonsId}`],
        {
            method: "GET",
            url: "/api/commons",
            params: {
                id: commonsId,
            },
        },
        []
    );
    // Stryker restore all
 
    const navigate = useNavigate();
 
    const showLeaderboard =
        hasRole(currentUser, "ROLE_ADMIN") || commons.showLeaderboard;
    return (
        <div
            data-testid={"LeaderboardPage-main-div"}
            style={{
                backgroundSize: "cover",
                backgroundImage: `url(${Background})`,
                width: '100%', 
                minHeight: '100vh', 
            }}
        >
            <BasicLayout>
                <div 
                    style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', flexDirection: 'column', width: '100%' }}
                    data-testid="LeaderboardPage-layout-div" 
                >
                    <div 
                        style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', width: '100%', maxWidth: '1200px', margin: '0 auto' }}
                        data-testid="LeaderboardPage-header-div" 
                    >
                        <h1>Leaderboard</h1>
                        <Button
                            onClick={() => navigate(-1)}
                            data-testid="LeaderboardPage-back-button"
                        >
                            Back
                        </Button>
                    </div>
                    {showLeaderboard ? (
                        <div data-testid="LeaderboardPage-leaderboard-div" style={{ width: '100%', margin: '0 auto' }}>
                            <LeaderboardTable
                                leaderboardUsers={userCommons}
                                currentUser={currentUser}
                            />
                        </div>
                    ) : (
                        <p>You're not authorized to see the leaderboard.</p>
                    )}
                </div>
            </BasicLayout>
        </div>
    );
    
}