make website run

This commit is contained in:
2025-12-17 14:40:46 +01:00
parent daa4bb6576
commit a213a5cf9f
54 changed files with 196 additions and 352 deletions

View File

@@ -3,7 +3,6 @@
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useEffectiveDriverId } from '@/lib/currentDriver';
import { getSendNotificationUseCase, getRaceRepository, getLeagueRepository } from '@/lib/di-container';
import type { NotificationUrgency } from '@core/notifications/application';
import {
Bell,
@@ -182,135 +181,135 @@ export default function DevToolbar() {
return null;
}
const handleSendNotification = async () => {
setSending(true);
try {
const sendNotification = getSendNotificationUseCase();
// const handleSendNotification = async () => {
// setSending(true);
// try {
// const sendNotification = getSendNotificationUseCase();
const raceRepository = getRaceRepository();
const leagueRepository = getLeagueRepository();
// const raceRepository = getRaceRepository();
// const leagueRepository = getLeagueRepository();
const [allRaces, allLeagues] = await Promise.all([
raceRepository.findAll(),
leagueRepository.findAll(),
]);
// const [allRaces, allLeagues] = await Promise.all([
// raceRepository.findAll(),
// leagueRepository.findAll(),
// ]);
const completedRaces = allRaces.filter((race) => race.status === 'completed');
const scheduledRaces = allRaces.filter((race) => race.status === 'scheduled');
// const completedRaces = allRaces.filter((race) => race.status === 'completed');
// const scheduledRaces = allRaces.filter((race) => race.status === 'scheduled');
const primaryRace = completedRaces[0] ?? allRaces[0];
const secondaryRace = scheduledRaces[0] ?? allRaces[1] ?? primaryRace;
const primaryLeague = allLeagues[0];
// const primaryRace = completedRaces[0] ?? allRaces[0];
// const secondaryRace = scheduledRaces[0] ?? allRaces[1] ?? primaryRace;
// const primaryLeague = allLeagues[0];
const notificationDeadline =
selectedUrgency === 'modal'
? new Date(Date.now() + 48 * 60 * 60 * 1000)
: undefined;
// const notificationDeadline =
// selectedUrgency === 'modal'
// ? new Date(Date.now() + 48 * 60 * 60 * 1000)
// : undefined;
let title: string;
let body: string;
let notificationType: 'protest_filed' | 'protest_defense_requested' | 'protest_vote_required' | 'race_performance_summary' | 'race_final_results';
let actionUrl: string;
// let title: string;
// let body: string;
// let notificationType: 'protest_filed' | 'protest_defense_requested' | 'protest_vote_required' | 'race_performance_summary' | 'race_final_results';
// let actionUrl: string;
switch (selectedType) {
case 'protest_filed': {
const raceId = primaryRace?.id;
title = '🚨 Protest Filed Against You';
body =
'A protest has been filed against you for unsafe rejoining during a recent race. Please review the incident details.';
notificationType = 'protest_filed';
actionUrl = raceId ? `/races/${raceId}/stewarding` : '/races';
break;
}
case 'defense_requested': {
const raceId = secondaryRace?.id ?? primaryRace?.id;
title = '⚖️ Defense Requested';
body =
'A steward has requested your defense regarding a recent incident. Please provide your side of the story within 48 hours.';
notificationType = 'protest_defense_requested';
actionUrl = raceId ? `/races/${raceId}/stewarding` : '/races';
break;
}
case 'vote_required': {
const leagueId = primaryLeague?.id;
title = '🗳️ Your Vote Required';
body =
'As a league steward, you are required to vote on an open protest. Please review the case and cast your vote.';
notificationType = 'protest_vote_required';
actionUrl = leagueId ? `/leagues/${leagueId}/stewarding` : '/leagues';
break;
}
case 'race_performance_summary': {
const raceId = primaryRace?.id;
const leagueId = primaryLeague?.id;
title = '🏁 Race Complete: Performance Summary';
body =
'Your Monza Grand Prix race is finished! You finished P1 with 0 incidents. Provisional rating: +25 points. View full results and standings.';
notificationType = 'race_performance_summary';
actionUrl = raceId ? `/races/${raceId}` : '/races';
break;
}
case 'race_final_results': {
const leagueId = primaryLeague?.id;
title = '🏆 Final Results: Monza Grand Prix';
body =
'Stewarding is now closed. Your final result: P1 (+25 rating). No penalties were applied. View championship standings.';
notificationType = 'race_final_results';
actionUrl = leagueId ? `/leagues/${leagueId}/standings` : '/leagues';
break;
}
}
// switch (selectedType) {
// case 'protest_filed': {
// const raceId = primaryRace?.id;
// title = '🚨 Protest Filed Against You';
// body =
// 'A protest has been filed against you for unsafe rejoining during a recent race. Please review the incident details.';
// notificationType = 'protest_filed';
// actionUrl = raceId ? `/races/${raceId}/stewarding` : '/races';
// break;
// }
// case 'defense_requested': {
// const raceId = secondaryRace?.id ?? primaryRace?.id;
// title = '⚖️ Defense Requested';
// body =
// 'A steward has requested your defense regarding a recent incident. Please provide your side of the story within 48 hours.';
// notificationType = 'protest_defense_requested';
// actionUrl = raceId ? `/races/${raceId}/stewarding` : '/races';
// break;
// }
// case 'vote_required': {
// const leagueId = primaryLeague?.id;
// title = '🗳️ Your Vote Required';
// body =
// 'As a league steward, you are required to vote on an open protest. Please review the case and cast your vote.';
// notificationType = 'protest_vote_required';
// actionUrl = leagueId ? `/leagues/${leagueId}/stewarding` : '/leagues';
// break;
// }
// case 'race_performance_summary': {
// const raceId = primaryRace?.id;
// const leagueId = primaryLeague?.id;
// title = '🏁 Race Complete: Performance Summary';
// body =
// 'Your Monza Grand Prix race is finished! You finished P1 with 0 incidents. Provisional rating: +25 points. View full results and standings.';
// notificationType = 'race_performance_summary';
// actionUrl = raceId ? `/races/${raceId}` : '/races';
// break;
// }
// case 'race_final_results': {
// const leagueId = primaryLeague?.id;
// title = '🏆 Final Results: Monza Grand Prix';
// body =
// 'Stewarding is now closed. Your final result: P1 (+25 rating). No penalties were applied. View championship standings.';
// notificationType = 'race_final_results';
// actionUrl = leagueId ? `/leagues/${leagueId}/standings` : '/leagues';
// break;
// }
// }
const actions =
selectedUrgency === 'modal'
? selectedType.startsWith('race_')
? [
{ label: selectedType === 'race_performance_summary' ? '🏁 View Race Results' : '🏆 View Standings', type: 'primary' as const, href: actionUrl, actionId: 'view' },
{ label: '🎉 Share Achievement', type: 'secondary' as const, actionId: 'share' },
]
: [
{ label: 'View Protest', type: 'primary' as const, href: actionUrl, actionId: 'view' },
{ label: 'Dismiss', type: 'secondary' as const, actionId: 'dismiss' },
]
: [];
// const actions =
// selectedUrgency === 'modal'
// ? selectedType.startsWith('race_')
// ? [
// { label: selectedType === 'race_performance_summary' ? '🏁 View Race Results' : '🏆 View Standings', type: 'primary' as const, href: actionUrl, actionId: 'view' },
// { label: '🎉 Share Achievement', type: 'secondary' as const, actionId: 'share' },
// ]
// : [
// { label: 'View Protest', type: 'primary' as const, href: actionUrl, actionId: 'view' },
// { label: 'Dismiss', type: 'secondary' as const, actionId: 'dismiss' },
// ]
// : [];
await sendNotification.execute({
recipientId: currentDriverId,
type: notificationType,
title,
body,
actionUrl,
urgency: selectedUrgency as NotificationUrgency,
requiresResponse: selectedUrgency === 'modal' && !selectedType.startsWith('race_'),
actions,
data: {
...(selectedType.startsWith('protest_') ? {
protestId: `demo-protest-${Date.now()}`,
} : {}),
...(selectedType.startsWith('race_') ? {
raceEventId: `demo-race-event-${Date.now()}`,
sessionId: `demo-session-${Date.now()}`,
position: 1,
positionChange: 0,
incidents: 0,
provisionalRatingChange: 25,
finalRatingChange: 25,
hadPenaltiesApplied: false,
} : {}),
raceId: primaryRace?.id ?? '',
leagueId: primaryLeague?.id ?? '',
...(notificationDeadline && selectedType.startsWith('protest_') ? { deadline: notificationDeadline } : {}),
},
});
// await sendNotification.execute({
// recipientId: currentDriverId,
// type: notificationType,
// title,
// body,
// actionUrl,
// urgency: selectedUrgency as NotificationUrgency,
// requiresResponse: selectedUrgency === 'modal' && !selectedType.startsWith('race_'),
// actions,
// data: {
// ...(selectedType.startsWith('protest_') ? {
// protestId: `demo-protest-${Date.now()}`,
// } : {}),
// ...(selectedType.startsWith('race_') ? {
// raceEventId: `demo-race-event-${Date.now()}`,
// sessionId: `demo-session-${Date.now()}`,
// position: 1,
// positionChange: 0,
// incidents: 0,
// provisionalRatingChange: 25,
// finalRatingChange: 25,
// hadPenaltiesApplied: false,
// } : {}),
// raceId: primaryRace?.id ?? '',
// leagueId: primaryLeague?.id ?? '',
// ...(notificationDeadline && selectedType.startsWith('protest_') ? { deadline: notificationDeadline } : {}),
// },
// });
setLastSent(`${selectedType}-${selectedUrgency}`);
setTimeout(() => setLastSent(null), 3000);
} catch (error) {
console.error('Failed to send demo notification:', error);
} finally {
setSending(false);
}
};
// setLastSent(`${selectedType}-${selectedUrgency}`);
// setTimeout(() => setLastSent(null), 3000);
// } catch (error) {
// console.error('Failed to send demo notification:', error);
// } finally {
// setSending(false);
// }
// };
if (isMinimized) {
return (