From 01bdbf76024f51bbc1072e33ceffb0c59ae45032 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Wed, 3 Jun 2026 10:08:41 -0700 Subject: move startDate to backend --- src/helpers/fetchInfo.ts | 9 +++++++++ src/helpers/scoreToEmoji.ts | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/helpers/fetchInfo.ts (limited to 'src/helpers') diff --git a/src/helpers/fetchInfo.ts b/src/helpers/fetchInfo.ts new file mode 100644 index 0000000..248cd98 --- /dev/null +++ b/src/helpers/fetchInfo.ts @@ -0,0 +1,9 @@ + +import { Info } from "../types/info"; + +export const fetchInfo = async (): Promise => { + const API_URL = process.env.REACT_APP_API_URL || "https://localhost:3000"; + const response = await fetch(`${API_URL}/info`); + const data = await response.json(); + return data as Info; +}; diff --git a/src/helpers/scoreToEmoji.ts b/src/helpers/scoreToEmoji.ts index cb525a8..5af1026 100644 --- a/src/helpers/scoreToEmoji.ts +++ b/src/helpers/scoreToEmoji.ts @@ -1,9 +1,12 @@ import { GuessType, GuessState } from "../types/guess"; -import { appName, startDate } from "../constants"; +import { appName } from "../constants"; +import { fetchInfo } from "./fetchInfo"; -export function scoreToEmoji(guesses: GuessType[]): string { +export async function scoreToEmoji(guesses: GuessType[]): Promise { const msInDay = 86400000; const todaysDate = new Date(); + const info = await fetchInfo(); + const startDate = new Date(info.startDate); const index = Math.floor((todaysDate.getTime() - startDate.getTime() )/msInDay) + 1 const emojis = { incorrect: "🟥", -- cgit v1.2.3