generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into dev_score
- Loading branch information
Showing
9 changed files
with
247 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import RankingsTable from "./RankingTable"; | ||
|
||
const RankingsLayout = () => { | ||
const [filter, setFilter] = useState('global'); // default ranking = global | ||
|
||
const handleFilterClick = (filter) => { | ||
setFilter(filter); | ||
} | ||
|
||
return ( | ||
<div className="flex h-screen"> | ||
<div id="sidebar" className="md:flex flex-col w-48 bg-[#504185]"> | ||
<div className="flex items-center justify-center h-16 bg-[#322653]"> | ||
<span className="text-xl font-bold text-white">Rankings</span> | ||
</div> | ||
<div id="categories" className="flex flex-col flex-1 overflow-y-auto"> | ||
<nav className="flex-1 px-2 py-4 bg-gradient-to-b | ||
from-[#3a2f60] from-10% to-[#504185] to-60%"> | ||
<button className="flex items-center px-4 py-2 text-gray-100 rounded-lg hover:bg-[#73689b]" | ||
onClick={() => handleFilterClick('global')}> | ||
Global | ||
</button> | ||
<button className="flex items-center px-4 py-2 text-gray-100 rounded-lg hover:bg-[#73689b]" | ||
onClick={() => handleFilterClick('flags')}> | ||
Flags | ||
</button> | ||
<button className="flex items-center px-4 py-2 text-gray-100 rounded-lg hover:bg-[#73689b]" | ||
onClick={() => handleFilterClick('cities')}> | ||
Cities | ||
</button> | ||
<button className="flex items-center px-4 py-2 text-gray-100 rounded-lg hover:bg-[#73689b]" | ||
onClick={() => handleFilterClick('monuments')}> | ||
Monuments | ||
</button> | ||
<button className="flex items-center px-4 py-2 text-gray-100 rounded-lg hover:bg-[#73689b]" | ||
onClick={() => handleFilterClick('food')}> | ||
Food | ||
</button> | ||
</nav> | ||
</div> | ||
</div> | ||
|
||
<div className="flex flex-col flex-1 overflow-y-auto"> | ||
<div className="flex items-center px-4 h-16"> | ||
<h1 className="text-4xl font-bold uppercase text-[#4d3b7f]">{filter}</h1> | ||
</div> | ||
<div className="p-4" id="table"> | ||
<RankingsTable filter={filter} /> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default RankingsLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import axios from "axios"; | ||
|
||
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT ||'http://localhost:8000'; | ||
|
||
const RankingsTable = ({ filter }) => { | ||
const [users, setUsers] = useState([]); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const response = await axios.get(`${apiEndpoint}/rankings/${filter}`); | ||
setUsers(response.data); | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
} | ||
}; | ||
|
||
fetchData(); | ||
}, [filter]); | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<div className="overflow-x-auto sm:mx-6 lg:mx-8"> | ||
<div className="py-2 inline-block min-w-full sm:px-6 lg:px-8"> | ||
<div className="overflow-hidden"> | ||
<table className="min-w-full"> | ||
<thead className="border-b"> | ||
<tr> | ||
<th scope="col" className="text-sm font-medium text-gray-900 px-6 py-4 text-left"></th> | ||
<th scope="col" className="text-sm font-medium text-gray-900 px-6 py-4 text-left">User</th> | ||
<th scope="col" className="text-sm font-medium text-gray-900 px-6 py-4 text-left">Points</th> | ||
<th scope="col" className="text-sm font-medium text-gray-900 px-6 py-4 text-left">Questions</th> | ||
<th scope="col" className="text-sm font-medium text-gray-900 px-6 py-4 text-left">Correct</th> | ||
<th scope="col" className="text-sm font-medium text-gray-900 px-6 py-4 text-left">Wrong</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ | ||
users.map(user => ( | ||
<tr className="border-b"> | ||
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{user.position}</td> | ||
<td className="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">{user.name}</td> | ||
<td className="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">{user.points}</td> | ||
<td className="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">{user.questions}</td> | ||
<td className="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">{user.correct}</td> | ||
<td className="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">{user.wrong}</td> | ||
</tr> | ||
)) | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default RankingsTable; |