diff options
Diffstat (limited to 'src/helpers')
| -rw-r--r-- | src/helpers/fetchSolution.ts | 2 | ||||
| -rw-r--r-- | src/helpers/fetchSongs.ts | 3 | ||||
| -rw-r--r-- | src/helpers/index.ts | 1 | ||||
| -rw-r--r-- | src/helpers/searchSong.ts | 6 | ||||
| -rw-r--r-- | src/helpers/todaysSolution.ts | 11 |
5 files changed, 7 insertions, 16 deletions
diff --git a/src/helpers/fetchSolution.ts b/src/helpers/fetchSolution.ts index d271dd0..5f5e2f3 100644 --- a/src/helpers/fetchSolution.ts +++ b/src/helpers/fetchSolution.ts @@ -1,7 +1,7 @@ import { Song } from "../types/song"; const SALT = process.env.REACT_APP_HEARDLE_SALT ?? 'changeme'; -const API_URL = process.env.REACT_APP_HEARDLE_API_URL ?? 'http://23:432e3001'; +const API_URL = process.env.REACT_APP_HEARDLE_API_URL ?? 'https://127.0.0.1:3001'; function hexToBytes(hex: string): Uint8Array { const bytes = new Uint8Array(hex.length / 2); diff --git a/src/helpers/fetchSongs.ts b/src/helpers/fetchSongs.ts index 5ae0d83..b403a52 100644 --- a/src/helpers/fetchSongs.ts +++ b/src/helpers/fetchSongs.ts @@ -6,12 +6,13 @@ function fuzzyMatch(input: string): string { export async function fetchSongs(useCache=true): Promise<Song[]> { + const API_URL = process.env.REACT_APP_HEARDLE_API_URL || "http://localhost:3001"; if (useCache && cachedSongs) { return cachedSongs; } try { - const response = await fetch('/songs'); + const response = await fetch(`${API_URL}/songs`); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 5593bc5..f8513ac 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -1,3 +1,2 @@ export { scoreToEmoji } from "./scoreToEmoji"; export { searchSong } from "./searchSong"; -export { todaysSolution } from "./todaysSolution"; diff --git a/src/helpers/searchSong.ts b/src/helpers/searchSong.ts index 13fa794..9ce36cf 100644 --- a/src/helpers/searchSong.ts +++ b/src/helpers/searchSong.ts @@ -1,12 +1,14 @@ -import { songs } from "../constants"; +import { fetchSongs } from "./fetchSongs"; import { Song } from "../types/song"; -export function searchSong(searchTerm: string): Song[] { +export async function searchSong(searchTerm: string): Promise<Song[]> { function fuzzyMatch(input: string){ return input.toLowerCase().replace(/[^0-9a-z ]/gi, ''); } searchTerm = fuzzyMatch(searchTerm); + const songs = await fetchSongs(); + return songs .filter((song: Song) => { const songName = fuzzyMatch(song.name); diff --git a/src/helpers/todaysSolution.ts b/src/helpers/todaysSolution.ts deleted file mode 100644 index 32760cb..0000000 --- a/src/helpers/todaysSolution.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { songs, startDate } from "../constants"; - -// const epochMs = new Date(2022, 3, 10).valueOf(); -// const now = Date.now(); -// const index = Math.floor((now - epochMs) / msInDay); - -const msInDay = 86400000; -const todaysDate = new Date(); -const index = Math.floor((todaysDate.getTime() - startDate.getTime() )/msInDay) - -export const todaysSolution = songs[index % songs.length]; |
