From f096b5c355a59f50edb3e8c4d62b299c713ca0e6 Mon Sep 17 00:00:00 2001 From: mbrucedogs Date: Mon, 21 Jul 2025 11:29:52 -0500 Subject: [PATCH] Signed-off-by: mbrucedogs --- src/firebase/services.ts | 36 ++++++++++++++++++++++++++++++------ tsconfig.app.json | 4 ++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/firebase/services.ts b/src/firebase/services.ts index 3663a9b..f1ff241 100644 --- a/src/firebase/services.ts +++ b/src/firebase/services.ts @@ -2,7 +2,6 @@ import { ref, get, set, - push, remove, onValue, off, @@ -163,7 +162,16 @@ export const historyService = { // Add song to history addToHistory: async (controllerName: string, song: Omit) => { const historyRef = ref(database, `controllers/${controllerName}/history`); - return await push(historyRef, song); + const historySnapshot = await get(historyRef); + const currentHistory = historySnapshot.exists() ? historySnapshot.val() : {}; + const numericKeys = Object.keys(currentHistory) + .map((key) => parseInt(key, 10)) + .filter((num) => !isNaN(num)); + const nextKey = numericKeys.length > 0 ? Math.max(...numericKeys) + 1 : 1; + const nextKeyStr = String(nextKey); + const newHistoryRef = ref(database, `controllers/${controllerName}/history/${nextKeyStr}`); + await set(newHistoryRef, song); + return { key: nextKeyStr }; }, // Remove song from history @@ -188,7 +196,16 @@ export const favoritesService = { // Add song to favorites addToFavorites: async (controllerName: string, song: Omit) => { const favoritesRef = ref(database, `controllers/${controllerName}/favorites`); - return await push(favoritesRef, song); + const favoritesSnapshot = await get(favoritesRef); + const currentFavorites = favoritesSnapshot.exists() ? favoritesSnapshot.val() : {}; + const numericKeys = Object.keys(currentFavorites) + .map((key) => parseInt(key, 10)) + .filter((num) => !isNaN(num)); + const nextKey = numericKeys.length > 0 ? Math.max(...numericKeys) + 1 : 1; + const nextKeyStr = String(nextKey); + const newFavoriteRef = ref(database, `controllers/${controllerName}/favorites/${nextKeyStr}`); + await set(newFavoriteRef, song); + return { key: nextKeyStr }; }, // Remove song from favorites @@ -226,17 +243,24 @@ export const singerService = { throw new Error('Singer already exists'); } + // Find the next available numeric key + const numericKeys = Object.keys(currentSingers) + .map((key) => parseInt(key, 10)) + .filter((num) => !isNaN(num)); + const nextKey = numericKeys.length > 0 ? Math.max(...numericKeys) + 1 : 1; + const nextKeyStr = String(nextKey); + // Create new singer with current timestamp const newSinger: Omit = { name: singerName, lastLogin: new Date().toISOString() }; - // Add to singers list - const newSingerRef = push(singersRef); + // Add to singers list with numeric key + const newSingerRef = ref(database, `controllers/${controllerName}/player/singers/${nextKeyStr}`); await set(newSingerRef, newSinger); - return { key: newSingerRef.key }; + return { key: nextKeyStr }; }, // Remove singer and all their queue items diff --git a/tsconfig.app.json b/tsconfig.app.json index 227a6c6..1fa3d63 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -10,7 +10,7 @@ /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, + "verbatimModuleSyntax": false, "moduleDetection": "force", "noEmit": true, "jsx": "react-jsx", @@ -19,7 +19,7 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "erasableSyntaxOnly": true, + "erasableSyntaxOnly": false, "noFallthroughCasesInSwitch": true, "noUncheckedSideEffectImports": true },