Skip to content

Commit e7a3ef6

Browse files
committed
fix(my-songs): prevent initial fetch with page=0 causing 400 error
1 parent b6d4401 commit e7a3ef6

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

apps/frontend/src/modules/my-songs/components/client/context/MySongs.context.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const useMySongsStore = create<MySongsStore>((set, get) => ({
5151
page: null,
5252
totalSongs: 0,
5353
totalPages: 0,
54-
currentPage: 0,
54+
currentPage: 1,
5555
pageSize: MY_SONGS.PAGE_SIZE,
5656
isLoading: true,
5757
error: null,
@@ -203,10 +203,15 @@ export const useMySongsStore = create<MySongsStore>((set, get) => ({
203203
export const useMySongsPageLoader = () => {
204204
const currentPage = useMySongsStore((state) => state.currentPage);
205205
const loadPage = useMySongsStore((state) => state.loadPage);
206+
const loadedSongs = useMySongsStore((state) => state.loadedSongs);
206207

207208
useEffect(() => {
209+
// Skip loading if the page is already loaded from initial data
210+
if (currentPage in loadedSongs) {
211+
return;
212+
}
208213
loadPage();
209-
}, [currentPage, loadPage]);
214+
}, [currentPage, loadPage, loadedSongs]);
210215
};
211216

212217
// Legacy hook name for backward compatibility
@@ -227,7 +232,7 @@ export const MySongProvider = ({
227232
InitialsongsFolder = {},
228233
children,
229234
totalPagesInit = 0,
230-
currentPageInit = 0,
235+
currentPageInit = 1,
231236
pageSizeInit = MY_SONGS.PAGE_SIZE,
232237
}: MySongProviderProps) => {
233238
const initialize = useMySongsStore((state) => state.initialize);

0 commit comments

Comments
 (0)