forked from nukeop/nuclear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace simple list view with a track table
- Loading branch information
Showing
4 changed files
with
37 additions
and
118 deletions.
There are no files selected for viewing
124 changes: 13 additions & 111 deletions
124
packages/app/app/components/LibraryView/LibrarySimpleList/index.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 |
---|---|---|
@@ -1,116 +1,18 @@ | ||
import React from 'react'; | ||
import _ from 'lodash'; | ||
import ReactList from 'react-list'; | ||
import PropTypes from 'prop-types'; | ||
import cx from 'classnames'; | ||
import { | ||
Icon, | ||
Ref, | ||
Table | ||
} from 'semantic-ui-react'; | ||
import { compose } from 'recompose'; | ||
import { withTranslation } from 'react-i18next'; | ||
import { ContextPopup, TrackRow, getThumbnail } from '@nuclear/ui'; | ||
import { Track } from '@nuclear/core'; | ||
|
||
import TrackPopupButtons from '../../../containers/TrackPopupButtons'; | ||
import styles from './styles.scss'; | ||
import TrackTableContainer from '../../../containers/TrackTableContainer'; | ||
|
||
const LibrarySimpleList = ({ | ||
tracks, | ||
sortBy, | ||
direction, | ||
handleSort, | ||
t | ||
}) => ( | ||
<ReactList | ||
ref={comp => { | ||
if (comp) { | ||
// enables css styling of the container element | ||
comp.el.className = styles.library_simple_list_container; | ||
} | ||
}} | ||
type='uniform' | ||
useStaticSize | ||
length={tracks.length} | ||
itemsRenderer={(items, ref) => ( | ||
<Table | ||
sortable | ||
className={cx( | ||
styles.library_simple_list, | ||
styles.table | ||
)} | ||
> | ||
<Table.Header className={styles.thead}> | ||
<Table.Row> | ||
<Table.HeaderCell> | ||
<Icon name='image' /> | ||
</Table.HeaderCell> | ||
<Table.HeaderCell | ||
sorted={sortBy === 'artist' ? direction : null} | ||
onClick={handleSort('artist')} | ||
> | ||
{t('artist')} | ||
</Table.HeaderCell> | ||
<Table.HeaderCell | ||
sorted={sortBy === 'name' ? direction : null} | ||
onClick={handleSort('name')} | ||
> | ||
{t('title')} | ||
</Table.HeaderCell> | ||
<Table.HeaderCell | ||
sorted={sortBy === 'album' ? direction : null} | ||
onClick={handleSort('album')} | ||
> | ||
{t('album')} | ||
</Table.HeaderCell> | ||
</Table.Row> | ||
</Table.Header> | ||
<Ref innerRef={ref}> | ||
<Table.Body className={styles.tbody}> | ||
{items} | ||
</Table.Body> | ||
</Ref> | ||
</Table> | ||
)} | ||
itemRenderer={index => { | ||
const track = _.get(tracks, index); | ||
const title = track?.name; | ||
const artist = _.isString(track?.artist) ? track?.artist : track?.artist?.name; | ||
type LibrarySimpleListProps = { | ||
tracks: Track[]; | ||
} | ||
|
||
return ( | ||
<ContextPopup | ||
trigger={ | ||
<TrackRow | ||
key={'library-track-' + index} | ||
track={track} | ||
displayCover | ||
displayArtist | ||
displayAlbum | ||
withAddToDownloads={false} | ||
/> | ||
} | ||
key={'library-track-' + index} | ||
thumb={getThumbnail(track)} | ||
title={title} | ||
artist={artist} | ||
> | ||
<TrackPopupButtons | ||
track={track} | ||
withAddToDownloads={false} | ||
/> | ||
</ContextPopup> | ||
); | ||
}} | ||
/> | ||
); | ||
const LibrarySimpleList: React.FC<LibrarySimpleListProps> = ({ | ||
tracks | ||
}) => <TrackTableContainer | ||
tracks={tracks} | ||
displayDeleteButton={false} | ||
displayFavorite={false} | ||
/>; | ||
|
||
LibrarySimpleList.propTypes = { | ||
tracks: PropTypes.array, | ||
sortBy: PropTypes.string, | ||
direction: PropTypes.string, | ||
handleSort: PropTypes.func | ||
}; | ||
|
||
export default compose( | ||
withTranslation('library') | ||
)(LibrarySimpleList); | ||
export default LibrarySimpleList; |
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