mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix game state on refresh.
There was accidentally a second layer of callback here. I'm not sure why it worked. I think the lambda being returned was being used as the cleanup function?
This commit is contained in:
parent
625f36c780
commit
6d29bfdf65
@ -2,7 +2,7 @@ import "./App.css";
|
||||
|
||||
import { LatLng } from "leaflet";
|
||||
import LiberationMap from "./components/liberationmap";
|
||||
import { useInitialGameState } from "./api/useInitialGameState";
|
||||
import useInitialGameState from "./api/useInitialGameState";
|
||||
|
||||
function App() {
|
||||
const mapCenter: LatLng = new LatLng(25.58, 54.9);
|
||||
|
||||
@ -10,30 +10,28 @@ import { useEffect } from "react";
|
||||
// are smart enough to only initialize once which get called in the components
|
||||
// that use them rather than forcibly loading the whole game in the root
|
||||
// component.
|
||||
export function useInitialGameState() {
|
||||
export const useInitialGameState = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
backend
|
||||
.get("/control-points")
|
||||
.catch((error) =>
|
||||
console.log(`Error fetching control points: ${error}`)
|
||||
)
|
||||
.then((response) => {
|
||||
if (response != null) {
|
||||
dispatch(setControlPoints(response.data as ControlPoint[]));
|
||||
backend
|
||||
.get("/control-points")
|
||||
.catch((error) => console.log(`Error fetching control points: ${error}`))
|
||||
.then((response) => {
|
||||
if (response != null) {
|
||||
dispatch(setControlPoints(response.data as ControlPoint[]));
|
||||
}
|
||||
});
|
||||
backend
|
||||
.get("/flights?with_waypoints=true")
|
||||
.catch((error) => console.log(`Error fetching flights: ${error}`))
|
||||
.then((response) => {
|
||||
if (response != null) {
|
||||
for (const flight of response.data) {
|
||||
dispatch(registerFlight(flight as Flight));
|
||||
}
|
||||
});
|
||||
backend
|
||||
.get("/flights?with_waypoints=true")
|
||||
.catch((error) => console.log(`Error fetching flights: ${error}`))
|
||||
.then((response) => {
|
||||
if (response != null) {
|
||||
for (const flight of response.data) {
|
||||
dispatch(registerFlight(flight as Flight));
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default useInitialGameState;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user