feat: improve draft admin UI, draft state sync, and styling
Major refactor of Draft admin and participant Websocket state sync Use consistent state dict serialization in DraftStateManager (to_dict, dict-like access, etc.) Always include up-to-date participants and draft status in sync payloads Draft phase/order summary now sent as objects instead of calling .get_summary() UI/UX updates: Updated DraftAdmin.jsx: Connects DraftParticipant panel for real-time participant state Centralizes phase advance, bidding, and sync controls Moves phase selector into a dedicated panel Refine markup/extends in room_admin.dj.html (use block body, fix root data attribute) Minor fixes to DraftCountdownClock.jsx to robustly handle NaN time CSS/layout: Refactor .draft-participant styling to .wrapper within #draft-participant-root and #draft-admin-root for better responsive layout and code clarity Server code: Simplify draft consumer/manager state interaction, drop unused cache keys, update order determination and phase management, and ensure DRY status object responses Small code style and consistency cleanups Misc: Add debugpy launch task in code-workspace and clean workspace JSON (style/consistency) Minor formatting and error handling improvements
This commit is contained in:
@@ -4,7 +4,6 @@ from django.core.exceptions import PermissionDenied
|
||||
from boxofficefantasy.models import League, Season
|
||||
from boxofficefantasy.views import parse_season_slug
|
||||
from draft.models import DraftSession, DraftSessionParticipant
|
||||
from django.core.cache import cache
|
||||
import asyncio
|
||||
from django.contrib.auth.models import User
|
||||
from draft.constants import (
|
||||
@@ -12,7 +11,7 @@ from draft.constants import (
|
||||
DraftPhase,
|
||||
DraftGroupChannelNames,
|
||||
)
|
||||
from draft.state import DraftCacheKeys, DraftStateManager
|
||||
from draft.state import DraftStateManager
|
||||
from typing import Any
|
||||
import logging
|
||||
|
||||
@@ -24,7 +23,6 @@ import random
|
||||
|
||||
class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
||||
group_names: DraftGroupChannelNames
|
||||
cache_keys: DraftCacheKeys
|
||||
draft_state: DraftStateManager
|
||||
user: User
|
||||
|
||||
@@ -39,7 +37,6 @@ class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
||||
)
|
||||
|
||||
self.group_names = DraftGroupChannelNames(draft_hashid)
|
||||
self.cache_keys = DraftCacheKeys(draft_hashid)
|
||||
self.draft_state = DraftStateManager(self.draft_session)
|
||||
|
||||
self.user = self.scope["user"]
|
||||
@@ -49,8 +46,8 @@ class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
||||
{
|
||||
"type": "direct.message",
|
||||
"subtype": DraftMessage.PARTICIPANT_JOIN_REJECT,
|
||||
"payload":{"current_user": self.user.username}
|
||||
}
|
||||
"payload": {"current_user": self.user.username},
|
||||
},
|
||||
)
|
||||
await self.close()
|
||||
await self.channel_layer.group_send(
|
||||
@@ -58,7 +55,7 @@ class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
||||
{
|
||||
"type": "broadcast.admin",
|
||||
"subtype": DraftMessage.PARTICIPANT_JOIN_REJECT,
|
||||
"payload":{"user": self.user.username}
|
||||
"payload": {"user": self.user.username},
|
||||
},
|
||||
)
|
||||
return
|
||||
@@ -80,7 +77,13 @@ class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
||||
{
|
||||
"type": "direct.message",
|
||||
"subtype": DraftMessage.STATUS_SYNC_INFORM,
|
||||
"payload": self.get_draft_status(),
|
||||
"payload": {
|
||||
**self.draft_state,
|
||||
"user": self.user.username,
|
||||
"participants": [
|
||||
user.username for user in self.draft_participants
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
await self.channel_layer.send(
|
||||
@@ -121,11 +124,7 @@ class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
||||
# === Methods ===
|
||||
|
||||
def get_draft_status(self) -> dict[str, Any]:
|
||||
return {
|
||||
**self.draft_state.get_summary(),
|
||||
"user": self.user.username,
|
||||
"participants": [user.username for user in self.draft_participants],
|
||||
}
|
||||
return
|
||||
|
||||
# === DB Access ===
|
||||
@database_sync_to_async
|
||||
@@ -133,8 +132,8 @@ class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
||||
draft_session_id = DraftSession.decode_id(draft_session_id_hashed)
|
||||
if draft_session_id:
|
||||
draft_session = DraftSession.objects.select_related(
|
||||
"season", "season__league", "settings"
|
||||
).get(pk=draft_session_id)
|
||||
"season", "season__league", "settings",
|
||||
).prefetch_related("participants").get(pk=draft_session_id)
|
||||
else:
|
||||
raise Exception()
|
||||
|
||||
@@ -178,13 +177,13 @@ class DraftAdminConsumer(DraftConsumerBase):
|
||||
{
|
||||
"type": "broadcast.session",
|
||||
"subtype": DraftMessage.DRAFT_INDEX_ADVANCE_CONFIRM,
|
||||
"payload": self.draft_state.get_summary(),
|
||||
"payload": {**self.draft_state},
|
||||
},
|
||||
)
|
||||
|
||||
if event_type == DraftMessage.NOMINATION_SUBMIT_REQUEST:
|
||||
movie_id = content.get('payload',{}).get('movie_id')
|
||||
user = content.get('payload',{}).get('user')
|
||||
movie_id = content.get("payload", {}).get("movie_id")
|
||||
user = content.get("payload", {}).get("user")
|
||||
self.draft_state.start_nomination(movie_id)
|
||||
await self.channel_layer.group_send(
|
||||
self.group_names.session,
|
||||
@@ -192,25 +191,23 @@ class DraftAdminConsumer(DraftConsumerBase):
|
||||
"type": "broadcast.session",
|
||||
"subtype": DraftMessage.NOMINATION_CONFIRM,
|
||||
"payload": {
|
||||
"current_movie": self.draft_state.get_summary()['current_movie'],
|
||||
"nominating_participant": user
|
||||
}
|
||||
}
|
||||
"current_movie": self.draft_state[
|
||||
"current_movie"
|
||||
],
|
||||
"nominating_participant": user,
|
||||
},
|
||||
},
|
||||
)
|
||||
if event_type == DraftMessage.BID_START_REQUEST:
|
||||
self.draft_state.start_timer()
|
||||
|
||||
self.draft_state.start_bidding()
|
||||
await self.channel_layer.group_send(
|
||||
self.group_names.session,
|
||||
{
|
||||
"type": "broadcast.session",
|
||||
"subtype": DraftMessage.BID_START_INFORM,
|
||||
"payload": {
|
||||
"current_movie": self.draft_state.get_summary()['current_movie'],
|
||||
"bidding_duration": self.draft_state.settings.bidding_duration,
|
||||
"bidding_timer_end": self.draft_state.get_timer_end(),
|
||||
"bidding_timer_start": self.draft_state.get_timer_start()
|
||||
}
|
||||
}
|
||||
"payload": self.get_draft_status(),
|
||||
},
|
||||
)
|
||||
|
||||
def should_accept_user(self):
|
||||
@@ -229,9 +226,7 @@ class DraftAdminConsumer(DraftConsumerBase):
|
||||
)
|
||||
|
||||
async def determine_draft_order(self):
|
||||
draft_order = self.draft_state.determine_draft_order(self.draft_participants)
|
||||
self.draft_state.draft_index = 0
|
||||
await self.set_draft_phase(DraftPhase.DETERMINE_ORDER)
|
||||
self.draft_state.determine_draft_order()
|
||||
next_picks = self.draft_state.next_picks(include_current=True)
|
||||
|
||||
await self.channel_layer.group_send(
|
||||
@@ -239,12 +234,7 @@ class DraftAdminConsumer(DraftConsumerBase):
|
||||
{
|
||||
"type": "broadcast.session",
|
||||
"subtype": DraftMessage.ORDER_DETERMINE_CONFIRM,
|
||||
"payload": {
|
||||
"draft_order": draft_order,
|
||||
"draft_index": self.draft_state.draft_index,
|
||||
"current_pick": next_picks[0],
|
||||
"next_picks": next_picks[1:]
|
||||
},
|
||||
"payload": {**self.draft_state},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -311,7 +301,7 @@ class DraftParticipantConsumer(DraftConsumerBase):
|
||||
|
||||
async def receive_json(self, content):
|
||||
await super().receive_json(content)
|
||||
event_type = content.get('type')
|
||||
event_type = content.get("type")
|
||||
if event_type == DraftMessage.NOMINATION_SUBMIT_REQUEST:
|
||||
await self.channel_layer.group_send(
|
||||
self.group_names.admin,
|
||||
@@ -319,13 +309,12 @@ class DraftParticipantConsumer(DraftConsumerBase):
|
||||
"type": "broadcast.admin",
|
||||
"subtype": event_type,
|
||||
"payload": {
|
||||
"movie_id": content.get('payload',{}).get('id'),
|
||||
"user": content.get('payload',{}).get('user')
|
||||
}
|
||||
}
|
||||
"movie_id": content.get("payload", {}).get("id"),
|
||||
"user": content.get("payload", {}).get("user"),
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# === Broadcast handlers ===
|
||||
|
||||
async def broadcast_participant(self, event):
|
||||
|
||||
Reference in New Issue
Block a user