@@ -10,27 +10,62 @@ export type ListenedTracks = Omit<Listened, "hooman_id"> & {
1010
1111export async function getLastListenedTracks (
1212 signal : AbortSignal ,
13+ page : number = 0 ,
1314) : Promise < ListenedTracks [ ] > {
14- const { data, error } = await supabase
15- . from ( "listened" )
16- . select < string , ListenedTracks > ( `
17- id,
18- artist_name,
19- track_name,
20- album_lastfm_id,
21- album_name,
22- created_at,
23- listened_at,
24- lastfm_id,
25- hooman:hooman_id (
26- id,
27- lastfm_user
28- )
29- ` )
30- . order ( "listened_at" , { ascending : false } )
31- . limit ( 50 )
32- . abortSignal ( signal ) ;
33-
34- if ( error ) throw error ;
35- return data ?? [ ] ;
15+ const limit = 50 ;
16+ const offset = page * limit ;
17+
18+ console . log ( 'Fetching tracks with page:' , page , 'offset:' , offset ) ;
19+
20+ try {
21+ // First, check if we can connect to Supabase at all
22+ const healthCheck = await supabase . from ( 'listened' ) . select ( 'count()' , { count : 'exact' } ) ;
23+ console . log ( 'Supabase health check:' , healthCheck ) ;
24+
25+ // Now perform the actual query
26+ const { data, error } = await supabase
27+ . from ( "listened" )
28+ . select < string , ListenedTracks > ( `
29+ id,
30+ artist_name,
31+ track_name,
32+ album_lastfm_id,
33+ album_name,
34+ created_at,
35+ listened_at,
36+ lastfm_id,
37+ hooman:hooman_id (
38+ id,
39+ lastfm_user
40+ )
41+ ` )
42+ . order ( "listened_at" , { ascending : false } )
43+ . range ( offset , offset + limit - 1 )
44+ . abortSignal ( signal ) ;
45+
46+ console . log ( 'Supabase response:' , {
47+ dataReceived : ! ! data ,
48+ dataLength : data ?. length || 0 ,
49+ error : error ? error . message : null ,
50+ firstItem : data && data . length > 0 ? {
51+ id : data [ 0 ] . id ,
52+ artist : data [ 0 ] . artist_name ,
53+ track : data [ 0 ] . track_name
54+ } : null
55+ } ) ;
56+
57+ if ( error ) {
58+ console . error ( 'Supabase error details:' , error ) ;
59+ throw error ;
60+ }
61+
62+ if ( ! data || data . length === 0 ) {
63+ console . warn ( 'No data returned from Supabase query' ) ;
64+ }
65+
66+ return data ?? [ ] ;
67+ } catch ( error ) {
68+ console . error ( 'Error fetching tracks:' , error ) ;
69+ throw error ;
70+ }
3671}
0 commit comments