Refactor draft app with improved state management and components
* Rename WebSocket message types for better organization * Improve state handling with dedicated methods like broadcast_state * Restructure frontend components and remove unused code
This commit is contained in:
75
data/cache_concept.py
Normal file
75
data/cache_concept.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import pickle
|
||||||
|
import os
|
||||||
|
from typing import Any
|
||||||
|
from pathlib import Path
|
||||||
|
import json
|
||||||
|
|
||||||
|
DEFAULT_PATH = Path("/Users/asc/Developer/boxofficefantasy/main/data/draft_cache.json")
|
||||||
|
|
||||||
|
class CachedDraftState:
|
||||||
|
participants: list
|
||||||
|
phase: str # Replace with Enum if needed
|
||||||
|
draft_order: list = []
|
||||||
|
draft_index: int
|
||||||
|
current_movie: str
|
||||||
|
bids: list
|
||||||
|
|
||||||
|
def __init__(self, cache_file: str = "draft_cache.json"):
|
||||||
|
super().__setattr__("_cache_file", cache_file)
|
||||||
|
super().__setattr__("_cache", self._load_cache())
|
||||||
|
|
||||||
|
def _load_cache(self) -> dict:
|
||||||
|
if os.path.exists(self._cache_file):
|
||||||
|
try:
|
||||||
|
with open(self._cache_file, "r", encoding="utf-8") as f:
|
||||||
|
return json.load(f)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to load cache: {e}")
|
||||||
|
return {}
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def _save_cache(self):
|
||||||
|
try:
|
||||||
|
with open(self._cache_file, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(self._cache, f, indent=2)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to save cache: {e}")
|
||||||
|
|
||||||
|
def __getattr__(self, name: str) -> Any:
|
||||||
|
if name in self.__class__.__annotations__:
|
||||||
|
print(f"[GET] {name} -> {self._cache.get(name)}")
|
||||||
|
return self._cache.get(name, None)
|
||||||
|
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
|
||||||
|
|
||||||
|
def __setattr__(self, name: str, value: Any):
|
||||||
|
if name in self.__class__.__annotations__:
|
||||||
|
print(f"[SET] {name} = {value}")
|
||||||
|
self._cache[name] = value
|
||||||
|
self._save_cache()
|
||||||
|
else:
|
||||||
|
super().__setattr__(name, value)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Clean start for testing
|
||||||
|
if os.path.exists("draft_cache.pkl"):
|
||||||
|
os.remove("draft_cache.pkl")
|
||||||
|
|
||||||
|
print("\n--- First Run: Setting Attributes ---")
|
||||||
|
state = CachedDraftState()
|
||||||
|
state.participants = ["Alice", "Bob"]
|
||||||
|
state.phase = "nominating"
|
||||||
|
# state.draft_order = ["Bob", "Alice"]
|
||||||
|
state.draft_index = 0
|
||||||
|
state.current_movie = "The Matrix"
|
||||||
|
state.bids = [{"Alice": 10}, {"Bob": 12}]
|
||||||
|
|
||||||
|
print("\n--- Second Run: Reading from Cache ---")
|
||||||
|
state2 = CachedDraftState()
|
||||||
|
print("participants:", state2.participants)
|
||||||
|
print("phase:", state2.phase)
|
||||||
|
print("draft_order:", state2.draft_order)
|
||||||
|
print("draft_index:", state2.draft_index)
|
||||||
|
print("current_movie:", state2.current_movie)
|
||||||
|
print("bids:", state2.bids)
|
||||||
|
|
||||||
|
pass
|
||||||
BIN
data/draft_cache.json
Normal file
BIN
data/draft_cache.json
Normal file
Binary file not shown.
@@ -18,8 +18,8 @@ class DraftMessage(StrEnum):
|
|||||||
PHASE_CHANGE_CONFIRM = "phase.change.confirm" # server -> client (target phase payload)
|
PHASE_CHANGE_CONFIRM = "phase.change.confirm" # server -> client (target phase payload)
|
||||||
|
|
||||||
# Status / sync
|
# Status / sync
|
||||||
STATUS_SYNC_REQUEST = "status.sync.request" # client -> server
|
DRAFT_STATUS_REQUEST = "draft.status.request" # client -> server
|
||||||
STATUS_SYNC_INFORM = "status.sync.inform" # server -> client (full/partial state)
|
DRAFT_STATUS_INFORM = "draft.status.sync.inform" # server -> client (full/partial state)
|
||||||
|
|
||||||
DRAFT_INDEX_ADVANCE_REQUEST = "draft.index.advance.request"
|
DRAFT_INDEX_ADVANCE_REQUEST = "draft.index.advance.request"
|
||||||
DRAFT_INDEX_ADVANCE_CONFIRM = "draft.index.advance.confirm"
|
DRAFT_INDEX_ADVANCE_CONFIRM = "draft.index.advance.confirm"
|
||||||
|
|||||||
@@ -72,18 +72,12 @@ class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
|||||||
"payload": {"user": self.user.username},
|
"payload": {"user": self.user.username},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await self.channel_layer.send(
|
await self.channel_layer.group_send(
|
||||||
self.channel_name,
|
self.group_names.session,
|
||||||
{
|
{
|
||||||
"type": "direct.message",
|
"type": "direct.message",
|
||||||
"subtype": DraftMessage.STATUS_SYNC_INFORM,
|
"subtype": DraftMessage.DRAFT_STATUS_INFORM,
|
||||||
"payload": {
|
"payload": self.draft_state.to_dict(),
|
||||||
**self.draft_state,
|
|
||||||
"user": self.user.username,
|
|
||||||
"participants": [
|
|
||||||
user.username for user in self.draft_participants
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await self.channel_layer.send(
|
await self.channel_layer.send(
|
||||||
@@ -101,14 +95,37 @@ class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
|||||||
async def receive_json(self, content):
|
async def receive_json(self, content):
|
||||||
logger.info(f"receiving message {content}")
|
logger.info(f"receiving message {content}")
|
||||||
event_type = content.get("type")
|
event_type = content.get("type")
|
||||||
if event_type == DraftMessage.STATUS_SYNC_REQUEST:
|
if event_type == DraftMessage.DRAFT_STATUS_REQUEST:
|
||||||
await self.send_json(
|
await self.send_json(
|
||||||
{
|
{
|
||||||
"type": DraftMessage.STATUS_SYNC_INFORM,
|
"type": DraftMessage.DRAFT_STATUS_INFORM,
|
||||||
"payload": self.get_draft_status(),
|
"payload": self.get_draft_status(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# --- Convenience helpers ---
|
||||||
|
async def send_draft_state(self):
|
||||||
|
"""Send the current draft state only to this client."""
|
||||||
|
await self.channel_layer.send(
|
||||||
|
self.channel_name,
|
||||||
|
{
|
||||||
|
"type": "direct.message",
|
||||||
|
"subtype": DraftMessage.DRAFT_STATUS_INFORM,
|
||||||
|
"payload": self.draft_state.to_dict(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
async def broadcast_state(self):
|
||||||
|
"""Broadcast current draft state to all in session group."""
|
||||||
|
await self.channel_layer.group_send(
|
||||||
|
self.group_names.session,
|
||||||
|
{
|
||||||
|
"type": "broadcast.session",
|
||||||
|
"subtype": DraftMessage.DRAFT_STATUS_INFORM,
|
||||||
|
"payload": self.draft_state.to_dict(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
# Broadcast Handlers
|
# Broadcast Handlers
|
||||||
async def direct_message(self, event):
|
async def direct_message(self, event):
|
||||||
await self._dispatch_broadcast(event)
|
await self._dispatch_broadcast(event)
|
||||||
@@ -132,9 +149,15 @@ class DraftConsumerBase(AsyncJsonWebsocketConsumer):
|
|||||||
def get_draft_session(self, draft_session_id_hashed) -> DraftSession:
|
def get_draft_session(self, draft_session_id_hashed) -> DraftSession:
|
||||||
draft_session_id = DraftSession.decode_id(draft_session_id_hashed)
|
draft_session_id = DraftSession.decode_id(draft_session_id_hashed)
|
||||||
if draft_session_id:
|
if draft_session_id:
|
||||||
draft_session = DraftSession.objects.select_related(
|
draft_session = (
|
||||||
"season", "season__league", "settings",
|
DraftSession.objects.select_related(
|
||||||
).prefetch_related("participants").get(pk=draft_session_id)
|
"season",
|
||||||
|
"season__league",
|
||||||
|
"settings",
|
||||||
|
)
|
||||||
|
.prefetch_related("participants")
|
||||||
|
.get(pk=draft_session_id)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
|
|
||||||
@@ -155,89 +178,85 @@ class DraftAdminConsumer(DraftConsumerBase):
|
|||||||
|
|
||||||
await self.channel_layer.group_add(self.group_names.admin, self.channel_name)
|
await self.channel_layer.group_add(self.group_names.admin, self.channel_name)
|
||||||
|
|
||||||
|
def should_accept_user(self):
|
||||||
|
return super().should_accept_user() and self.user.is_staff
|
||||||
|
|
||||||
async def receive_json(self, content):
|
async def receive_json(self, content):
|
||||||
await super().receive_json(content)
|
await super().receive_json(content)
|
||||||
logger.info(f"Receive message {content}")
|
logger.info(f"Receive message {content}")
|
||||||
event_type = content.get("type")
|
event_type = content.get("type")
|
||||||
if (
|
|
||||||
event_type == DraftMessage.PHASE_CHANGE_REQUEST
|
|
||||||
and content.get("destination") == DraftPhase.DETERMINE_ORDER
|
|
||||||
):
|
|
||||||
await self.determine_draft_order()
|
|
||||||
|
|
||||||
if (
|
match event_type:
|
||||||
event_type == DraftMessage.PHASE_CHANGE_REQUEST
|
case DraftMessage.PHASE_CHANGE_REQUEST:
|
||||||
and content.get("destination") == DraftPhase.NOMINATING
|
destination = content.get('destination')
|
||||||
):
|
match destination:
|
||||||
await self.start_nominate()
|
case DraftPhase.DETERMINE_ORDER:
|
||||||
|
await self.set_draft_phase(DraftPhase.DETERMINE_ORDER)
|
||||||
|
self.draft_state.determine_draft_order()
|
||||||
|
await self.channel_layer.group_send(
|
||||||
|
self.group_names.session,
|
||||||
|
{
|
||||||
|
"type": "broadcast.session",
|
||||||
|
"subtype": DraftMessage.ORDER_DETERMINE_CONFIRM,
|
||||||
|
"payload": {"draft_order": self.draft_state.draft_order},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await self.broadcast_state()
|
||||||
|
|
||||||
if event_type == DraftMessage.DRAFT_INDEX_ADVANCE_REQUEST:
|
case DraftPhase.NOMINATING:
|
||||||
self.draft_state.draft_index_advance()
|
await self.set_draft_phase(DraftPhase.NOMINATING)
|
||||||
await self.channel_layer.group_send(
|
await self.channel_layer.group_send(
|
||||||
self.group_names.session,
|
self.group_names.session,
|
||||||
{
|
{
|
||||||
"type": "broadcast.session",
|
"type": "broadcast.session",
|
||||||
"subtype": DraftMessage.DRAFT_INDEX_ADVANCE_CONFIRM,
|
"subtype": DraftMessage.PHASE_CHANGE_CONFIRM,
|
||||||
"payload": {**self.draft_state},
|
"payload": {"phase": self.draft_state.phase},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
await self.broadcast_state()
|
||||||
|
|
||||||
if event_type == DraftMessage.NOMINATION_SUBMIT_REQUEST:
|
case DraftMessage.DRAFT_INDEX_ADVANCE_REQUEST:
|
||||||
movie_id = content.get("payload", {}).get("movie_id")
|
self.draft_state.draft_index_advance()
|
||||||
user = content.get("payload", {}).get("user")
|
await self.channel_layer.group_send(
|
||||||
self.draft_state.start_nomination(movie_id)
|
self.group_names.session,
|
||||||
await self.channel_layer.group_send(
|
{
|
||||||
self.group_names.session,
|
"type": "broadcast.session",
|
||||||
{
|
"subtype": DraftMessage.DRAFT_INDEX_ADVANCE_CONFIRM,
|
||||||
"type": "broadcast.session",
|
"payload": {"draft_index": self.draft_state.draft_index},
|
||||||
"subtype": DraftMessage.NOMINATION_CONFIRM,
|
|
||||||
"payload": {
|
|
||||||
"current_movie": self.draft_state[
|
|
||||||
"current_movie"
|
|
||||||
],
|
|
||||||
"nominating_participant": user,
|
|
||||||
},
|
},
|
||||||
},
|
)
|
||||||
)
|
await self.broadcast_state()
|
||||||
if event_type == DraftMessage.BID_START_REQUEST:
|
|
||||||
|
|
||||||
self.draft_state.start_bidding()
|
case DraftMessage.NOMINATION_SUBMIT_REQUEST:
|
||||||
await self.channel_layer.group_send(
|
movie_id = content.get("payload", {}).get("movie_id")
|
||||||
self.group_names.session,
|
user = content.get("payload", {}).get("user")
|
||||||
{
|
self.draft_state.start_nomination(movie_id)
|
||||||
"type": "broadcast.session",
|
await self.channel_layer.group_send(
|
||||||
"subtype": DraftMessage.BID_START_INFORM,
|
self.group_names.session,
|
||||||
"payload": {**self.draft_state},
|
{
|
||||||
},
|
"type": "broadcast.session",
|
||||||
)
|
"subtype": DraftMessage.NOMINATION_CONFIRM,
|
||||||
|
"payload": {
|
||||||
|
"current_movie": self.draft_state["current_movie"],
|
||||||
|
"nominating_participant": user,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await self.broadcast_state()
|
||||||
|
|
||||||
def should_accept_user(self):
|
case DraftMessage.BID_START_REQUEST:
|
||||||
return super().should_accept_user() and self.user.is_staff
|
self.draft_state.start_bidding()
|
||||||
|
await self.channel_layer.group_send(
|
||||||
|
self.group_names.session,
|
||||||
|
{
|
||||||
|
"type": "broadcast.session",
|
||||||
|
"subtype": DraftMessage.BID_START_INFORM,
|
||||||
|
"payload": {**self.draft_state},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await self.broadcast_state()
|
||||||
|
|
||||||
# === Draft logic ===
|
# === Draft logic ===
|
||||||
async def start_nominate(self):
|
|
||||||
await self.set_draft_phase(DraftPhase.NOMINATING)
|
|
||||||
await self.channel_layer.group_send(
|
|
||||||
self.group_names.session,
|
|
||||||
{
|
|
||||||
"type": "broadcast.session",
|
|
||||||
"subtype": DraftMessage.PHASE_CHANGE_CONFIRM,
|
|
||||||
"payload": {"phase": self.draft_state.phase},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
async def determine_draft_order(self):
|
|
||||||
self.draft_state.determine_draft_order()
|
|
||||||
next_picks = self.draft_state.next_picks(include_current=True)
|
|
||||||
|
|
||||||
await self.channel_layer.group_send(
|
|
||||||
self.group_names.session,
|
|
||||||
{
|
|
||||||
"type": "broadcast.session",
|
|
||||||
"subtype": DraftMessage.ORDER_DETERMINE_CONFIRM,
|
|
||||||
"payload": {**self.draft_state},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
async def set_draft_phase(self, destination: DraftPhase):
|
async def set_draft_phase(self, destination: DraftPhase):
|
||||||
self.draft_state.phase = destination
|
self.draft_state.phase = destination
|
||||||
@@ -269,7 +288,9 @@ class DraftParticipantConsumer(DraftConsumerBase):
|
|||||||
"subtype": DraftMessage.PARTICIPANT_JOIN_CONFIRM,
|
"subtype": DraftMessage.PARTICIPANT_JOIN_CONFIRM,
|
||||||
"payload": {
|
"payload": {
|
||||||
"user": self.user.username,
|
"user": self.user.username,
|
||||||
"connected_participants": list(self.draft_state.connected_participants),
|
"connected_participants": list(
|
||||||
|
self.draft_state.connected_participants
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -287,7 +308,9 @@ class DraftParticipantConsumer(DraftConsumerBase):
|
|||||||
"subtype": DraftMessage.PARTICIPANT_LEAVE_INFORM,
|
"subtype": DraftMessage.PARTICIPANT_LEAVE_INFORM,
|
||||||
"payload": {
|
"payload": {
|
||||||
"user": self.user.username,
|
"user": self.user.username,
|
||||||
"connected_participants": list(self.draft_state.connected_participants),
|
"connected_participants": list(
|
||||||
|
self.draft_state.connected_participants
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -315,9 +338,9 @@ class DraftParticipantConsumer(DraftConsumerBase):
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if event_type == DraftMessage.BID_PLACE_REQUEST:
|
if event_type == DraftMessage.BID_PLACE_REQUEST:
|
||||||
bid_amount = content.get('payload',{}).get('bid_amount')
|
bid_amount = content.get("payload", {}).get("bid_amount")
|
||||||
self.draft_state.place_bid(self.user, bid_amount)
|
self.draft_state.place_bid(self.user, bid_amount)
|
||||||
await self.channel_layer.group_send(
|
await self.channel_layer.group_send(
|
||||||
self.group_names.session,
|
self.group_names.session,
|
||||||
|
|||||||
@@ -65,10 +65,11 @@ class DraftCache:
|
|||||||
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
|
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
|
||||||
|
|
||||||
class DraftStateManager:
|
class DraftStateManager:
|
||||||
|
_initial_phase: DraftPhase = DraftPhase.WAITING.value
|
||||||
|
|
||||||
def __init__(self, session: DraftSession):
|
def __init__(self, session: DraftSession):
|
||||||
self.session_id: str = session.hashid
|
self.session_id: str = session.hashid
|
||||||
self.cache: DraftCache = DraftCache(self.session_id, cache)
|
self.cache: DraftCache = DraftCache(self.session_id, cache)
|
||||||
self._initial_phase: DraftPhase = self.cache.phase or DraftPhase.WAITING.value
|
|
||||||
self.settings: DraftSessionSettings = session.settings
|
self.settings: DraftSessionSettings = session.settings
|
||||||
self.participants: set[User] = set(session.participants.all())
|
self.participants: set[User] = set(session.participants.all())
|
||||||
self.connected_participants: set[User] = set()
|
self.connected_participants: set[User] = set()
|
||||||
@@ -76,7 +77,7 @@ class DraftStateManager:
|
|||||||
# === Phase Management ===
|
# === Phase Management ===
|
||||||
@property
|
@property
|
||||||
def phase(self) -> str:
|
def phase(self) -> str:
|
||||||
return self.cache.phase
|
return self.cache.phase or self._initial_phase
|
||||||
|
|
||||||
@phase.setter
|
@phase.setter
|
||||||
def phase(self, new_phase: DraftPhase) -> None:
|
def phase(self, new_phase: DraftPhase) -> None:
|
||||||
@@ -106,7 +107,7 @@ class DraftStateManager:
|
|||||||
self.phase = DraftPhase.DETERMINE_ORDER
|
self.phase = DraftPhase.DETERMINE_ORDER
|
||||||
self.draft_index = 0
|
self.draft_index = 0
|
||||||
draft_order = random.sample(
|
draft_order = random.sample(
|
||||||
self.participants, len(self.participants)
|
list(self.participants), len(self.participants)
|
||||||
)
|
)
|
||||||
self.draft_order = [user.username for user in draft_order]
|
self.draft_order = [user.username for user in draft_order]
|
||||||
return self.draft_order
|
return self.draft_order
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
<script>
|
<script>
|
||||||
window.draftSessionId = "{{ draft_id_hashed }}"
|
window.draftSessionId = "{{ draft_id_hashed }}"
|
||||||
|
console.log("{{user}}")
|
||||||
</script>
|
</script>
|
||||||
<div id="draft-participant-root" data-draft-id="{{ draft_id_hashed }}"></div>
|
<div id="draft-participant-root" data-draft-id="{{ draft_id_hashed }}"></div>
|
||||||
|
{% if user.is_staff %}
|
||||||
|
<div id="draft-admin-bar-root" data-draft-id="{{ draft_id_hashed }}">You are admin!</div>
|
||||||
|
{% endif %}
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
@@ -6,6 +6,7 @@ app_name = "draft"
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# path("", views.draft_room, name="room"),
|
# path("", views.draft_room, name="room"),
|
||||||
path("session/<str:draft_session_id_hashed>/", views.draft_room, name="session"),
|
path("session/<str:draft_session_id_hashed>/", views.draft_room, name="session"),
|
||||||
path("session/<str:draft_session_id_hashed>/<str:subpage>", views.draft_room, name="admin_session"),
|
path("session/<str:draft_session_id_hashed>/debug", views.draft_room_debug, name="session"),
|
||||||
|
# path("session/<str:draft_session_id_hashed>/<str:subpage>", views.draft_room, name="admin_session"),
|
||||||
# path("<slug:league_slug>/<slug:season_slug>/", views.draft_room_list, name="room"),
|
# path("<slug:league_slug>/<slug:season_slug>/", views.draft_room_list, name="room"),
|
||||||
]
|
]
|
||||||
@@ -6,28 +6,22 @@ from django.contrib.auth.decorators import login_required
|
|||||||
from boxofficefantasy_project.utils import decode_id
|
from boxofficefantasy_project.utils import decode_id
|
||||||
|
|
||||||
@login_required(login_url='/login/')
|
@login_required(login_url='/login/')
|
||||||
def draft_room(request, league_slug=None, season_slug=None, draft_session_id_hashed=None, subpage=""):
|
def draft_room(request, draft_session_id_hashed=None):
|
||||||
if draft_session_id_hashed:
|
if draft_session_id_hashed:
|
||||||
draft_session_id = decode_id(draft_session_id_hashed)
|
draft_session_id = decode_id(draft_session_id_hashed)
|
||||||
draft_session = get_object_or_404(DraftSession, id=draft_session_id)
|
draft_session = get_object_or_404(DraftSession, id=draft_session_id)
|
||||||
league = draft_session.season.league
|
league = draft_session.season.league
|
||||||
season = draft_session.season
|
season = draft_session.season
|
||||||
elif league_slug and season_slug:
|
|
||||||
raise NotImplementedError
|
|
||||||
league = get_object_or_404(League, slug=league_slug)
|
|
||||||
label, year = parse_season_slug(season_slug)
|
|
||||||
season = get_object_or_404(Season, league=league, label__iexact=label, year=year)
|
|
||||||
draft_session = get_object_or_404(DraftSession, season=season)
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"draft_id_hashed": draft_session.hashid,
|
"draft_id_hashed": draft_session.hashid,
|
||||||
"league": league,
|
"league": league,
|
||||||
"season": season,
|
"season": season,
|
||||||
}
|
}
|
||||||
|
return render(request, "draft/room.dj.html", context)
|
||||||
|
|
||||||
if subpage == "admin":
|
def draft_room_debug(request, draft_session_id_hashed=None):
|
||||||
return render(request, "draft/room_admin.dj.html", context)
|
if draft_session_id_hashed:
|
||||||
elif subpage == "debug":
|
draft_session_id = decode_id(draft_session_id_hashed)
|
||||||
return render(request, "draft/room_debug.dj.html", context)
|
draft_session = get_object_or_404(DraftSession, id=draft_session_id)
|
||||||
else:
|
return render(request, "draft/room_debug.dj.html", {"draft_id_hashed": draft_session.hashid,})
|
||||||
return render(request, "draft/room.dj.html", context)
|
|
||||||
21
draft_cache.json
Normal file
21
draft_cache.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"participants": [
|
||||||
|
"Alice",
|
||||||
|
"Bob"
|
||||||
|
],
|
||||||
|
"phase": "nominating",
|
||||||
|
"draft_order": [
|
||||||
|
"Bob",
|
||||||
|
"Alice"
|
||||||
|
],
|
||||||
|
"draft_index": 0,
|
||||||
|
"current_movie": "The Matrix",
|
||||||
|
"bids": [
|
||||||
|
{
|
||||||
|
"Alice": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Bob": 12
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { useWebSocket } from "../common/WebSocketContext.jsx";
|
import { useWebSocket } from "./components/WebSocketContext.jsx";
|
||||||
import { WebSocketStatus } from "../common/WebSocketStatus.jsx";
|
|
||||||
import { ParticipantList } from "../common/ParticipantList.jsx";
|
import { DraftMessage, DraftPhase, DraftPhaseLabel, DraftPhasesOrdered } from './constants.js';
|
||||||
import { DraftMessage, DraftPhase, DraftPhaseLabel, DraftPhasesOrdered } from '../constants.js';
|
import { fetchDraftDetails, isEmptyObject, handleDraftStatusMessages, handleUserIdentifyMessages } from "./utils.js"
|
||||||
import { fetchDraftDetails, isEmptyObject, handleDraftStatusMessages, handleUserIdentifyMessages } from "../common/utils.js"
|
|
||||||
import { DraftMoviePool } from "../common/DraftMoviePool.jsx"
|
|
||||||
import { DraftCountdownClock } from "../common/DraftCountdownClock.jsx"
|
|
||||||
import { DraftParticipant } from "../participant/DraftParticipant.jsx";
|
|
||||||
import { jsxs } from "react/jsx-runtime";
|
import { jsxs } from "react/jsx-runtime";
|
||||||
|
|
||||||
|
|
||||||
@@ -102,7 +99,6 @@ export const DraftAdmin = ({ draftSessionId }) => {
|
|||||||
else if (target == "previous" && originPhaseIndex > 0) {
|
else if (target == "previous" && originPhaseIndex > 0) {
|
||||||
destination = DraftPhasesOrdered[originPhaseIndex - 1]
|
destination = DraftPhasesOrdered[originPhaseIndex - 1]
|
||||||
}
|
}
|
||||||
console.log(destination)
|
|
||||||
socket.send(
|
socket.send(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
{ type: DraftMessage.PHASE_CHANGE_REQUEST, origin, destination }
|
{ type: DraftMessage.PHASE_CHANGE_REQUEST, origin, destination }
|
||||||
@@ -140,22 +136,15 @@ export const DraftAdmin = ({ draftSessionId }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="">
|
<div id="draft-admin-bar">
|
||||||
<div className="">
|
<div>
|
||||||
<DraftParticipant draftSessionId={draftSessionId}></DraftParticipant>
|
|
||||||
<div className="d-flex justify-content-between border-bottom mb-2 p-1">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<section className="d-flex justify-content-center mt-3">
|
|
||||||
<button onClick={() => handleRequestDraftSummary()} className="btn btn-small btn-light mx-1">
|
<button onClick={() => handleRequestDraftSummary()} className="btn btn-small btn-light mx-1">
|
||||||
<i className="bi bi-arrow-clockwise"></i>
|
<i className="bi bi-arrow-clockwise"></i>
|
||||||
</button>
|
</button>
|
||||||
<button onClick={handleAdvanceDraft} className="btn btn-primary mx-1">Advance Index</button>
|
<button onClick={handleAdvanceDraft} className="btn btn-primary mx-1">Advance Index</button>
|
||||||
<button onClick={handleStartBidding} className="btn btn-primary mx-1">Start Bidding</button>
|
<button onClick={handleStartBidding} className="btn btn-primary mx-1">Start Bidding</button>
|
||||||
</section>
|
</div>
|
||||||
|
<div>
|
||||||
<div class="d-flex justify-content-center mt-3">
|
|
||||||
<DraftPhaseDisplay draftPhase={draftState.phase} nextPhaseHandler={() => { handlePhaseChange('next') }} prevPhaseHandler={() => { handlePhaseChange('previous') }}></DraftPhaseDisplay>
|
<DraftPhaseDisplay draftPhase={draftState.phase} nextPhaseHandler={() => { handlePhaseChange('next') }} prevPhaseHandler={() => { handlePhaseChange('previous') }}></DraftPhaseDisplay>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
// DraftAdmin.jsx
|
// DraftAdmin.jsx
|
||||||
import React, { useEffect, useState, useRef } from "react";
|
import React, { useEffect, useState, useRef } from "react";
|
||||||
|
|
||||||
import { useWebSocket } from "../common/WebSocketContext.jsx";
|
import { useWebSocket } from "./components/WebSocketContext.jsx";
|
||||||
import { WebSocketStatus } from "../common/WebSocketStatus.jsx";
|
import { WebSocketStatus } from "./components/WebSocketStatus.jsx";
|
||||||
import { DraftMessage, DraftPhaseLabel, DraftPhases } from '../constants.js';
|
import { DraftMessage, DraftPhaseLabel, DraftPhases } from './constants.js';
|
||||||
import { fetchDraftDetails, handleUserIdentifyMessages, isEmptyObject } from "../common/utils.js";
|
import { fetchDraftDetails, handleUserIdentifyMessages, isEmptyObject } from "./utils.js";
|
||||||
import { DraftMoviePool } from "../common/DraftMoviePool.jsx";
|
import { DraftMoviePool } from "./components/DraftMoviePool.jsx";
|
||||||
import { ParticipantList } from "../common/ParticipantList.jsx";
|
import { ParticipantList } from "./components/ParticipantList.jsx";
|
||||||
import { DraftCountdownClock } from "../common/DraftCountdownClock.jsx"
|
import { DraftCountdownClock } from "./components/DraftCountdownClock.jsx"
|
||||||
import { handleDraftStatusMessages } from '../common/utils.js'
|
import { handleDraftStatusMessages } from './utils.js'
|
||||||
// import { Collapse } from 'bootstrap/dist/js/bootstrap.bundle.min.js';
|
// import { Collapse } from 'bootstrap/dist/js/bootstrap.bundle.min.js';
|
||||||
import { Collapse, ListGroup } from "react-bootstrap";
|
import { Collapse, ListGroup } from "react-bootstrap";
|
||||||
|
|
||||||
@@ -62,6 +62,7 @@ const NominateMenu = ({ socket, draftState, draftDetails, currentUser, }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const DraftParticipant = ({ draftSessionId }) => {
|
export const DraftParticipant = ({ draftSessionId }) => {
|
||||||
|
|
||||||
const socket = useWebSocket();
|
const socket = useWebSocket();
|
||||||
const [draftState, setDraftState] = useState({});
|
const [draftState, setDraftState] = useState({});
|
||||||
const [draftDetails, setDraftDetails] = useState({});
|
const [draftDetails, setDraftDetails] = useState({});
|
||||||
@@ -79,13 +80,6 @@ export const DraftParticipant = ({ draftSessionId }) => {
|
|||||||
})
|
})
|
||||||
}, [draftSessionId])
|
}, [draftSessionId])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!socket) return;
|
|
||||||
socket.onclose = (event) => {
|
|
||||||
console.log('Websocket Closed')
|
|
||||||
}
|
|
||||||
}, [socket])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!socket) return;
|
if (!socket) return;
|
||||||
|
|
||||||
@@ -116,80 +110,88 @@ export const DraftParticipant = ({ draftSessionId }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="wrapper">
|
<div className="wrapper">
|
||||||
<section className="panel draft-live">
|
<section id="draft-live">
|
||||||
<header className="panel-header">
|
<div className="panel">
|
||||||
<h2 className="panel-title">Draft Live</h2>
|
<header className="panel-header">
|
||||||
<div className="d-flex gap-1">
|
<div className="panel-title"><span>Draft Live</span></div>
|
||||||
<div className="phase-indicator badge bg-primary">{DraftPhaseLabel[draftState.phase]}</div>
|
<div className="d-flex gap-1">
|
||||||
<WebSocketStatus socket={socket} />
|
<div className="phase-indicator badge bg-primary">{DraftPhaseLabel[draftState.phase]}</div>
|
||||||
</div>
|
<WebSocketStatus socket={socket} />
|
||||||
</header>
|
|
||||||
<div className="panel-body">
|
|
||||||
<div className="draft-live-state-container">
|
|
||||||
<DraftCountdownClock endTime={draftState.bidding_timer_end}></DraftCountdownClock>
|
|
||||||
<div className="pick-description">
|
|
||||||
{console.log("draft_state", draftState)}
|
|
||||||
<div>Round {draftState.current_pick?.round}</div>
|
|
||||||
<div>Pick {draftState.current_pick?.pick_in_round}</div>
|
|
||||||
<div>{draftState.current_pick?.overall + 1} Overall</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</header>
|
||||||
<div className="bid-status">
|
<div className="panel-body">
|
||||||
<div className="d-flex">
|
<div id="draft-clock">
|
||||||
<div className="flex-grow-1 text-center">
|
<DraftCountdownClock draftState={draftState}></DraftCountdownClock>
|
||||||
{draftState.bids?.length > 0 ? Math.max(draftState.bids?.map(i=>i.bid_amount)) : ""}
|
<div className="pick-description">
|
||||||
|
<div>Round {draftState.current_pick?.round}</div>
|
||||||
|
<div>Pick {draftState.current_pick?.pick_in_round}</div>
|
||||||
|
<div>{draftState.current_pick?.overall + 1} Overall</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-grow-1 text-center">
|
</div>
|
||||||
highest bid
|
<div className="bid-controls btn-group d-flex flex-column">
|
||||||
|
|
||||||
|
<a className="btn btn-primary d-none" data-bs-toggle="collapse" aria-expanded="true" aria-controls="collapse-1" href="#collapse-1" role="button">Show Content</a>
|
||||||
|
<div id="collapse-1" className="collapse show">
|
||||||
|
<div>
|
||||||
|
<div className="row g-0 border rounded-2 m-2">
|
||||||
|
<div className="col-3"><img className="img-fluid flex-fill" /></div>
|
||||||
|
<div className="col d-flex justify-content-center align-items-center">
|
||||||
|
<span className="fw-bold">Movie title</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="lh-sm text-center border p-0 border-bottom"><span>Bids</span></div>
|
||||||
|
<div className="bids-container">
|
||||||
|
<ol className="list-group list-group-flush">
|
||||||
|
{draftState.bids?.reverse().map((b,idx) => (
|
||||||
|
<li key={idx} className="list-group-item p-0">
|
||||||
|
<div className="row g-0">
|
||||||
|
<div className="col-8 col-xl-9 col-xxl-10"><span>{b.user}</span></div>
|
||||||
|
<div className="col"><span>{b.amount}</span></div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="p-1">
|
||||||
|
<form id="bid" onSubmit={submitBidRequest}>
|
||||||
|
<div className="input-group input-group-sm">
|
||||||
|
<span className="input-group-text">Bid</span>
|
||||||
|
<input className="form-control" type="number" id="bidAmount" name="bidAmount"/>
|
||||||
|
<button className="btn btn-primary" type="submit">Submit</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<ol className="bid-list">
|
<ul className="pick-list">
|
||||||
{draftState.bids?.map((bid, idx) => (
|
<li>
|
||||||
<li key={idx}>{bid.user}: {bid.amount}</li>
|
<div>Current Pick: {draftState.current_pick?.participant}</div>
|
||||||
))}
|
</li>
|
||||||
</ol>
|
<li
|
||||||
|
>
|
||||||
|
<div>Next Pick: {draftState.next_picks ? draftState.next_picks[0]?.participant : ""}</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div className="bid-controls btn-group d-flex flex-column">
|
|
||||||
<form id="bid" onSubmit={submitBidRequest}>
|
|
||||||
<div className="d-flex">
|
|
||||||
<div className="flex-grow-1 text-center">
|
|
||||||
<input type="number" id="bidAmount" name="bidAmount"></input>
|
|
||||||
</div>
|
|
||||||
<div className="flex-grow-1 text-center">
|
|
||||||
<button className="flex-grow-1">Submit</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="d-flex">
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<ul className="pick-list">
|
|
||||||
<li>
|
|
||||||
<div>Current Pick: {draftState.current_pick?.participant}</div>
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
>
|
|
||||||
<div>Next Pick: {draftState.next_picks ? draftState.next_picks[0]?.participant : ""}</div>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className="panel draft-catalog">
|
<section className="panel" id="draft-slate">
|
||||||
<header className="panel-header">
|
<header className="panel-header">
|
||||||
<h2 className="panel-title">Draft Catalog</h2>
|
<div className="panel-title"><span>Draft Catalog</span></div>
|
||||||
</header>
|
</header>
|
||||||
<div className="panel-body">
|
<div className="panel-body">
|
||||||
<div className="current-movie card">
|
<div className="current-movie card">
|
||||||
<span>Current Nomination: {movies.find(i => draftState.current_movie == i.id)?.title}</span>
|
<span>Current Nomination: {movies.find(i => draftState.current_movie == i.id)?.title}</span>
|
||||||
</div>
|
</div>
|
||||||
<NominateMenu socket={socket} currentUser={currentUser} draftState={draftState} draftDetails={draftDetails}></NominateMenu>
|
{/* <NominateMenu socket={socket} currentUser={currentUser} draftState={draftState} draftDetails={draftDetails}></NominateMenu> */}
|
||||||
<div className="movie-filters"></div>
|
<div className="movie-filters"></div>
|
||||||
|
|
||||||
<DraftMoviePool isParticipant={true} draftDetails={draftDetails} draftState={draftState}></DraftMoviePool>
|
<DraftMoviePool isParticipant={true} draftDetails={draftDetails} draftState={draftState}></DraftMoviePool>
|
||||||
@@ -199,7 +201,7 @@ export const DraftParticipant = ({ draftSessionId }) => {
|
|||||||
|
|
||||||
<section className="panel my-team">
|
<section className="panel my-team">
|
||||||
<header className="panel-header">
|
<header className="panel-header">
|
||||||
<h2 className="panel-title">My Team</h2>
|
<div className="panel-title"><span>My Team</span></div>
|
||||||
</header>
|
</header>
|
||||||
<div className="panel-body">
|
<div className="panel-body">
|
||||||
<ul className="team-movie-list list-group">
|
<ul className="team-movie-list list-group">
|
||||||
@@ -212,21 +214,18 @@ export const DraftParticipant = ({ draftSessionId }) => {
|
|||||||
|
|
||||||
<section className="panel teams">
|
<section className="panel teams">
|
||||||
<header className="panel-header">
|
<header className="panel-header">
|
||||||
<h2 className="panel-title">Teams</h2>
|
<div className="panel-title"><span>Teams</span></div>
|
||||||
</header>
|
</header>
|
||||||
<div className="panel-body">
|
<div className="panel-body">
|
||||||
<ParticipantList
|
|
||||||
currentUser={currentUser}
|
|
||||||
draftState={draftState}
|
|
||||||
draftDetails={draftDetails}
|
|
||||||
/>
|
|
||||||
<ul className="team-list list-group">
|
<ul className="team-list list-group">
|
||||||
<li className="team-item list-group-item">
|
{draftState.participants?.map(p => (
|
||||||
<div className="team-name fw-bold"></div>
|
<li className="team-item list-group-item" key={p}>
|
||||||
<ul className="team-movie-list list-group list-group-flush">
|
<div className="team-name fw-bold">{p}</div>
|
||||||
<li className="team-movie-item list-group-item"></li>
|
<ul className="team-movie-list list-group list-group-flush">
|
||||||
</ul>
|
<li className="team-movie-item list-group-item"></li>
|
||||||
</li>
|
</ul>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState } from "react";;
|
import React, { useEffect, useState } from "react";;
|
||||||
import { useWebSocket } from "./common/WebSocketContext.jsx";
|
import { useWebSocket } from "./components/WebSocketContext.jsx";
|
||||||
import { DraftMessage, DraftPhase, DraftPhaseLabel, DraftPhasesOrdered } from './constants.js';
|
import { DraftMessage, DraftPhase, DraftPhaseLabel, DraftPhasesOrdered } from './constants.js';
|
||||||
import { fetchDraftDetails, isEmptyObject, handleDraftStatusMessages, handleUserIdentifyMessages } from "./common/utils.js"
|
import { fetchDraftDetails, isEmptyObject, handleDraftStatusMessages, handleUserIdentifyMessages } from "./utils.js"
|
||||||
|
|
||||||
export const DraftDebug = ({ draftSessionId }) => {
|
export const DraftDebug = ({ draftSessionId }) => {
|
||||||
const [draftState, setDraftState] = useState({})
|
const [draftState, setDraftState] = useState({})
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
export function DraftCountdownClock({ endTime, onFinish }) {
|
export function DraftCountdownClock({ draftState }) {
|
||||||
// endTime is in seconds (Unix time)
|
// endTime is in seconds (Unix time)
|
||||||
|
const {bidding_timer_end, onFinish} = draftState
|
||||||
const getTimeLeft = (et) => Math.max(0, Math.floor(et - Date.now() / 1000));
|
const getTimeLeft = (et) => Math.max(0, Math.floor(et - Date.now() / 1000));
|
||||||
const [timeLeft, setTimeLeft] = useState(getTimeLeft(endTime));
|
const [timeLeft, setTimeLeft] = useState(getTimeLeft(bidding_timer_end));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (timeLeft <= 0) {
|
if (timeLeft <= 0) {
|
||||||
@@ -12,13 +12,13 @@ export function DraftCountdownClock({ endTime, onFinish }) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
const t = getTimeLeft(endTime);
|
const t = getTimeLeft(bidding_timer_end);
|
||||||
setTimeLeft(t);
|
setTimeLeft(t);
|
||||||
if (t <= 0 && onFinish) onFinish();
|
if (t <= 0 && onFinish) onFinish();
|
||||||
}, 100);
|
}, 100);
|
||||||
return () => clearInterval(timer);
|
return () => clearInterval(timer);
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, [endTime, onFinish, timeLeft]);
|
}, [bidding_timer_end, onFinish, timeLeft]);
|
||||||
|
|
||||||
const minutes = Math.floor(timeLeft / 60);
|
const minutes = Math.floor(timeLeft / 60);
|
||||||
const secs = timeLeft % 60;
|
const secs = timeLeft % 60;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { isEmptyObject } from "./utils";
|
import { isEmptyObject } from "../utils";
|
||||||
|
|
||||||
export const DraftMoviePool = ({ isParticipant, draftDetails, draftState }) => {
|
export const DraftMoviePool = ({ isParticipant, draftDetails, draftState }) => {
|
||||||
if(isEmptyObject(draftDetails)) {return}
|
if(isEmptyObject(draftDetails)) {return}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { fetchDraftDetails, isEmptyObject } from "../common/utils.js"
|
import { fetchDraftDetails, isEmptyObject } from "../utils.js"
|
||||||
|
|
||||||
export const ParticipantList = ({ isAdmin, draftState, draftDetails, currentUser }) => {
|
export const ParticipantList = ({ isAdmin, draftState, draftDetails, currentUser }) => {
|
||||||
if (isEmptyObject(draftState) || isEmptyObject(draftDetails)) { console.warn('empty draft state', draftState); return }
|
if (isEmptyObject(draftState) || isEmptyObject(draftDetails)) { console.warn('empty draft state', draftState); return }
|
||||||
@@ -13,8 +13,8 @@ export const DraftMessage = {
|
|||||||
PHASE_CHANGE_INFORM: "phase.change.inform",
|
PHASE_CHANGE_INFORM: "phase.change.inform",
|
||||||
PHASE_CHANGE_REQUEST: "phase.change.request",
|
PHASE_CHANGE_REQUEST: "phase.change.request",
|
||||||
PHASE_CHANGE_CONFIRM: "phase.change.confirm",
|
PHASE_CHANGE_CONFIRM: "phase.change.confirm",
|
||||||
STATUS_SYNC_REQUEST: "status.sync.request",
|
DRAFT_STATUS_REQUEST: "draft.status.request",
|
||||||
STATUS_SYNC_INFORM: "status.sync.inform",
|
DRAFT_STATUS_INFORM: "draft.status.sync.inform",
|
||||||
DRAFT_INDEX_ADVANCE_REQUEST: "draft.index.advance.request",
|
DRAFT_INDEX_ADVANCE_REQUEST: "draft.index.advance.request",
|
||||||
DRAFT_INDEX_ADVANCE_CONFIRM: "draft.index.advance.confirm",
|
DRAFT_INDEX_ADVANCE_CONFIRM: "draft.index.advance.confirm",
|
||||||
ORDER_DETERMINE_REQUEST: "order.determine.request",
|
ORDER_DETERMINE_REQUEST: "order.determine.request",
|
||||||
@@ -22,6 +22,7 @@ export const DraftMessage = {
|
|||||||
BID_START_INFORM: "bid.start.inform",
|
BID_START_INFORM: "bid.start.inform",
|
||||||
BID_START_REQUEST: "bid.start.request",
|
BID_START_REQUEST: "bid.start.request",
|
||||||
BID_PLACE_REQUEST: "bid.place.request",
|
BID_PLACE_REQUEST: "bid.place.request",
|
||||||
|
BID_PLACE_CONFIRM: "bid.update.confirm",
|
||||||
BID_UPDATE_INFORM: "bid.update.inform",
|
BID_UPDATE_INFORM: "bid.update.inform",
|
||||||
BID_END_INFORM: "bid.end.inform",
|
BID_END_INFORM: "bid.end.inform",
|
||||||
NOMINATION_SUBMIT_REQUEST: "nomination.submit.request",
|
NOMINATION_SUBMIT_REQUEST: "nomination.submit.request",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { DraftMessage } from "../constants";
|
import { DraftMessage } from "./constants";
|
||||||
|
|
||||||
export async function fetchDraftDetails(draftSessionId) {
|
export async function fetchDraftDetails(draftSessionId) {
|
||||||
return fetch(`/api/draft/${draftSessionId}/`)
|
return fetch(`/api/draft/${draftSessionId}/`)
|
||||||
@@ -37,38 +37,12 @@ export function isEmptyObject(obj) {
|
|||||||
export const handleDraftStatusMessages = (event, setDraftState) => {
|
export const handleDraftStatusMessages = (event, setDraftState) => {
|
||||||
const message = JSON.parse(event.data);
|
const message = JSON.parse(event.data);
|
||||||
const { type, payload } = message;
|
const { type, payload } = message;
|
||||||
console.log("Message: ", type, event?.data);
|
|
||||||
|
|
||||||
if (!payload) return;
|
if (!payload) return;
|
||||||
const {
|
|
||||||
connected_participants,
|
|
||||||
phase,
|
|
||||||
draft_order,
|
|
||||||
draft_index,
|
|
||||||
current_movie,
|
|
||||||
bidding_timer_end,
|
|
||||||
bidding_timer_start,
|
|
||||||
current_pick,
|
|
||||||
next_picks,
|
|
||||||
bids
|
|
||||||
} = payload;
|
|
||||||
|
|
||||||
if (type == DraftMessage.STATUS_SYNC_INFORM) {
|
if (type == DraftMessage.DRAFT_STATUS_INFORM) {
|
||||||
setDraftState(payload);
|
setDraftState(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
setDraftState((prev) => ({
|
|
||||||
...prev,
|
|
||||||
...(connected_participants ? { connected_participants } : {}),
|
|
||||||
...(draft_order ? { draft_order } : {}),
|
|
||||||
...(draft_index ? { draft_index } : {}),
|
|
||||||
...(phase ? { phase: Number(phase) } : {}),
|
|
||||||
...(current_movie ? { current_movie } : {}),
|
|
||||||
...(bidding_timer_end ? { bidding_timer_end: Number(bidding_timer_end) } : {}),
|
|
||||||
...(current_pick ? { current_pick } : {}),
|
|
||||||
...(next_picks ? { next_picks } : {}),
|
|
||||||
...(bids ? {bids} : {})
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleUserIdentifyMessages = (event, setUser) => {
|
export const handleUserIdentifyMessages = (event, setUser) => {
|
||||||
@@ -2,13 +2,13 @@ import './scss/styles.scss'
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import { WebSocketProvider } from "./apps/draft/common/WebSocketContext.jsx";
|
import { WebSocketProvider } from "./apps/draft/components/WebSocketContext.jsx";
|
||||||
import { DraftAdmin } from "./apps/draft/admin/DraftAdmin.jsx";
|
import { DraftAdmin } from "./apps/draft/DraftAdminBar.jsx";
|
||||||
import { DraftParticipant} from './apps/draft/participant/DraftParticipant.jsx'
|
import { DraftParticipant} from './apps/draft/DraftDashboard.jsx'
|
||||||
import { DraftDebug} from './apps/draft/DraftDebug.jsx'
|
import { DraftDebug} from './apps/draft/DraftDebug.jsx'
|
||||||
|
|
||||||
|
|
||||||
const draftAdminRoot = document.getElementById("draft-admin-root");
|
const draftAdminBarRoot = document.getElementById("draft-admin-bar-root");
|
||||||
const draftPartipantRoot = document.getElementById("draft-participant-root")
|
const draftPartipantRoot = document.getElementById("draft-participant-root")
|
||||||
const draftDebugRoot = document.getElementById("draft-debug-root")
|
const draftDebugRoot = document.getElementById("draft-debug-root")
|
||||||
const {draftSessionId} = window; // from backend template
|
const {draftSessionId} = window; // from backend template
|
||||||
@@ -21,9 +21,9 @@ if (draftPartipantRoot) {
|
|||||||
</WebSocketProvider>
|
</WebSocketProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (draftAdminRoot) {
|
if (draftAdminBarRoot) {
|
||||||
const wsUrl = `ws://${window.location.host}/ws/draft/session/${draftSessionId}/admin`;
|
const wsUrl = `ws://${window.location.host}/ws/draft/session/${draftSessionId}/admin`;
|
||||||
createRoot(draftAdminRoot).render(
|
createRoot(draftAdminBarRoot).render(
|
||||||
<WebSocketProvider url={wsUrl}>
|
<WebSocketProvider url={wsUrl}>
|
||||||
<DraftAdmin draftSessionId={draftSessionId}/>
|
<DraftAdmin draftSessionId={draftSessionId}/>
|
||||||
</WebSocketProvider>
|
</WebSocketProvider>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
@use "../../node_modules/bootstrap/scss/bootstrap.scss";
|
@use "../../node_modules/bootstrap/scss/bootstrap.scss";
|
||||||
@use "./fonts/graphique.css";
|
@use "./fonts/graphique.css";
|
||||||
@import url("https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Oswald:wght@200..700&display=swap");
|
@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=League+Gothic&family=Oswald:wght@200..700&display=swap');
|
||||||
// Import only functions & variables
|
// Import only functions & variables
|
||||||
@import "~bootstrap/scss/functions";
|
@import "~bootstrap/scss/functions";
|
||||||
@import "~bootstrap/scss/variables";
|
@import "~bootstrap/scss/variables";
|
||||||
@@ -127,8 +127,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#draft-participant-root,
|
#draft-admin-bar {
|
||||||
#draft-admin-root {
|
@extend .d-flex;
|
||||||
|
@extend .flex-column;
|
||||||
|
@extend .border-top;
|
||||||
|
@extend .border-bottom;
|
||||||
|
@extend .gap-2;
|
||||||
|
@extend .p-2;
|
||||||
|
@extend .shadow-sm;
|
||||||
|
div {
|
||||||
|
@extend .d-flex;
|
||||||
|
@extend .justify-content-center
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#draft-participant-root {
|
||||||
@extend .flex-grow-1;
|
@extend .flex-grow-1;
|
||||||
.wrapper:first-child {
|
.wrapper:first-child {
|
||||||
@extend .p-2;
|
@extend .p-2;
|
||||||
@@ -137,44 +150,61 @@
|
|||||||
gap: 1rem; /* space between panels */
|
gap: 1rem; /* space between panels */
|
||||||
justify-content: center; /* center the panels horizontally */
|
justify-content: center; /* center the panels horizontally */
|
||||||
|
|
||||||
|
section {
|
||||||
|
max-width: 450px; /* never go beyond this */
|
||||||
|
min-width: 300px; /* keeps them from getting too small */
|
||||||
|
flex: 1 1 350px; /* grow/shrink, base width */
|
||||||
|
}
|
||||||
.panel {
|
.panel {
|
||||||
@extend .border;
|
@extend .border;
|
||||||
@extend .shadow-sm;
|
@extend .shadow-sm;
|
||||||
@extend .rounded-2;
|
@extend .rounded-2;
|
||||||
flex: 1 1 350px; /* grow/shrink, base width */
|
|
||||||
max-width: 450px; /* never go beyond this */
|
|
||||||
min-width: 300px; /* keeps them from getting too small */
|
|
||||||
header.panel-header {
|
header.panel-header {
|
||||||
@extend .p-1;
|
@extend .p-1;
|
||||||
@extend .text-uppercase;
|
@extend .text-uppercase;
|
||||||
@extend .align-items-center;
|
@extend .align-items-center;
|
||||||
@extend .border-bottom;
|
@extend .border-bottom;
|
||||||
@extend .border-secondary;
|
@extend .border-2;
|
||||||
background-color: $blue-100;
|
@extend .border-secondary-subtle;
|
||||||
|
// background-color: $blue-100;
|
||||||
|
@extend .bg-dark;
|
||||||
|
@extend .bg-gradient;
|
||||||
|
@extend .text-light;
|
||||||
@extend .rounded-top-2;
|
@extend .rounded-top-2;
|
||||||
.panel-title {
|
.panel-title {
|
||||||
|
@extend .ms-2;
|
||||||
@extend .fw-bold;
|
@extend .fw-bold;
|
||||||
@extend .fs-5;
|
@extend .fs-5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.panel.draft-live {
|
.bids-container {
|
||||||
|
overflow: scroll;
|
||||||
|
height: 85px;
|
||||||
|
}
|
||||||
|
#draft-live {
|
||||||
header.panel-header {
|
header.panel-header {
|
||||||
@extend .d-flex;
|
@extend .d-flex;
|
||||||
@extend .justify-content-between;
|
@extend .justify-content-between;
|
||||||
}
|
}
|
||||||
.draft-live-state-container {
|
#draft-clock {
|
||||||
@extend .d-flex;
|
@extend .row;
|
||||||
background-color: $green-100;
|
@extend .g-0;
|
||||||
|
// background-color: $green-100;
|
||||||
|
@extend .text-light;
|
||||||
|
@extend .text-bg-dark;
|
||||||
|
@extend .lh-1;
|
||||||
.countdown-clock {
|
.countdown-clock {
|
||||||
@extend .fs-1;
|
font-family: 'League Gothic';
|
||||||
@extend .fw-bold;
|
font-size: $font-size-base * 5;
|
||||||
|
@extend .fw-bolder;
|
||||||
@extend .col;
|
@extend .col;
|
||||||
@extend .align-content-center;
|
@extend .align-content-center;
|
||||||
@extend .text-center;
|
@extend .text-center;
|
||||||
}
|
}
|
||||||
.pick-description {
|
.pick-description {
|
||||||
@extend .col;
|
@extend .col;
|
||||||
|
@extend .align-content-center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
div:has(.pick-list), div:has(.bid-list){
|
div:has(.pick-list), div:has(.bid-list){
|
||||||
|
|||||||
0
scripts/generate_js_constants.py
Normal file → Executable file
0
scripts/generate_js_constants.py
Normal file → Executable file
Reference in New Issue
Block a user