-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
8feb22b
commit 37258ec
Showing
10 changed files
with
754 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
packages/web/src/pages/dashboard-page/components/ArtistContentSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import { useState, useCallback } from 'react' | ||
|
||
import { Nullable } from '@audius/common/utils' | ||
import { | ||
SelectablePill, | ||
IconSearch, | ||
Paper, | ||
Flex, | ||
FilterButton, | ||
TextInput, | ||
TextInputSize | ||
} from '@audius/harmony' | ||
|
||
import { ArtistDashboardAlbumsTab } from './ArtistDashboardAlbumsTab' | ||
import { ArtistDashboardTracksTab } from './ArtistDashboardTracksTab' | ||
import { | ||
useArtistDashboardAlbumFilters, | ||
useArtistDashboardTrackFilters, | ||
useFormattedAlbumData, | ||
useFormattedTrackData | ||
} from './hooks' | ||
import { AlbumFilters, TrackFilters } from './types' | ||
|
||
const messages = { | ||
allReleases: 'All Releases', | ||
tracks: 'Tracks', | ||
albums: 'Albums', | ||
search: (type: Pills) => | ||
`Search ${type === Pills.TRACKS ? 'Tracks' : 'Albums'}` | ||
} | ||
|
||
enum Pills { | ||
TRACKS, | ||
ALBUMS | ||
} | ||
|
||
export const ArtistContentSection = () => { | ||
const [filterText, setFilterText] = useState('') | ||
const [selectedPill, setSelectedPill] = useState(Pills.TRACKS) | ||
const [selectedTrackFilter, setSelectedTrackFilter] = | ||
useState<Nullable<TrackFilters>>(null) | ||
const [selectedAlbumFilter, setSelectedAlbumFilter] = | ||
useState<Nullable<AlbumFilters>>(null) | ||
const isTracks = selectedPill === Pills.TRACKS | ||
const tracks = useFormattedTrackData() | ||
const albums = useFormattedAlbumData() | ||
|
||
const { | ||
filterButtonOptions: filterButtonTrackOptions, | ||
hasOnlyOneSection: hasOnlyOneTrackSection | ||
} = useArtistDashboardTrackFilters() | ||
const { | ||
filterButtonOptions: filterButtonAlbumOptions, | ||
hasOnlyOneSection: hasOnlyOneAlbumSection | ||
} = useArtistDashboardAlbumFilters() | ||
|
||
const filterButtonOptions = isTracks | ||
? filterButtonTrackOptions | ||
: filterButtonAlbumOptions | ||
const shouldShowFilterButton = | ||
(isTracks && !hasOnlyOneTrackSection) || | ||
(!isTracks && !hasOnlyOneAlbumSection) | ||
const shouldShowPills = tracks.length && albums.length | ||
|
||
const onClickPill = useCallback( | ||
(pill: Pills) => { | ||
setSelectedPill(pill) | ||
setFilterText('') | ||
|
||
// Reset filter button state when switching content types | ||
if (!isTracks && pill === Pills.TRACKS) { | ||
setSelectedAlbumFilter(null) | ||
} else if (isTracks && pill === Pills.ALBUMS) { | ||
setSelectedTrackFilter(null) | ||
} | ||
}, | ||
[isTracks] | ||
) | ||
|
||
const handleSelectFilter = (value: string) => { | ||
if (isTracks) { | ||
setSelectedTrackFilter(value as TrackFilters) | ||
} else { | ||
setSelectedAlbumFilter(value as AlbumFilters) | ||
} | ||
} | ||
|
||
const handleFilterChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const val = e.target.value | ||
setFilterText(val) | ||
} | ||
|
||
if (!tracks.length && !albums.length) return null | ||
|
||
return ( | ||
<Paper w='100%' direction='column' mt='xl'> | ||
<Flex ph='2xl' pv='l' justifyContent='space-between'> | ||
<Flex gap='2xl'> | ||
{shouldShowPills ? ( | ||
<Flex gap='s'> | ||
<SelectablePill | ||
isSelected={selectedPill === Pills.TRACKS} | ||
label={messages.tracks} | ||
size='large' | ||
onClick={() => onClickPill(Pills.TRACKS)} | ||
/> | ||
<SelectablePill | ||
isSelected={selectedPill === Pills.ALBUMS} | ||
label={messages.albums} | ||
size='large' | ||
onClick={() => onClickPill(Pills.ALBUMS)} | ||
/> | ||
</Flex> | ||
) : null} | ||
{ | ||
// Only show filter button if there are multiple sections for the selected content type | ||
shouldShowFilterButton ? ( | ||
<FilterButton | ||
onSelect={handleSelectFilter} | ||
selection={isTracks ? selectedTrackFilter : selectedAlbumFilter} | ||
label={messages.allReleases} | ||
options={filterButtonOptions} | ||
popupAnchorOrigin={{ vertical: 'bottom', horizontal: 'left' }} | ||
popupTransformOrigin={{ vertical: 'top', horizontal: 'left' }} | ||
/> | ||
) : null | ||
} | ||
</Flex> | ||
<Flex> | ||
<TextInput | ||
placeholder={messages.search(selectedPill)} | ||
label={messages.search(selectedPill)} | ||
value={filterText} | ||
onChange={handleFilterChange} | ||
size={TextInputSize.SMALL} | ||
startIcon={IconSearch} | ||
/> | ||
</Flex> | ||
</Flex> | ||
{selectedPill === Pills.TRACKS ? ( | ||
<ArtistDashboardTracksTab | ||
selectedFilter={selectedTrackFilter} | ||
filterText={filterText} | ||
/> | ||
) : ( | ||
<ArtistDashboardAlbumsTab | ||
selectedFilter={selectedAlbumFilter} | ||
filterText={filterText} | ||
/> | ||
)} | ||
</Paper> | ||
) | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/web/src/pages/dashboard-page/components/ArtistDashboardAlbumsTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useCallback } from 'react' | ||
|
||
import { Nullable } from '@audius/common/utils' | ||
import { Paper } from '@audius/harmony' | ||
import { useSelector } from 'react-redux' | ||
|
||
import { TracksTable, TracksTableColumn } from 'components/tracks-table' | ||
import { useGoToRoute } from 'hooks/useGoToRoute' | ||
|
||
import { makeGetDashboard } from '../store/selectors' | ||
|
||
import { SHOW_MORE_LIMIT, TABLE_PAGE_SIZE } from './constants' | ||
import { useFilteredAlbumData } from './hooks' | ||
import { AlbumFilters } from './types' | ||
|
||
const albumTableColumns: TracksTableColumn[] = [ | ||
'spacer', | ||
'trackName', | ||
'releaseDate', | ||
'reposts', | ||
'overflowMenu' | ||
] | ||
|
||
type ArtistDashboardAlbumsTabProps = { | ||
selectedFilter: Nullable<AlbumFilters> | ||
filterText: string | ||
} | ||
|
||
export const ArtistDashboardAlbumsTab = ({ | ||
selectedFilter, | ||
filterText | ||
}: ArtistDashboardAlbumsTabProps) => { | ||
const goToRoute = useGoToRoute() | ||
const { account } = useSelector(makeGetDashboard()) | ||
const filteredData = useFilteredAlbumData({ | ||
selectedFilter, | ||
filterText | ||
}) | ||
|
||
const onClickRow = useCallback( | ||
(collection: any) => { | ||
if (!account) return | ||
goToRoute(collection.permalink) | ||
}, | ||
[account, goToRoute] | ||
) | ||
|
||
if (!filteredData.length || !account) return null | ||
|
||
return ( | ||
<Paper w='100%' direction='column' mt='xl'> | ||
<TracksTable | ||
data={filteredData} | ||
disabledTrackEdit | ||
columns={albumTableColumns} | ||
onClickRow={onClickRow} | ||
pageSize={TABLE_PAGE_SIZE} | ||
userId={account.user_id} | ||
showMoreLimit={SHOW_MORE_LIMIT} | ||
totalRowCount={account.track_count} | ||
/> | ||
</Paper> | ||
) | ||
} |
Oops, something went wrong.