Continue messing with stores

This commit is contained in:
ThePetrovich 2025-06-27 19:27:19 +08:00
parent c7df38e6ce
commit 52558ed3b2
7 changed files with 148 additions and 83 deletions

View file

@ -3,8 +3,8 @@ import type { LatLngExpression } from "leaflet";
import L from "leaflet";
import { getCsrfToken } from "./auth";
import type { PredictionStage, Prediction, ParsedPrediction } from "./types";
import { latestPrediction, latestPredictionParsed } from "./stores";
import type { PredictionStage, RawPrediction, Prediction } from "./types";
import { PredictionStore, RawPredictionStore, writeLocalStorage } from "./stores";
function getLatestDataset() {
const now = new Date();
@ -76,8 +76,10 @@ export const getForecast = async (
const data = await response.json();
console.log("Forecast response:", data);
latestPrediction.set(data.result);
latestPredictionParsed.set(parsePrediction(data.result.prediction));
RawPredictionStore.set(data.result as RawPrediction);
PredictionStore.set(parsePrediction(data.result.prediction) as Prediction);
writeLocalStorage("rawPrediction", data.result as RawPrediction);
writeLocalStorage("prediction", parsePrediction(data.result.prediction) as Prediction);
alert("Forecast request successful!");
// Handle the response data as needed
@ -87,7 +89,7 @@ export const getForecast = async (
}
};
export function parsePrediction(prediction: PredictionStage[]): ParsedPrediction {
export function parsePrediction(prediction: PredictionStage[]): Prediction {
const flight_path: [number, number, number][] = [];
const launch: { latlng: LatLngExpression; datetime: Date } = {} as any;
const burst: { latlng: LatLngExpression; datetime: Date } = {} as any;