File tree 10 files changed +55
-15
lines changed
10 files changed +55
-15
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,11 @@ export default async function ProfileTopAlbumsSubPage({
44
44
const statsMeasurement = validateStatsMeasurement (
45
45
searchParams [ STATS_MEASUREMENT ]
46
46
)
47
- const timeRange = validateTimeRange ( searchParams [ TIME_RANGE ] , statsProvider )
47
+ const timeRange = validateTimeRange (
48
+ searchParams [ TIME_RANGE ] ,
49
+ statsProvider ,
50
+ createdAt
51
+ )
48
52
const view = validateView ( searchParams [ VIEW ] )
49
53
50
54
if ( statsProvider === StatsProvider . SPOTIFY ) return null
Original file line number Diff line number Diff line change @@ -50,7 +50,11 @@ export default async function ProfileTopArtistsSubPage({
50
50
const statsMeasurement = validateStatsMeasurement (
51
51
searchParams [ STATS_MEASUREMENT ]
52
52
)
53
- const timeRange = validateTimeRange ( searchParams [ TIME_RANGE ] , statsProvider )
53
+ const timeRange = validateTimeRange (
54
+ searchParams [ TIME_RANGE ] ,
55
+ statsProvider ,
56
+ createdAt
57
+ )
54
58
const view = validateView ( searchParams [ VIEW ] )
55
59
56
60
let items : ArtistEntity [ ] | RigtchStatsResponse < ArtistEntity >
Original file line number Diff line number Diff line change @@ -48,7 +48,11 @@ export default async function ProfileTopGenresSubPage({
48
48
const statsMeasurement = validateStatsMeasurement (
49
49
searchParams [ STATS_MEASUREMENT ]
50
50
)
51
- const timeRange = validateTimeRange ( searchParams [ TIME_RANGE ] , statsProvider )
51
+ const timeRange = validateTimeRange (
52
+ searchParams [ TIME_RANGE ] ,
53
+ statsProvider ,
54
+ createdAt
55
+ )
52
56
53
57
let items : string [ ] | RigtchStatsResponse < string >
54
58
Original file line number Diff line number Diff line change @@ -47,7 +47,11 @@ export default async function ProfileTopTracksSubPage({
47
47
searchParams [ STATS_PROVIDER ] ,
48
48
createdAt
49
49
)
50
- const timeRange = validateTimeRange ( searchParams [ TIME_RANGE ] , statsProvider )
50
+ const timeRange = validateTimeRange (
51
+ searchParams [ TIME_RANGE ] ,
52
+ statsProvider ,
53
+ createdAt
54
+ )
51
55
const statsMeasurement = validateStatsMeasurement (
52
56
searchParams [ STATS_MEASUREMENT ]
53
57
)
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
13
13
} from '@app/profile/utils/validators'
14
14
import { afterParamFactory } from '@app/profile/utils/factories'
15
15
import { StatsProvider , type RigtchTimeRange } from '@app/profile/enums'
16
+ import { getUser } from '@app/api/fetchers'
16
17
17
18
export const runtime = 'edge'
18
19
@@ -21,19 +22,24 @@ export default async function ProfileTopAlbumsPage({
21
22
params,
22
23
} : ProfilePageProps ) {
23
24
const userId = validateId ( params . id )
25
+ const token = await getServerToken ( )
26
+
27
+ if ( ! token ) redirect ( '/' )
28
+
29
+ const { createdAt } = await getUser ( token , {
30
+ userId,
31
+ } )
32
+
24
33
const statsMeasurement = validateStatsMeasurement (
25
34
searchParams [ STATS_MEASUREMENT ]
26
35
)
27
36
const timeRange = validateTimeRange (
28
37
searchParams [ TIME_RANGE ] ,
29
- StatsProvider . RIGTCH
38
+ StatsProvider . RIGTCH ,
39
+ createdAt
30
40
)
31
41
const view = validateView ( searchParams [ VIEW ] )
32
42
33
- const token = await getServerToken ( )
34
-
35
- if ( ! token ) redirect ( '/' )
36
-
37
43
const items = await getRigtchTopAlbums ( token , {
38
44
after : afterParamFactory ( timeRange as RigtchTimeRange ) ,
39
45
userId,
Original file line number Diff line number Diff line change @@ -49,7 +49,11 @@ export default async function ProfileTopArtistsPage({
49
49
const statsMeasurement = validateStatsMeasurement (
50
50
searchParams [ STATS_MEASUREMENT ]
51
51
)
52
- const timeRange = validateTimeRange ( searchParams [ TIME_RANGE ] , statsProvider )
52
+ const timeRange = validateTimeRange (
53
+ searchParams [ TIME_RANGE ] ,
54
+ statsProvider ,
55
+ createdAt
56
+ )
53
57
const view = validateView ( searchParams [ VIEW ] )
54
58
55
59
let items : ArtistEntity [ ] | RigtchStatsResponse < ArtistEntity >
Original file line number Diff line number Diff line change @@ -47,7 +47,11 @@ export default async function ProfileTopGenresPage({
47
47
const statsMeasurement = validateStatsMeasurement (
48
48
searchParams [ STATS_MEASUREMENT ]
49
49
)
50
- const timeRange = validateTimeRange ( searchParams [ TIME_RANGE ] , statsProvider )
50
+ const timeRange = validateTimeRange (
51
+ searchParams [ TIME_RANGE ] ,
52
+ statsProvider ,
53
+ createdAt
54
+ )
51
55
52
56
let items : string [ ] | RigtchStatsResponse < string >
53
57
Original file line number Diff line number Diff line change @@ -49,7 +49,11 @@ export default async function ProfileTopTracksPage({
49
49
const statsMeasurement = validateStatsMeasurement (
50
50
searchParams [ STATS_MEASUREMENT ]
51
51
)
52
- const timeRange = validateTimeRange ( searchParams [ TIME_RANGE ] , statsProvider )
52
+ const timeRange = validateTimeRange (
53
+ searchParams [ TIME_RANGE ] ,
54
+ statsProvider ,
55
+ createdAt
56
+ )
53
57
const view = validateView ( searchParams [ VIEW ] )
54
58
55
59
let items : TrackEntity [ ] | RigtchStatsResponse < TrackEntity >
Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ export function StatsOptions() {
35
35
const view = validateView ( searchParams . get ( VIEW ) )
36
36
const timeRange = validateTimeRange (
37
37
searchParams . get ( TIME_RANGE ) ,
38
- statsProvider
38
+ statsProvider ,
39
+ user ?. createdAt
39
40
)
40
41
41
42
const route = pathname . split ( '/' ) . at ( - 1 )
Original file line number Diff line number Diff line change
1
+ import { isTimeRangeDisabled } from '../helpers'
2
+
1
3
import {
2
4
DEFAULT_RIGTCH_TIME_RANCE ,
3
5
DEFAULT_SPOTIFY_TIME_RANCE ,
@@ -18,7 +20,8 @@ function isRigtchTimeRange(value: string): value is RigtchTimeRange {
18
20
19
21
export function validateTimeRange (
20
22
timeRange : string | string [ ] | null | undefined ,
21
- provider : StatsProvider
23
+ provider : StatsProvider ,
24
+ userCreatedAt ?: Date
22
25
) {
23
26
if ( typeof timeRange === 'string' ) {
24
27
if ( provider === StatsProvider . SPOTIFY && isSpotifyTimeRange ( timeRange ) )
@@ -30,5 +33,7 @@ export function validateTimeRange(
30
33
31
34
return provider === StatsProvider . SPOTIFY
32
35
? DEFAULT_SPOTIFY_TIME_RANCE
33
- : DEFAULT_RIGTCH_TIME_RANCE
36
+ : isTimeRangeDisabled ( DEFAULT_RIGTCH_TIME_RANCE , userCreatedAt )
37
+ ? RigtchTimeRange . WEEK
38
+ : DEFAULT_RIGTCH_TIME_RANCE
34
39
}
You can’t perform that action at this time.
0 commit comments