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
refactoring
  • Loading branch information
damienmauchamp committed Mar 30, 2024
commit b4e4f6df38d4b851b490d9273344f5aae489bbba
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ server {

## TODO

- [ ] externalize albums/songs list components
- [ ] groups similar pages/components
- [ ] create "cache" for each section for data ?
66 changes: 2 additions & 64 deletions app/new-releases/page.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,5 @@
'use client'
import useAPI from '@/lib/useAPI'
import useAuth from '@/lib/useAuth'
import Loading from '@/src/components/Components/Loading/Loading'
import AlbumsGridSection from '@/src/components/LayoutComponents/AlbumsGridSection/AlbumsGridSection'
import PageNavigation from '@/src/components/Pages/PageNavigation/PageNavigation'
import { Album } from '@/types/Items'
import moment from 'moment'
import { useEffect, useState } from 'react'
import NewReleasesGridPage from '@/src/components/Pages/User/NewReleasesGridPage'

export default function Home() {
// Hooks
// const { logged } = useMusicKitContext()

// Auth hook
const { user, isLoading, hasTestToken } = useAuth({ middleware: 'auth' }) // todo : redirect to previous page after login
const [ready, setReady] = useState<boolean>(false)
const [newReleases, setNewReleases] = useState<Album[]>([])

// API hook
const api = useAPI()

// API calls
const from = moment().subtract(7, 'days').format('YYYY-MM-DD')

const loadNewSingles = async () => {
const res = await api.getNewReleases(from)
setNewReleases(res.data.data)
}
const loadData = () => {
if (!ready) return
loadNewSingles()
}

useEffect(() => {
if (!isLoading && (user || hasTestToken)) {
setReady(true)
}
}, [isLoading, user, hasTestToken])

useEffect(() => {
// if (ready) {
loadData()
// }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ready])

if (isLoading || !(user || hasTestToken)) {
return <Loading subText="Loading new releases page" />
}

return (
<PageNavigation title={'New Releases'} goBack={true} largeTitle={true}>
<AlbumsGridSection
id={'newReleases'}
title={''}
// title={'New Releases'}
key={'newReleases'}
items={newReleases}
scroll={false}
mobileScroll={false}
// rows={2}
// seeAll={() => console.log('see all 1')}
/>
</PageNavigation>
)
return <NewReleasesGridPage />
}
66 changes: 2 additions & 64 deletions app/new-singles/page.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,5 @@
'use client'
import useAPI from '@/lib/useAPI'
import useAuth from '@/lib/useAuth'
import Loading from '@/src/components/Components/Loading/Loading'
import AlbumsGridSection from '@/src/components/LayoutComponents/AlbumsGridSection/AlbumsGridSection'
import PageNavigation from '@/src/components/Pages/PageNavigation/PageNavigation'
import { Album } from '@/types/Items'
import moment from 'moment'
import { useEffect, useState } from 'react'
import NewSinglesGridPage from '@/src/components/Pages/User/NewSinglesGridPage'

export default function Home() {
// Hooks
// const { logged } = useMusicKitContext()

// Auth hook
const { user, isLoading, hasTestToken } = useAuth({ middleware: 'auth' }) // todo : redirect to previous page after login
const [ready, setReady] = useState<boolean>(false)
const [newSingles, setNewSingles] = useState<Album[]>([])

// API hook
const api = useAPI()

// API calls
const from = moment().subtract(7, 'days').format('YYYY-MM-DD')

const loadNewSingles = async () => {
const res = await api.getNewSingles(from)
setNewSingles(res.data.data)
}
const loadData = () => {
if (!ready) return
loadNewSingles()
}

useEffect(() => {
if (!isLoading && (user || hasTestToken)) {
setReady(true)
}
}, [isLoading, user, hasTestToken])

useEffect(() => {
// if (ready) {
loadData()
// }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ready])

if (isLoading || !(user || hasTestToken)) {
return <Loading subText="Loading new singles page" />
}

return (
<PageNavigation title={'New Singles'} goBack={true} largeTitle={true}>
<AlbumsGridSection
id={'newSingles'}
// title={'New Singles'}
title={''}
key={'newSingles'}
items={newSingles}
scroll={false}
mobileScroll={false}
// rows={2}
// seeAll={() => console.log('see all 1')}
/>
</PageNavigation>
)
return <NewSinglesGridPage />
}
65 changes: 2 additions & 63 deletions app/new-songs/page.tsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,5 @@
'use client'
import useAPI from '@/lib/useAPI'
import useAuth from '@/lib/useAuth'
import Loading from '@/src/components/Components/Loading/Loading'
import SongsListSection from '@/src/components/LayoutComponents/SongsListSection/SongsListSection'
import PageNavigation from '@/src/components/Pages/PageNavigation/PageNavigation'
import { Song } from '@/types/Items'
import moment from 'moment'
import { useEffect, useState } from 'react'
import NewSongsListPage from '@/src/components/Pages/User/NewSongsListPage'

export default function Home() {
// Hooks
// const { logged } = useMusicKitContext()

// Auth hook
const { user, isLoading, hasTestToken } = useAuth({ middleware: 'auth' }) // todo : redirect to previous page after login
const [ready, setReady] = useState<boolean>(false)
const [newSongs, setNewSongs] = useState<Song[]>([])

// API hook
const api = useAPI()

// API calls
const from = moment().subtract(7, 'days').format('YYYY-MM-DD')

const loadNewSongs = async () => {
const res = await api.getNewSongs(from)
setNewSongs(res.data.data)
}
const loadData = () => {
if (!ready) return
loadNewSongs()
}

useEffect(() => {
if (!isLoading && (user || hasTestToken)) {
setReady(true)
}
}, [isLoading, user, hasTestToken])

useEffect(() => {
// if (ready) {
loadData()
// }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ready])

if (isLoading || !(user || hasTestToken)) {
return <Loading subText="Loading new songs page" />
}

return (
<PageNavigation title={'New Songs'} goBack={true} largeTitle={true}>
<SongsListSection
id={'newSongs'}
// title={'New Songs'}
title={''}
key={'newSongs'}
items={newSongs}
scroll={false}
// rows={2}
// seeAll={() => console.log('see all 1')}
/>
</PageNavigation>
)
return <NewSongsListPage />
}
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReleasesPage from '@/src/components/Pages/User/ReleasesPages'
import ReleasesPage from '@/src/components/Pages/User/ReleasesPage'

export default function Home() {
return <ReleasesPage />
Expand Down
5 changes: 5 additions & 0 deletions app/upcoming-releases/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import UpcomingReleasesGridPage from '@/src/components/Pages/User/UpcomingReleasesGridPage'

export default function Home() {
return <UpcomingReleasesGridPage />
}
5 changes: 5 additions & 0 deletions app/upcoming-songs/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import UpcomingSongsListPage from '@/src/components/Pages/User/UpcomingSongsListPage'

export default function Home() {
return <UpcomingSongsListPage />
}
67 changes: 0 additions & 67 deletions app/upcoming/page.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions lib/useAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default function useAPI() {
},
})
}
const getUpcoming = (from: string) => {
const getUpcomingReleases = (from: string) => {
return get(`/api/user/releases`, {
params: {
...timestamps(),
Expand Down Expand Up @@ -171,7 +171,7 @@ export default function useAPI() {
//
getNewReleases,
getNewSingles,
getUpcoming,
getUpcomingReleases,
getNewSongs,
getUpcomingSongs,
addResourceToLibrary,
Expand Down
12 changes: 0 additions & 12 deletions src/components/Elements/ArtistLink.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import AlbumsSection, { AlbumsSectionProps } from './AlbumsSection'

export interface AlbumsGridSectionProps extends AlbumsSectionProps {}

const AlbumsGridSection = ({ ...props }: AlbumsGridSectionProps) => (
<AlbumsSection {...props} grid />
)

export default AlbumsGridSection
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,35 @@ import AlbumsCollectionView, {
import { Album, SectionCollectionProps } from '@/types/Items'
import Loading from '../../Components/Loading/Loading'

interface AlbumsGridSectionProps
export interface AlbumsSectionProps
extends SectionProps,
AlbumCollectionViewProps,
SectionCollectionProps {
// key: string
items: Album[]

grid?: boolean
}

const AlbumsGridSection = ({
const AlbumsSection = ({
id,
title,
seeAll,
seeAllPath,
grid = false,
loading = false,
...props
}: AlbumsGridSectionProps) => {
}: AlbumsSectionProps) => {
if (!loading && !props.items.length) {
return null
}

const collectionViewProps = () => {
if (!grid) return { ...props }

return { ...props, grid: grid, mobileScroll: false }
}

return (
<>
<Section
Expand All @@ -40,12 +49,11 @@ const AlbumsGridSection = ({
<Loading subText={`${title} loading...`} />
</div>
) : (
<AlbumsCollectionView id={id} {...props} />
<AlbumsCollectionView id={id} {...collectionViewProps()} />
)}
</Section>
</>
)
}

export default AlbumsGridSection
export type { AlbumsGridSectionProps }
export default AlbumsSection
Loading