From 8f5cd6ed4fbe2d1ff9166b9d92ea8d6b16d74f7c Mon Sep 17 00:00:00 2001 From: Logan Davidson Date: Sun, 1 Oct 2023 16:14:58 +0100 Subject: [PATCH] Add a notification for new turn starting --- backend/rorapp/functions/face_mortality.py | 17 +++++++++++ frontend/components/MetaSection.tsx | 4 +-- .../actionLogs/ActionLog.module.css | 5 ++++ frontend/components/actionLogs/ActionLog.tsx | 4 ++- .../actionLogs/ActionLog_NewTurn.tsx | 30 +++++++++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 frontend/components/actionLogs/ActionLog_NewTurn.tsx diff --git a/backend/rorapp/functions/face_mortality.py b/backend/rorapp/functions/face_mortality.py index 450d79d4..add373c8 100644 --- a/backend/rorapp/functions/face_mortality.py +++ b/backend/rorapp/functions/face_mortality.py @@ -215,6 +215,23 @@ def face_mortality(game, faction, potential_action, step): } }) + # Issue a notification to say that the next turn has started + new_action_log_index = ActionLog.objects.filter(step__phase__turn__game=game).order_by('-index')[0].index + 1 + action_log = ActionLog( + index=new_action_log_index, + step=step, + type="new_turn", + data={"turn_index": new_turn.index} + ) + action_log.save() + messages_to_send.append({ + "operation": "create", + "instance": { + "class": "action_log", + "data": ActionLogSerializer(action_log).data + } + }) + # Create potential actions for the next mortality phase factions = Faction.objects.filter(game__id=game.id) for faction in factions: diff --git a/frontend/components/MetaSection.tsx b/frontend/components/MetaSection.tsx index 3e97c6b0..6d800b84 100644 --- a/frontend/components/MetaSection.tsx +++ b/frontend/components/MetaSection.tsx @@ -4,7 +4,7 @@ import Link from 'next/link' import Button from '@mui/material/Button' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faRightFromBracket } from '@fortawesome/free-solid-svg-icons' -import { faClock } from '@fortawesome/free-regular-svg-icons' +import { faHourglass } from '@fortawesome/free-regular-svg-icons' import Turn from "@/classes/Turn" import Phase from "@/classes/Phase" @@ -42,7 +42,7 @@ const MetaSection = (props: MetaSectionProps) => {

{game.name}

- + Turn {props.latestTurn.index}, {props.latestPhase.name} Phase
diff --git a/frontend/components/actionLogs/ActionLog.module.css b/frontend/components/actionLogs/ActionLog.module.css index db2bcbc6..b794eec2 100644 --- a/frontend/components/actionLogs/ActionLog.module.css +++ b/frontend/components/actionLogs/ActionLog.module.css @@ -4,3 +4,8 @@ display: flex; justify-content: center; } + +.faIcon { + margin-top: 2px; + color: var(--foreground-color); +} diff --git a/frontend/components/actionLogs/ActionLog.tsx b/frontend/components/actionLogs/ActionLog.tsx index 4a22964f..e7e7c9b8 100644 --- a/frontend/components/actionLogs/ActionLog.tsx +++ b/frontend/components/actionLogs/ActionLog.tsx @@ -2,6 +2,7 @@ import ActionLog from "@/classes/ActionLog" import SelectFactionLeaderNotification from "./ActionLog_SelectFactionLeader" import FaceMortalityNotification from "./ActionLog_FaceMortality" import TemporaryRomeConsulNotification from "./ActionLog_TemporaryRomeConsul" +import NewTurnNotification from "./ActionLog_NewTurn" interface NotificationItemProps { notification: ActionLog @@ -11,7 +12,8 @@ interface NotificationItemProps { const notifications: { [key: string]: React.ComponentType } = { select_faction_leader: SelectFactionLeaderNotification, face_mortality: FaceMortalityNotification, - temporary_rome_consul: TemporaryRomeConsulNotification + temporary_rome_consul: TemporaryRomeConsulNotification, + new_turn: NewTurnNotification } // Container for a notification, which determines the type of notification to render diff --git a/frontend/components/actionLogs/ActionLog_NewTurn.tsx b/frontend/components/actionLogs/ActionLog_NewTurn.tsx new file mode 100644 index 00000000..56d12665 --- /dev/null +++ b/frontend/components/actionLogs/ActionLog_NewTurn.tsx @@ -0,0 +1,30 @@ +import { Alert } from "@mui/material" +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { faHourglass } from '@fortawesome/free-regular-svg-icons' +import ActionLog from "@/classes/ActionLog" +import styles from "./ActionLog.module.css" + +interface NotificationProps { + notification: ActionLog +} + +// Notification for when a senator dies during the mortality phase +const NewTurnNotification = ({ notification } : NotificationProps) => { + // Get notification-specific data + const turnIndex = notification.data?.turn_index ?? null + + const getIcon = () => ( +
+ +
+ ) + + return ( + + New Turn +

Turn {turnIndex} has started.

+
+ ) +} + +export default NewTurnNotification