From ca72b37295a0d421f775248ce84639cca42b59c7 Mon Sep 17 00:00:00 2001 From: "Damon L. Montague Jr." Date: Sun, 28 Apr 2024 03:26:39 -0400 Subject: [PATCH] added better formatting --- ui/src/components/display-card.tsx | 1 - ui/src/pages/History.tsx | 69 +++++++++++++----------------- 2 files changed, 29 insertions(+), 41 deletions(-) diff --git a/ui/src/components/display-card.tsx b/ui/src/components/display-card.tsx index 73e5592..68c569b 100644 --- a/ui/src/components/display-card.tsx +++ b/ui/src/components/display-card.tsx @@ -1,6 +1,5 @@ import { Component, createSignal, For, Show } from "solid-js"; import { Game, GameWithPrediction, Period, Team } from "~/interface"; - import { FiClock } from "solid-icons/fi"; import { IoLocationOutline } from "solid-icons/io"; import { OcDotfill3 } from "solid-icons/oc"; diff --git a/ui/src/pages/History.tsx b/ui/src/pages/History.tsx index aca274b..c5f5406 100644 --- a/ui/src/pages/History.tsx +++ b/ui/src/pages/History.tsx @@ -9,45 +9,30 @@ async function fetchHistory() { return await instance.getDates(); } -async function fetchHistoryForModelOnDate(model: string, date: string) { - const instance = AccuribetAPI.getInstance(); - return await instance.getPredictedGames(date, model); +interface IHistory { + model: string; + date: string; } -export function History() { - const [dates] = createResource(fetchHistory); - const [selectedModel, setSelectedModel] = createSignal(""); - const [selectedDate, setSelectedDate] = createSignal(""); - const [history, setHistory] = createSignal([]); - const [error, setError] = createSignal(""); +async function fetchHistoryForModelOnDate( + value: IHistory +): Promise { + if (value.date === "" || value.model === "") return undefined; + const instance = AccuribetAPI.getInstance(); + return await instance.getPredictedGames(value.date, value.model); +} - const handleDateChange = (e: Event) => { - let target = e.target as HTMLInputElement; - setSelectedDate(target.value); - setHistory([]); - updateHistory().then(() => { - setError(""); - }); - }; - const updateHistory = async () => { - const data = await fetchHistoryForModelOnDate(selectedModel(), selectedDate()); - - console.log("oldest date", oldestDateForModel()); +export function History() { + const [dates] = createResource(fetchHistory); + const [currentData, setCurrentData] = createSignal({ model: "", date: "" } as IHistory); + const [historyResource] = createResource(currentData, fetchHistoryForModelOnDate); - if (data) { - setHistory(data as HistoryGame[]); - console.log(history()); - } else { - setHistory([]); - setError("No data found for this model on this date"); - } - }; const oldestDateForModel = () => { if (!dates.error && dates()) { - const datesForModel = dates()?.find(date => date.model_name === selectedModel()); + const datesForModel = dates()?.find(date => date.model_name === currentData().model); if (datesForModel) { return datesForModel.dates[datesForModel.dates.length - 1]; } @@ -69,7 +54,7 @@ export function History() { I would like to see the history of the { + setCurrentData({ ...currentData(), date: event.target.value }); + }} max={new Date().toISOString().split("T")[0]} min={oldestDateForModel()} /> - - + + + {game => ( -
{game.home_team_name} vs {game.away_team_name} @@ -114,9 +102,10 @@ export function History() { {game.home_team_score} - {game.away_team_score} {game.date} -
+
)}
+