Skip to content

Commit

Permalink
Merge branch 'main' into reassign_host_on_disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
shammy642 authored Oct 24, 2024
2 parents 6bea420 + d0928ed commit bf9277e
Show file tree
Hide file tree
Showing 18 changed files with 374 additions and 34 deletions.
1 change: 1 addition & 0 deletions api/numberGame/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Player {
this.totalScore = 0
this.nextRound = false
this.avatar = avatar;
this.host = false
}

guess(num) {
Expand Down
14 changes: 13 additions & 1 deletion api/tests/numberGame/Player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@ describe('player', () => {
const player = new Player('17326746', 'Bob')
expect(player.getTotalScore()).toBe(0)
})

test('wonRound adds 1 to total score', () => {
const player = new Player('17326746', 'Bob')
player.wonRound()
expect(player.totalScore).toEqual(1)
})
test('setIsHost makes player isHost true', () => {

test('setIsHost', () => {
const player = new Player('17326746', 'Bob')
player.setIsHost()
expect(player.isHost).toEqual(true)

test('voteNextRound', () => {
const player = new Player('17326746', 'Bob')
player.voteNextRound()
expect(player.nextRound).toEqual(true)
})
test('setAvatar', () => {
const player = new Player('17326746', 'Bob')
player.setAvatar("avatar")
expect(player.avatar).toEqual("avatar")
})
})
5 changes: 5 additions & 0 deletions api/tests/numberGame/game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,9 @@ describe("Game", () => {
fetchMock.resetMocks();
});
});
describe("checkNextRound", () => {
test("given all players next round equals false", () => {
expect(game.checkNextRound()).toEqual(true)
})
})
});
194 changes: 194 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.2",
"@vitejs/plugin-react-swc": "^3.3.2",
"@vitest/coverage-v8": "^2.1.3",
"@vitest/ui": "^2.1.3",
"autoprefixer": "^10.4.20",
"eslint": "^9.11.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { socket } from "../socket";
const avatars = import.meta.glob("/src/assets/*.png", { eager: true });

export function AvatarDropdown({ setAvatar, isOpen, setAvatarOpen}) {
//console.log("Avatar dropdown - avatars", avatars)
const [avatarOptions, setAvatarOptions] = useState([]);

useEffect(() => {
Expand All @@ -21,6 +22,7 @@ export function AvatarDropdown({ setAvatar, isOpen, setAvatarOpen}) {
<>
{isOpen && (
<div

id="dropdownUsers"
className="z-10 bg-white rounded-lg shadow w-60 dark:bg-gray-700"
>
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/components/AvatarPlaceholder.jsx

This file was deleted.

33 changes: 19 additions & 14 deletions frontend/src/components/Table.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { Gold, Silver, Bronze } from "../assets/Medals";

export function Table({ players, sortBy }) {

export function Table({ players, sortBy, showMedals }) {
const position = (number) => {
if (number === 0) {
return <Gold />;
} else if (number === 1) {
return <Silver />
return <Silver />;
} else if (number === 2) {
return <Bronze />
return <Bronze />;
}
return number + 1
return number + 1;
};

return (
<div className="relative overflow-y-auto shadow-md sm:rounded-lg max-h-36 my-6">
<table className="w-full text-sm text-center rtl:text-right text-white dark:text-white">
<thead className="sticky top-0 text-md text-white uppercase bg-gray-50 dark:bg-gray-700 dark:text-white">
<table className="w-full text-sm text-center rtl:text-right text-gray-900 dark:text-white">
<thead className="sticky top-0 text-md text-gray-900 uppercase bg-yellow-300 dark:bg-gray-700 dark:text-white">
<tr>
<th scope="col" className="px-3 py-2">
Pos.
</th>
{showMedals && (
<th scope="col" className="px-3 py-2">
Pos.
</th>
)}
<th scope="col" className="px-3 py-2">
Name
</th>
<th scope="col" className="px-3 py-2">
{sortBy === "totalScore" ? "Score" : "Guess"}
{sortBy === "totalScore" ? "Score" : "Guess"}
</th>
</tr>
</thead>
Expand All @@ -35,7 +36,7 @@ export function Table({ players, sortBy }) {
key={index}
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600"
>
<td className="px-3 py-2">{position(index)}</td>
{showMedals && <td className="px-3 py-2">{position(index)}</td>}
<td className="px-3 py-2">
<div className="flex justify-center items-center">
{" "}
Expand All @@ -49,8 +50,12 @@ export function Table({ players, sortBy }) {
{player.name}
</div>
</td>

<td className="px-3 py-2">{sortBy === "totalScore" ? player.totalScore : player.currentGuess}</td>

<td className="px-3 py-2">
{sortBy === "totalScore"
? player.totalScore
: player.currentGuess}
</td>
</tr>
))}
</tbody>
Expand Down
Loading

0 comments on commit bf9277e

Please sign in to comment.