More events team nonsense
This commit is contained in:
@@ -37,14 +37,40 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
year--;
|
||||
}
|
||||
|
||||
const data = await context.env.D1.prepare(
|
||||
"SELECT day, details, id FROM events WHERE approved = 1 AND month = ? AND year = ? AND (performed_at IS NULL OR (reached_minimum_player_count = 0 AND type = 'gamenight')) ORDER BY day;",
|
||||
)
|
||||
.bind(month, year)
|
||||
.all();
|
||||
const data = await context.data.prisma.event.findMany({
|
||||
orderBy: {
|
||||
day: "asc",
|
||||
},
|
||||
select: {
|
||||
answered_at: true,
|
||||
day: true,
|
||||
details: true,
|
||||
id: true,
|
||||
performed_at: true,
|
||||
reached_minimum_player_count: true,
|
||||
type: true,
|
||||
},
|
||||
where: {
|
||||
AND: {
|
||||
approved: true,
|
||||
month,
|
||||
year,
|
||||
OR: [
|
||||
{
|
||||
AND: [
|
||||
{
|
||||
reached_minimum_player_count: false,
|
||||
type: "gamenight",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
events: data.results as Record<string, string | number>[],
|
||||
events: data,
|
||||
past_cutoff: now.getUTCDate() > 7,
|
||||
};
|
||||
}
|
||||
@@ -52,7 +78,7 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
export default function () {
|
||||
const { events, past_cutoff } = useLoaderData<typeof loader>();
|
||||
const { isOpen, onClose, onOpen } = useDisclosure();
|
||||
const [eventData, setEventData] = useState({} as { [k: string]: any });
|
||||
const [eventData, setEventData] = useState({} as (typeof events)[number]);
|
||||
const [isBrowserSupported, setIsBrowserSupported] = useState(true);
|
||||
const toast = useToast();
|
||||
|
||||
@@ -74,10 +100,10 @@ export default function () {
|
||||
});
|
||||
}
|
||||
|
||||
function getStatus(event: { [k: string]: string | number }) {
|
||||
function getStatus(event: (typeof events)[number]) {
|
||||
if (!event.performed_at) return "Approved";
|
||||
if (event.type === "rotw" && event.answered_at) return "Solved";
|
||||
if (event.type === "gamenight" && event.areached_minimum_player_count)
|
||||
if (event.type === "gamenight" && event.reached_minimum_player_count)
|
||||
return "Certified";
|
||||
|
||||
return "Completed";
|
||||
@@ -106,7 +132,7 @@ export default function () {
|
||||
});
|
||||
|
||||
const newData = structuredClone(eventData);
|
||||
newData.reached_minimum_player_count = 1;
|
||||
newData.reached_minimum_player_count = true;
|
||||
|
||||
setEventData(newData);
|
||||
}
|
||||
@@ -134,9 +160,12 @@ export default function () {
|
||||
});
|
||||
|
||||
const newData = structuredClone(eventData);
|
||||
newData.performed_at = Date.now();
|
||||
|
||||
setEventData(newData);
|
||||
setEventData(
|
||||
Object.defineProperty(newData, "performed_at", {
|
||||
value: new Date().toISOString(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function forgotten() {
|
||||
@@ -162,9 +191,12 @@ export default function () {
|
||||
});
|
||||
|
||||
const newData = structuredClone(eventData);
|
||||
newData.performed_at = 0;
|
||||
|
||||
setEventData(newData);
|
||||
setEventData(
|
||||
Object.defineProperty(newData, "performed_at", {
|
||||
value: new Date().toISOString(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function solve() {
|
||||
@@ -190,9 +222,12 @@ export default function () {
|
||||
});
|
||||
|
||||
const newData = structuredClone(eventData);
|
||||
newData.answered_at = Date.now();
|
||||
|
||||
setEventData(newData);
|
||||
setEventData(
|
||||
Object.defineProperty(newData, "performed_at", {
|
||||
value: new Date().toISOString(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -216,13 +251,13 @@ export default function () {
|
||||
<Box gap="8px">
|
||||
<Heading size="xs">Completion</Heading>
|
||||
<Button
|
||||
disabled={typeof eventData.completed_at === "number"}
|
||||
disabled={Boolean(eventData.performed_at)}
|
||||
onClick={async () => await completed()}
|
||||
>
|
||||
Mark as Complete
|
||||
</Button>
|
||||
<Button
|
||||
disabled={typeof eventData.completed_at === "number"}
|
||||
disabled={typeof eventData.performed_at === "number"}
|
||||
onClick={async () => await forgotten()}
|
||||
>
|
||||
Mark as Forgotten
|
||||
@@ -243,7 +278,7 @@ export default function () {
|
||||
<Box gap="8px">
|
||||
<Heading size="xs">Certified Status</Heading>
|
||||
<Button
|
||||
disabled={Boolean(eventData.reached_minimum_player_count)}
|
||||
disabled={eventData.reached_minimum_player_count}
|
||||
onClick={async () => await certify()}
|
||||
>
|
||||
{eventData.reached_minimum_player_count
|
||||
@@ -277,8 +312,8 @@ export default function () {
|
||||
<Tr>
|
||||
<Td>{event.day}</Td>
|
||||
<Td>
|
||||
{(event.details as string).length > 100
|
||||
? `${(event.details as string).substring(0, 97)}...`
|
||||
{event.details.length > 100
|
||||
? `${event.details.substring(0, 97)}...`
|
||||
: event.details}
|
||||
</Td>
|
||||
<Td>{getStatus(event)}</Td>
|
||||
|
||||
Reference in New Issue
Block a user