@@ -40,7 +40,7 @@ import {
40
40
TopGenres ,
41
41
TopTracks ,
42
42
} from '@/components/User' ;
43
- import { clockProps , type UserPageCarouselsWithGrid } from '@/utils' ;
43
+ import { clockProps , type UserScrollIntoView } from '@/utils' ;
44
44
import dynamic from 'next/dynamic' ;
45
45
import type { TimeframeSelection } from '@/components/User/utils' ;
46
46
import { getTimeframeOptions , getTimeframeText } from '@/components/User/utils' ;
@@ -51,18 +51,25 @@ type Props = SSRProps & {
51
51
userProfile : statsfm . UserPublic ;
52
52
friendStatus : statsfm . FriendStatus ;
53
53
friendCount : number ;
54
- activeCarousel : UserPageCarouselsWithGrid | null ;
54
+ scrollIntoView : UserScrollIntoView | null ;
55
55
} ;
56
56
57
- function activeGridModeFromDeepLink (
57
+ function activeScrollIntoViewFromDeepLink (
58
58
deeplink : string | string [ ] | undefined
59
- ) : UserPageCarouselsWithGrid | null {
59
+ ) : UserScrollIntoView | null {
60
60
if ( typeof deeplink !== 'object' ) return null ;
61
61
if ( deeplink . length !== 1 ) return null ;
62
62
63
63
const [ id ] = deeplink ;
64
- // TODO: this should rewrite or redirect
65
- if ( id !== 'tracks' && id !== 'albums' && id !== 'artists' ) return null ;
64
+ if (
65
+ id !== 'genres' &&
66
+ id !== 'tracks' &&
67
+ id !== 'albums' &&
68
+ id !== 'artists' &&
69
+ id !== 'listeningClocks' &&
70
+ id !== 'recentStreams'
71
+ )
72
+ return null ;
66
73
67
74
return id ;
68
75
}
@@ -77,10 +84,13 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
77
84
throw new Error ( 'no param id recieved' ) ;
78
85
}
79
86
80
- const activeCarousel = activeGridModeFromDeepLink ( deeplink ) ;
87
+ const scrollIntoView = activeScrollIntoViewFromDeepLink ( deeplink ) ;
81
88
82
89
const userProfile = await api . users . get ( id ) . catch ( ( ) => { } ) ;
83
- if ( ! userProfile ) return { notFound : true } ;
90
+ if ( ! userProfile )
91
+ return {
92
+ notFound : true ,
93
+ } ;
84
94
85
95
const user = await fetchUser ( ctx ) ;
86
96
@@ -105,11 +115,11 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
105
115
106
116
return {
107
117
props : {
108
- activeCarousel,
109
118
userProfile,
110
119
user,
111
120
friendStatus,
112
121
friendCount,
122
+ scrollIntoView,
113
123
} ,
114
124
} ;
115
125
} ;
@@ -199,7 +209,7 @@ const User: NextPage<Props> = ({
199
209
userProfile : user ,
200
210
friendStatus,
201
211
friendCount,
202
- activeCarousel ,
212
+ scrollIntoView ,
203
213
} ) => {
204
214
const api = useApi ( ) ;
205
215
const router = useRouter ( ) ;
@@ -221,6 +231,9 @@ const User: NextPage<Props> = ({
221
231
const topTracksRef = useRef < HTMLElement > ( null ) ;
222
232
const topAlbumsRef = useRef < HTMLElement > ( null ) ;
223
233
const topArtistsRef = useRef < HTMLElement > ( null ) ;
234
+ const topGenresRef = useRef < HTMLElement > ( null ) ;
235
+ const listeningClocksRef = useRef < HTMLElement > ( null ) ;
236
+ const recentStreamsRef = useRef < HTMLElement > ( null ) ;
224
237
225
238
const isCurrentUser = currentUser ?. id === user . id ;
226
239
@@ -268,13 +281,16 @@ const User: NextPage<Props> = ({
268
281
} , [ timeframe , user ] ) ;
269
282
270
283
useEffect ( ( ) => {
271
- const refs : Record < UserPageCarouselsWithGrid , RefObject < HTMLElement > > = {
284
+ const refs : Record < UserScrollIntoView , RefObject < HTMLElement > > = {
272
285
tracks : topTracksRef ,
273
286
albums : topAlbumsRef ,
274
287
artists : topArtistsRef ,
288
+ genres : topGenresRef ,
289
+ listeningClocks : listeningClocksRef ,
290
+ recentStreams : recentStreamsRef ,
275
291
} ;
276
292
277
- if ( activeCarousel ) refs [ activeCarousel ] . current ?. scrollIntoView ( ) ;
293
+ if ( scrollIntoView ) refs [ scrollIntoView ] . current ?. scrollIntoView ( ) ;
278
294
} , [ ] ) ;
279
295
280
296
// TODO: improvements
@@ -499,28 +515,32 @@ const User: NextPage<Props> = ({
499
515
) }
500
516
</ section >
501
517
502
- < TopGenres timeframe = { timeframe } userProfile = { user } />
518
+ < TopGenres
519
+ timeframe = { timeframe }
520
+ userProfile = { user }
521
+ topGenresRef = { topGenresRef }
522
+ />
503
523
504
524
< TopTracks
505
525
timeframe = { timeframe }
506
526
userProfile = { user }
507
527
trackRef = { topTracksRef }
508
- activeCarousel = { activeCarousel }
528
+ activeCarousel = { scrollIntoView === 'tracks' }
509
529
/>
510
530
511
531
< TopArtists
512
532
timeframe = { timeframe }
513
533
userProfile = { user }
514
534
artistRef = { topArtistsRef }
515
- activeCarousel = { activeCarousel }
535
+ activeCarousel = { scrollIntoView === 'artists' }
516
536
/>
517
537
518
538
{ user . isPlus && (
519
539
< TopAlbums
520
540
timeframe = { timeframe }
521
541
userProfile = { user }
522
542
albumRef = { topAlbumsRef }
523
- activeCarousel = { activeCarousel }
543
+ activeCarousel = { scrollIntoView === 'albums' }
524
544
/>
525
545
) }
526
546
@@ -535,6 +555,7 @@ const User: NextPage<Props> = ({
535
555
} listening habits throughout the day ${ getTimeframeText (
536
556
timeframe
537
557
) } `}
558
+ ref = { listeningClocksRef }
538
559
>
539
560
< Scope value = "streamStats" >
540
561
< div className = "flex-1 content-center text-center" >
@@ -555,6 +576,7 @@ const User: NextPage<Props> = ({
555
576
isCurrentUser ? 'Your' : `${ user . displayName } 's`
556
577
} recently played tracks`}
557
578
scope = "recentlyPlayed"
579
+ ref = { recentStreamsRef }
558
580
>
559
581
{ ( { headerRef } ) => (
560
582
< Scope value = "recentlyPlayed" >
0 commit comments