refactor page to use services
This commit is contained in:
@@ -5,7 +5,7 @@ import Card from '@/components/ui/Card';
|
||||
import { useEffectiveDriverId } from '@/hooks/useEffectiveDriverId';
|
||||
import type { DriverDto, LeagueMembership } from '@/lib/dtos';
|
||||
import { isLeagueAdminOrHigherRole } from '@/lib/leagueRoles';
|
||||
import { getLeagueStandings } from '@/lib/services/leagues/LeagueService';
|
||||
import { useServices } from '@/lib/services/ServiceProvider';
|
||||
import type { LeagueStandingsViewModel } from '@/lib/view-models';
|
||||
import type { StandingEntryViewModel } from '@/lib/view-models/StandingEntryViewModel';
|
||||
import { useParams } from 'next/navigation';
|
||||
@@ -15,6 +15,7 @@ export default function LeagueStandingsPage() {
|
||||
const params = useParams();
|
||||
const leagueId = params.id as string;
|
||||
const currentDriverId = useEffectiveDriverId();
|
||||
const { leagueService } = useServices();
|
||||
|
||||
const [standings, setStandings] = useState<StandingEntryViewModel[]>([]);
|
||||
const [drivers, setDrivers] = useState<DriverDto[]>([]);
|
||||
@@ -26,7 +27,7 @@ export default function LeagueStandingsPage() {
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
try {
|
||||
const vm = await getLeagueStandings(leagueId, currentDriverId);
|
||||
const vm = await leagueService.getLeagueStandings(leagueId, currentDriverId);
|
||||
setViewModel(vm);
|
||||
setStandings(vm.standings);
|
||||
setDrivers(vm.drivers);
|
||||
@@ -40,7 +41,7 @@ export default function LeagueStandingsPage() {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [leagueId, currentDriverId]);
|
||||
}, [leagueId, currentDriverId, leagueService]);
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
|
||||
Reference in New Issue
Block a user