Skip to content

Commit

Permalink
Merge pull request #20 from Draft-Bash/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
StephenFeddes authored Sep 20, 2023
2 parents bc72357 + e520b24 commit 0784fab
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/components/DraftRoom/DraftContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface DraftContextType {
setDraftRoomId: React.Dispatch<React.SetStateAction<string | null>>;
setRoster: React.Dispatch<React.SetStateAction<DraftRoster| undefined>>;
roster: DraftRoster | undefined; // Change the type
currentTurnUserId: number;
}

const SocketContext = createContext<DraftContextType | null>(null);
Expand All @@ -27,6 +28,7 @@ export const SocketProvider: React.FC<SocketContextProps> = ({ children }) => {
const [socket, setSocket] = useState<Socket | null>(null);
const [draftRoomId, setDraftRoomId] = useState<string | null>(null);
const [roster, setRoster] = useState<DraftRoster>(); // Change the type
const [currentTurnUserId, setCurrentTurnUserId] = useState(-1);
const { userId } = useAuth();

useEffect(() => {
Expand All @@ -41,6 +43,10 @@ export const SocketProvider: React.FC<SocketContextProps> = ({ children }) => {

useEffect(() => {
socket?.emit('join-room', draftRoomId);
socket?.on('update-draft-turn', (userId: number) => {
setCurrentTurnUserId(userId);
console.log(userId);
});
}, [draftRoomId]);

async function fetchDraftedPlayers() {
Expand Down Expand Up @@ -86,7 +92,8 @@ export const SocketProvider: React.FC<SocketContextProps> = ({ children }) => {
draftRoomId,
setDraftRoomId,
setRoster,
roster
roster,
currentTurnUserId
};

return (
Expand Down
1 change: 1 addition & 0 deletions src/components/DraftRoom/center/CenterHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const CenterHeader = () => {

socket?.on('send-draft-order', (updatedDraftOrder: DraftPick[]) => {
setDraftOrder(updatedDraftOrder);
console.log(updatedDraftOrder)

for (let i = 0; i < updatedDraftOrder.length; i++) {
if (updatedDraftOrder[i].user_id === userId && !updatedDraftOrder[i].is_picked) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/DraftRoom/center/PlayersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const PlayersTable = () => {
const setRoster = draftContext?.setRoster;
const socket = draftContext?.socket;
const [playerList, setPlayerList] = useState<PlayerPreviousSeasonStats[]>();
const currentTurnUserId = draftContext?.currentTurnUserId;
const { userId } = useAuth();


const pickPlayer = (playerId: string, userId: string, draftId: string) => {
socket?.emit('pick-player', playerId, userId, draftId);

}

useEffect(() => {
Expand Down
17 changes: 16 additions & 1 deletion src/components/DraftRoom/header/draftClock.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import '../../../css/draftRoom/draftClock.css';
import React from 'react';
import { useState, useEffect } from 'react';
import { useDraft } from '../DraftContext';

const DraftClock = () => {

const draftContext = useDraft();
const socket = draftContext?.socket;
const draftRoomId = draftContext?.draftRoomId;
const [time, setTime] = useState(0)

useEffect(() => {
if (draftRoomId) {
socket?.on('update-clock', (remainingTime: number) => {
setTime(remainingTime);
});
}
}, [draftRoomId]);

return (
<div className="draft-clock">
00:09
{time}
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
list-style-type:none;
border-spacing: 0px;
font-size: 16px;
user-select: none;
}

a {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/CreateMockDraft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ConfigureMockDraft = () => {
const [utilityPlayerCount, setUtilityPlayerCount] = useState(3);
const [benchSize, setBenchSize] = useState(4);
const [draftRange, setDraftRange] = useState<number[]>([]);
const pickTimes = ["None","30 seconds", "60 seconds", "90 seconds", "120 seconds", "150 seconds"];
const pickTimes = ["30 seconds", "60 seconds", "90 seconds", "120 seconds", "150 seconds"];

const randomizePickPosition = () => {
const randomIndex = Math.floor(Math.random() * draftRange.length);
Expand All @@ -43,7 +43,7 @@ const ConfigureMockDraft = () => {
body: JSON.stringify({
draft_type: draftType,
scoring_type: scoringType,
pick_time_seconds: pickTime,
pick_time_seconds: Number(pickTime.split(" ")[0]),
team_count: teamCount,
pointguard_slots: pointGuardCount,
shootingguard_slots: shootingGuardCount,
Expand Down

0 comments on commit 0784fab

Please sign in to comment.