Skip to content

Commit

Permalink
Made changes to broadcasts per ATM feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
beabravedude committed Feb 12, 2025
1 parent 2bc2896 commit f11b9b8
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 15 deletions.
10 changes: 10 additions & 0 deletions actions/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ export const deleteBroadcast = async (id: string) => {
after(async () => {
await log('DELETE', 'BROADCAST', `Deleted broadcast ${broadcast.title}`);
});
}

export const deleteStaleBroadcasts = async () => {
await prisma.changeBroadcast.deleteMany({
where: {
timestamp: {
lt: new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 30 * 6), // 6 months
},
},
});
}
10 changes: 1 addition & 9 deletions actions/broadcastViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const handleSeenBroadcast = async (user: User, broadcastId: string) => {
}

export const handleAgreeBroadcast = async (user: User, broadcastId: string) => {
const broadcast = await prisma.changeBroadcast.update({
await prisma.changeBroadcast.update({
where: {
id: broadcastId,
},
Expand All @@ -50,12 +50,4 @@ export const handleAgreeBroadcast = async (user: User, broadcastId: string) => {
seenBy: true,
},
});

if (broadcast.seenBy.length + broadcast.unseenBy.length === 0) {
await prisma.changeBroadcast.delete({
where: {
id: broadcastId,
},
});
}
}
4 changes: 4 additions & 0 deletions app/admin/broadcasts/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default async function Page() {
});

const groups: MailGroup[] = [
{
name: 'All Rostered Controllers',
ids: users.map(user => user.id),
},
{
name: 'Home Observers',
ids: users.filter(user => user.rating === 1 && user.controllerStatus === "HOME").map(user => user.id),
Expand Down
6 changes: 5 additions & 1 deletion app/admin/broadcasts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import {Box, Button, Card, CardContent, Stack, Typography} from "@mui/material";
import Link from "next/link";
import {Add} from "@mui/icons-material";
import BroadcastTable from "@/components/Broadcast/BroadcastTable";
import {deleteStaleBroadcasts} from "@/actions/broadcast";

export default async function Page() {

await deleteStaleBroadcasts();

return (
<Card>
<CardContent>
<Stack direction="row" spacing={2} justifyContent="space-between" sx={{mb: 2,}}>
<Box>
<Typography variant="h5">Active Broadcasts</Typography>
<Typography>Broadcasts are automatically deleted if everybody agrees.</Typography>
<Typography>Broadcasts are automatically deleted 6 months after they were last
updated.</Typography>
</Box>

<Link href="/admin/broadcasts/new">
Expand Down
51 changes: 51 additions & 0 deletions components/Broadcast/BroadcastAgreedViewerButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use client';
import React, {useState} from 'react';
import {ChangeBroadcast, User} from "@prisma/client";
import {Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Tooltip} from "@mui/material";
import {GridActionsCellItem} from "@mui/x-data-grid";
import {Check} from "@mui/icons-material";
import {getRating} from "@/lib/vatsim";
import Link from "next/link";

export default function BroadcastAgreedViewerButton({broadcast, agreedBy}: {
broadcast: ChangeBroadcast,
agreedBy: User[],
}) {

const [open, setOpen] = useState(false);

return (
<>
<Tooltip title="View Controllers Reviewed">
<GridActionsCellItem
icon={<Check/>}
label="View Controllers Reviewed"
onClick={() => setOpen(true)}
/>
</Tooltip>
<Dialog open={open} onClose={() => setOpen(false)}>
<DialogTitle>Agreed - {broadcast.title}</DialogTitle>
<DialogContent>
<DialogContentText>Click on a controller to view profile in a new tab.</DialogContentText>
<DialogContentText gutterBottom>The following controllers have reviewed this
broadcast:</DialogContentText>
<ul>
{agreedBy
.sort((a, b) => (a.lastName || '').localeCompare(b.lastName || ''))
.map((user) => (
<li key={user.id}>
<Link href={`/admin/controller/${user.cid}`} style={{textDecoration: 'none',}}
target="_blank">
<DialogContentText>{user.firstName} {user.lastName} - {getRating(user.rating)}</DialogContentText>
</Link>
</li>
))}
</ul>
</DialogContent>
<DialogActions>
<Button onClick={() => setOpen(false)} color="inherit">Close</Button>
</DialogActions>
</Dialog>
</>
);
}
6 changes: 3 additions & 3 deletions components/Broadcast/BroadcastNotAgreedViewerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ export default function BroadcastNotAgreedViewerButton({broadcast, notAgreedBy}:

return (
<>
<Tooltip title="View Controllers NOT Agreed">
<Tooltip title="View Controllers NOT Reviewed">
<GridActionsCellItem
icon={<Gavel/>}
label="View Controllers NOT Agreed"
label="View Controllers NOT Reviewed"
onClick={() => setOpen(true)}
/>
</Tooltip>
<Dialog open={open} onClose={() => setOpen(false)}>
<DialogTitle>Not Agreed - {broadcast.title}</DialogTitle>
<DialogContent>
<DialogContentText>Click on a controller to view profile in a new tab.</DialogContentText>
<DialogContentText gutterBottom>The following controllers have not agreed to this
<DialogContentText gutterBottom>The following controllers have not reviewed this
broadcast:</DialogContentText>
<ul>
{notAgreedBy
Expand Down
5 changes: 4 additions & 1 deletion components/Broadcast/BroadcastTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BroadcastDeleteButton from "@/components/Broadcast/BroadcastDeleteButton"
import {fetchBroadcasts} from "@/actions/broadcast";
import BroadcastNotAgreedViewerButton from "@/components/Broadcast/BroadcastNotAgreedViewerButton";
import {formatZuluDate} from "@/lib/date";
import BroadcastAgreedViewerButton from "@/components/Broadcast/BroadcastAgreedViewerButton";

export default function BroadcastTable() {

Expand Down Expand Up @@ -46,7 +47,7 @@ export default function BroadcastTable() {
{
field: 'agreed',
type: 'number',
headerName: 'Agreed',
headerName: 'Reviewed',
flex: 1,
renderCell: (params) => `${params.row.agreedBy.length}/${params.row.seenBy.length + params.row.unseenBy.length + params.row.agreedBy.length}`,
},
Expand All @@ -56,6 +57,8 @@ export default function BroadcastTable() {
headerName: 'Actions',
flex: 1,
getActions: (params) => [
<BroadcastAgreedViewerButton agreedBy={params.row.agreedBy}
key={`agreed-${params.row.id}`} broadcast={params.row}/>,
<BroadcastNotAgreedViewerButton notAgreedBy={[...params.row.unseenBy, ...params.row.seenBy]}
key={`notagreed-${params.row.id}`} broadcast={params.row}/>,
<Tooltip title="Edit Broadcast" key={`edit-${params.row.id}`}>
Expand Down
3 changes: 2 additions & 1 deletion components/BroadcastViewer/BroadcastDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Button, Dialog, DialogActions, DialogContent, DialogTitle} from "@mui/ma
import {ChangeBroadcast} from "@prisma/client";
import {handleAgreeBroadcast, handleSeenBroadcast} from "@/actions/broadcastViewer";
import {User} from "next-auth";
import {Check} from "@mui/icons-material";

export default function BroadcastDialog({user, broadcasts, children}: {
user: User,
Expand Down Expand Up @@ -31,7 +32,7 @@ export default function BroadcastDialog({user, broadcasts, children}: {
</DialogContent>
<DialogActions>
<Button onClick={handleClose} color="inherit">Save for Later</Button>
<Button onClick={handleAgree} variant="contained">Agree</Button>
<Button onClick={handleAgree} variant="contained" startIcon={<Check/>}>Reviewed</Button>
</DialogActions>
</Dialog>
);
Expand Down

0 comments on commit f11b9b8

Please sign in to comment.