Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework7 & other stuff #4

Merged
merged 25 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
new releases/singles sections
  • Loading branch information
damienmauchamp committed Apr 7, 2024
commit 5f8bef90f7b56c71fd849b8b7f8fa6d05f95b667
4 changes: 4 additions & 0 deletions lib/useAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ export default function useAPI() {
/* region API */
const getNewReleases = (
from: string,
params: object = {},
config?: AxiosRequestConfig<any> | undefined
) => {
return get(`/api/user/releases`, {
...config,
params: {
...defaultParams(),
from: from,
...params,
sort: '-releaseDate',
// weekly: 1,
// weeks: 1,
Expand All @@ -113,13 +115,15 @@ export default function useAPI() {
}
const getNewSingles = (
from: string,
params: object = {},
config?: AxiosRequestConfig<any> | undefined
) => {
return get(`/api/user/releases`, {
...config,
params: {
...defaultParams(),
from: from,
...params,
sort: '-releaseDate',
hide_albums: 1,
hide_eps: 1,
Expand Down
34 changes: 28 additions & 6 deletions src/components/PageComponents/NewReleases/NewReleasesSection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useState } from 'react'
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { Album } from '@/types/Items'
import { getFrom } from '@/src/helpers/releases'
import { getFromViaWeeks, getToViaWeeks } from '@/src/helpers/releases'
import useAPI from '@/lib/useAPI'
import AlbumsSection from '../../LayoutComponents/AlbumsSection/AlbumsSection'

Expand All @@ -14,15 +14,35 @@ export interface NewReleasesSectionProps {

newNav?: boolean
full?: boolean

weeks?: number
}

function NewReleasesSection({
data = [] as Album[],
grid = false,
weeks = 0,
title,
...props
}: NewReleasesSectionProps) {
const api = useAPI()
const from = getFrom()
// const from = getFrom()
const from = getFromViaWeeks(weeks)
const params = useMemo(
() =>
weeks
? {
// weekly: 1,
// weeks: weeks * -1,
weekly: 0,
to: getToViaWeeks(weeks),
}
: {},
[weeks]
)
if (!title && weeks) {
title = getFromViaWeeks(weeks, 'll')
}

const hasData = Boolean(data.length)

Expand All @@ -35,7 +55,9 @@ function NewReleasesSection({
async (signal?: AbortSignal) => {
try {
if (!hasData && !newReleasesLoaded && !newReleasesLoading) {
const res = await api.getNewReleases(from, { signal })
const res = await api.getNewReleases(from, params, {
signal,
})
setNewReleases(res.data.data)
setNewReleasesLoading(true)
}
Expand All @@ -46,7 +68,7 @@ function NewReleasesSection({
setNewReleasesLoading(false)
}
},
[api, from, hasData, newReleasesLoaded, newReleasesLoading]
[api, from, params, hasData, newReleasesLoaded, newReleasesLoading]
)

useEffect(() => {
Expand Down Expand Up @@ -84,7 +106,7 @@ function NewReleasesSection({
return (
<AlbumsSection
id={props.id || 'newReleases'}
title={props.title}
title={title}
key={props.id || 'newReleases'}
items={newReleases}
scroll={false}
Expand Down
36 changes: 30 additions & 6 deletions src/components/PageComponents/NewSingles/NewSinglesSection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useState } from 'react'
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { Album } from '@/types/Items'
import { getFrom } from '@/src/helpers/releases'
import { getFromViaWeeks, getToViaWeeks } from '@/src/helpers/releases'
import useAPI from '@/lib/useAPI'
import AlbumsSection from '../../LayoutComponents/AlbumsSection/AlbumsSection'

Expand All @@ -14,15 +14,37 @@ export interface NewSinglesSectionProps {

newNav?: boolean
full?: boolean

weeks?: number
}

function NewSinglesSection({
data = [] as Album[],
grid = false,
weeks = 0,
title,
...props
}: NewSinglesSectionProps) {
const api = useAPI()
const from = getFrom()
// const from = getFrom()
const from = getFromViaWeeks(weeks)

const params = useMemo(
() =>
weeks
? {
// weekly: 1,
// weeks: weeks * -1,
weekly: 0,
to: getToViaWeeks(weeks),
}
: {},
[weeks]
)
if (!title && weeks) {
// title = `${weeks} week${weeks > 1 ? 's' : ''} ago`
title = getFromViaWeeks(weeks, 'll')
}

const hasData = Boolean(data.length)

Expand All @@ -35,7 +57,9 @@ function NewSinglesSection({
async (signal?: AbortSignal) => {
try {
if (!hasData && !newSinglesLoaded && !newSinglesLoading) {
const res = await api.getNewSingles(from, { signal })
const res = await api.getNewSingles(from, params, {
signal,
})
setNewSingles(res.data.data)
setNewSinglesLoading(true)
}
Expand All @@ -46,7 +70,7 @@ function NewSinglesSection({
setNewSinglesLoading(false)
}
},
[api, from, hasData, newSinglesLoading, newSinglesLoaded]
[api, from, params, hasData, newSinglesLoading, newSinglesLoaded]
)

useEffect(() => {
Expand Down Expand Up @@ -85,7 +109,7 @@ function NewSinglesSection({
return (
<AlbumsSection
id={props.id || 'newSingles'}
title={props.title}
title={title}
key={props.id || 'newSingles'}
items={newSingles}
// mobileScroll={true}
Expand Down
8 changes: 8 additions & 0 deletions src/components/Pages/User/NewReleasesGridPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export default function NewReleasesGridPage({
{...props}
>
<NewReleasesGridSection full />
{[...Array(6)].map((value, index) =>
!index ? null : (
<NewReleasesGridSection
key={`NewReleasesGridSection${index}`}
weeks={-index}
/>
)
)}
</AppPage>
)
}
6 changes: 6 additions & 0 deletions src/components/Pages/User/NewSinglesGridPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export default function NewSinglesGridPage({
{...props}
>
<NewSinglesGridSection full />
<NewSinglesGridSection weeks={-1} />
<NewSinglesGridSection weeks={-2} />
<NewSinglesGridSection weeks={-3} />
<NewSinglesGridSection weeks={-4} />
<NewSinglesGridSection weeks={-5} />
<NewSinglesGridSection weeks={-6} />
</AppPage>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
.gridNotScrollable {
@apply max-sm:grid-cols-2 max-md:grid-cols-4 grid-cols-6;
@apply overflow-x-hidden;
@apply grid-rows-none;
}

.gridScrollable {
Expand Down
18 changes: 17 additions & 1 deletion src/helpers/releases.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
import moment from 'moment'

export const getFrom = () => moment().subtract(7, 'days').format('YYYY-MM-DD')
export const DATE_FORMAT = 'YYYY-MM-DD'
export const getFrom = (format: string = DATE_FORMAT) =>
moment().subtract(7, 'days').format(format)
export const getFromViaWeeks = (
weeks: number = 0,
format: string = DATE_FORMAT
) =>
moment()
.add((weeks - 1) * 7, 'days')
.format(format)
export const getToViaWeeks = (
weeks: number = 0,
format: string = DATE_FORMAT
) =>
moment(getFromViaWeeks(weeks + 1))
.subtract(1, 'days')
.format(format)