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:
@@ -65,10 +65,11 @@ class DraftCache:
|
||||
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
|
||||
|
||||
class DraftStateManager:
|
||||
_initial_phase: DraftPhase = DraftPhase.WAITING.value
|
||||
|
||||
def __init__(self, session: DraftSession):
|
||||
self.session_id: str = session.hashid
|
||||
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.participants: set[User] = set(session.participants.all())
|
||||
self.connected_participants: set[User] = set()
|
||||
@@ -76,7 +77,7 @@ class DraftStateManager:
|
||||
# === Phase Management ===
|
||||
@property
|
||||
def phase(self) -> str:
|
||||
return self.cache.phase
|
||||
return self.cache.phase or self._initial_phase
|
||||
|
||||
@phase.setter
|
||||
def phase(self, new_phase: DraftPhase) -> None:
|
||||
@@ -106,7 +107,7 @@ class DraftStateManager:
|
||||
self.phase = DraftPhase.DETERMINE_ORDER
|
||||
self.draft_index = 0
|
||||
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]
|
||||
return self.draft_order
|
||||
|
||||
Reference in New Issue
Block a user