mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-19 01:44:00 +02:00
Add album detail list view (#1681)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
|
||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||
|
||||
export const ActionsColumn = ({ controls, internalState, song }: ItemDetailListCellProps) => {
|
||||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
const index = internalState?.findItemIndex(song.id) ?? -1;
|
||||
controls?.onMore?.({
|
||||
event,
|
||||
index,
|
||||
internalState: internalState ?? undefined,
|
||||
item: song,
|
||||
itemType: LibraryItem.SONG,
|
||||
});
|
||||
};
|
||||
|
||||
const handleDoubleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
return (
|
||||
<ActionIcon
|
||||
icon="ellipsisHorizontal"
|
||||
iconProps={{
|
||||
color: 'muted',
|
||||
size: 'xs',
|
||||
}}
|
||||
onClick={handleClick}
|
||||
onDoubleClick={handleDoubleClick}
|
||||
size="xs"
|
||||
variant="subtle"
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import {
|
||||
JOINED_ARTISTS_MUTED_PROPS,
|
||||
JoinedArtists,
|
||||
} from '/@/renderer/features/albums/components/joined-artists';
|
||||
|
||||
export const AlbumArtistColumn = ({ isRowHovered, song }: ItemDetailListCellProps) => {
|
||||
const name = song.albumArtistName?.trim() ?? '';
|
||||
const hasArtists = name.length > 0 || (song.albumArtists?.length ?? 0) > 0;
|
||||
|
||||
if (!hasArtists) return <> </>;
|
||||
|
||||
return (
|
||||
<JoinedArtists
|
||||
artistName={song.albumArtistName ?? ''}
|
||||
artists={song.albumArtists ?? []}
|
||||
linkProps={JOINED_ARTISTS_MUTED_PROPS.linkProps}
|
||||
readOnly={!isRowHovered}
|
||||
rootTextProps={JOINED_ARTISTS_MUTED_PROPS.rootTextProps}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const AlbumColumn = ({ song }: ItemDetailListCellProps) => song.album ?? <> </>;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import {
|
||||
JOINED_ARTISTS_MUTED_PROPS,
|
||||
JoinedArtists,
|
||||
} from '/@/renderer/features/albums/components/joined-artists';
|
||||
|
||||
export const ArtistColumn = ({ isRowHovered, song }: ItemDetailListCellProps) => {
|
||||
const name = song.artistName?.trim() ?? '';
|
||||
const hasArtists = name.length > 0 || (song.artists?.length ?? 0) > 0;
|
||||
|
||||
if (!hasArtists) return <> </>;
|
||||
|
||||
return (
|
||||
<JoinedArtists
|
||||
artistName={song.artistName ?? ''}
|
||||
artists={song.artists ?? []}
|
||||
linkProps={JOINED_ARTISTS_MUTED_PROPS.linkProps}
|
||||
readOnly={!isRowHovered}
|
||||
rootTextProps={JOINED_ARTISTS_MUTED_PROPS.rootTextProps}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const BitDepthColumn = ({ song }: ItemDetailListCellProps) => song.bitDepth;
|
||||
@@ -0,0 +1,4 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const BitRateColumn = ({ song }: ItemDetailListCellProps) =>
|
||||
song.bitRate != null ? `${song.bitRate} kbps` : <> </>;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const BpmColumn = ({ song }: ItemDetailListCellProps) => song.bpm ?? <> </>;
|
||||
@@ -0,0 +1,4 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const ChannelsColumn = ({ song }: ItemDetailListCellProps) =>
|
||||
song.channels != null ? String(song.channels) : <> </>;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const CodecColumn = ({ song }: ItemDetailListCellProps) => song.container ?? <> </>;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const CommentColumn = ({ song }: ItemDetailListCellProps) => song.comment ?? <> </>;
|
||||
@@ -0,0 +1,7 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const ComposerColumn = ({ song }: ItemDetailListCellProps) => {
|
||||
const composers = song.participants?.composer;
|
||||
if (!composers?.length) return <> </>;
|
||||
return composers.map((a) => a.name).join(', ');
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { formatDateAbsolute } from '/@/renderer/utils/format';
|
||||
|
||||
export const DateAddedColumn = ({ song }: ItemDetailListCellProps) =>
|
||||
song.createdAt ? formatDateAbsolute(song.createdAt) : <> </>;
|
||||
@@ -0,0 +1,11 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
interface DefaultColumnProps extends ItemDetailListCellProps {
|
||||
columnId: string;
|
||||
}
|
||||
|
||||
export const DefaultColumn = ({ columnId, song }: DefaultColumnProps) => {
|
||||
const raw = (song as Record<string, unknown>)[columnId];
|
||||
if (raw === undefined || raw === null || typeof raw === 'object') return <> </>;
|
||||
return String(raw);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const DiscNumberColumn = ({ song }: ItemDetailListCellProps) => String(song.discNumber ?? 1);
|
||||
@@ -0,0 +1,5 @@
|
||||
import formatDuration from 'format-duration';
|
||||
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const DurationColumn = ({ song }: ItemDetailListCellProps) => formatDuration(song.duration);
|
||||
@@ -0,0 +1,54 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { useIsMutatingCreateFavorite } from '/@/renderer/features/shared/mutations/create-favorite-mutation';
|
||||
import { useIsMutatingDeleteFavorite } from '/@/renderer/features/shared/mutations/delete-favorite-mutation';
|
||||
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
|
||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||
|
||||
export const FavoriteColumn = ({
|
||||
controls,
|
||||
internalState,
|
||||
isMutatingFavorite,
|
||||
onFavoriteClick,
|
||||
song,
|
||||
}: ItemDetailListCellProps) => {
|
||||
const isMutatingCreateFavorite = useIsMutatingCreateFavorite();
|
||||
const isMutatingDeleteFavorite = useIsMutatingDeleteFavorite();
|
||||
const isMutating = isMutatingFavorite ?? (isMutatingCreateFavorite || isMutatingDeleteFavorite);
|
||||
const isFavorite = song.userFavorite ?? false;
|
||||
|
||||
return (
|
||||
<ActionIcon
|
||||
disabled={isMutating}
|
||||
icon="favorite"
|
||||
iconProps={{
|
||||
color: isFavorite ? 'primary' : 'muted',
|
||||
fill: isFavorite ? 'primary' : undefined,
|
||||
size: 'xs',
|
||||
}}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
const index = internalState?.findItemIndex(song.id) ?? -1;
|
||||
if (controls?.onFavorite) {
|
||||
controls.onFavorite({
|
||||
event,
|
||||
favorite: !isFavorite,
|
||||
index,
|
||||
internalState: internalState ?? undefined,
|
||||
item: song,
|
||||
itemType: LibraryItem.SONG,
|
||||
});
|
||||
} else {
|
||||
onFavoriteClick?.(song);
|
||||
}
|
||||
}}
|
||||
onDoubleClick={(event) => {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}}
|
||||
size="xs"
|
||||
variant="subtle"
|
||||
/>
|
||||
);
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.group {
|
||||
flex-wrap: nowrap;
|
||||
gap: var(--theme-spacing-sm) var(--theme-spacing-xs);
|
||||
min-width: 0;
|
||||
padding: var(--theme-spacing-xs) 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.group a {
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useMemo } from 'react';
|
||||
import { generatePath, Link } from 'react-router';
|
||||
|
||||
import styles from './genre-badge-column.module.css';
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { AppRoute } from '/@/renderer/router/routes';
|
||||
import { Badge } from '/@/shared/components/badge/badge';
|
||||
import { Group } from '/@/shared/components/group/group';
|
||||
import { stringToColor } from '/@/shared/utils/string-to-color';
|
||||
|
||||
const MAX_GENRES = 4;
|
||||
|
||||
export const GenreBadgeColumn = ({ song }: ItemDetailListCellProps) => {
|
||||
const genres = song.genres;
|
||||
|
||||
const genresWithStyle = useMemo(() => {
|
||||
if (!genres) return [];
|
||||
return genres.slice(0, MAX_GENRES).map((genre) => {
|
||||
const { color, isLight } = stringToColor(genre.name);
|
||||
const path = generatePath(AppRoute.LIBRARY_GENRES_DETAIL, { genreId: genre.id });
|
||||
return { ...genre, color, isLight, path };
|
||||
});
|
||||
}, [genres]);
|
||||
|
||||
if (!genresWithStyle.length) return <> </>;
|
||||
|
||||
return (
|
||||
<Group className={styles.group} wrap="nowrap">
|
||||
{genresWithStyle.map((genre) => (
|
||||
<Badge
|
||||
component={Link}
|
||||
key={genre.id}
|
||||
state={{ item: genre }}
|
||||
style={{
|
||||
backgroundColor: genre.color,
|
||||
color: genre.isLight ? 'black' : 'white',
|
||||
}}
|
||||
to={genre.path}
|
||||
>
|
||||
{genre.name}
|
||||
</Badge>
|
||||
))}
|
||||
</Group>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Fragment } from 'react';
|
||||
import { generatePath, Link } from 'react-router';
|
||||
|
||||
import { ItemDetailListCellProps } from '/@/renderer/components/item-list/item-detail-list/columns/types';
|
||||
import { AppRoute } from '/@/renderer/router/routes';
|
||||
import { Text } from '/@/shared/components/text/text';
|
||||
|
||||
const TEXT_PROPS = { isMuted: true, isNoSelect: true, size: 'sm' as const } as const;
|
||||
|
||||
export const GenreColumn = ({ isRowHovered, song }: ItemDetailListCellProps) => {
|
||||
const genres = song.genres ?? [];
|
||||
if (!genres.length) return <> </>;
|
||||
|
||||
return (
|
||||
<>
|
||||
{genres.map((genre, index) => (
|
||||
<Fragment key={genre.id}>
|
||||
{isRowHovered ? (
|
||||
<Text
|
||||
component={Link}
|
||||
isLink
|
||||
state={{ item: genre }}
|
||||
to={generatePath(AppRoute.LIBRARY_GENRES_DETAIL, {
|
||||
genreId: genre.id,
|
||||
})}
|
||||
{...TEXT_PROPS}
|
||||
>
|
||||
{genre.name}
|
||||
</Text>
|
||||
) : (
|
||||
<Text component="span" {...TEXT_PROPS}>
|
||||
{genre.name}
|
||||
</Text>
|
||||
)}
|
||||
{index < genres.length - 1 && ', '}
|
||||
</Fragment>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
.image-container {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.compact-container {
|
||||
flex: 1 1 0;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
max-height: 100%;
|
||||
aspect-ratio: unset;
|
||||
padding-top: var(--theme-spacing-xs);
|
||||
padding-bottom: var(--theme-spacing-xs);
|
||||
overflow: hidden;
|
||||
border-radius: var(--theme-radius-md);
|
||||
}
|
||||
|
||||
.play-button-overlay {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
z-index: 10;
|
||||
opacity: 0.6;
|
||||
transform: translate(-50%, -50%);
|
||||
transition: opacity 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
.play-button-overlay:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.play-button-overlay button {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
.compact-image {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
object-position: center;
|
||||
border-radius: var(--theme-radius-md);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import clsx from 'clsx';
|
||||
import { useState } from 'react';
|
||||
|
||||
import styles from './image-column.module.css';
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { ItemImage } from '/@/renderer/components/item-image/item-image';
|
||||
import { PlayButton } from '/@/renderer/features/shared/components/play-button';
|
||||
import {
|
||||
LONG_PRESS_PLAY_BEHAVIOR,
|
||||
PlayTooltip,
|
||||
} from '/@/renderer/features/shared/components/play-button-group';
|
||||
import { usePlayButtonBehavior } from '/@/renderer/store';
|
||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||
import { Play } from '/@/shared/types/types';
|
||||
|
||||
export const ImageColumn = ({
|
||||
controls,
|
||||
internalState,
|
||||
rowIndex = 0,
|
||||
song,
|
||||
}: ItemDetailListCellProps) => {
|
||||
const playButtonBehavior = usePlayButtonBehavior();
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
||||
const handlePlay = (playType: Play) => {
|
||||
if (!song || !controls?.onDoubleClick) {
|
||||
return;
|
||||
}
|
||||
|
||||
controls.onDoubleClick({
|
||||
event: null,
|
||||
index: rowIndex,
|
||||
internalState,
|
||||
item: song,
|
||||
itemType: LibraryItem.SONG,
|
||||
meta: { playType, singleSongOnly: true },
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={styles.imageContainer}
|
||||
onMouseEnter={() => setIsHovered(true)}
|
||||
onMouseLeave={() => setIsHovered(false)}
|
||||
>
|
||||
<ItemImage
|
||||
className={styles.compactImage}
|
||||
containerClassName={styles.compactContainer}
|
||||
explicitStatus={song.explicitStatus}
|
||||
id={song.imageId}
|
||||
itemType={LibraryItem.SONG}
|
||||
serverId={song._serverId}
|
||||
type="table"
|
||||
/>
|
||||
{isHovered && (
|
||||
<div className={clsx(styles.playButtonOverlay)}>
|
||||
<PlayTooltip disabled={false} type={playButtonBehavior}>
|
||||
<PlayButton
|
||||
fill
|
||||
onClick={() => handlePlay(playButtonBehavior)}
|
||||
onLongPress={() =>
|
||||
handlePlay(LONG_PRESS_PLAY_BEHAVIOR[playButtonBehavior])
|
||||
}
|
||||
/>
|
||||
</PlayTooltip>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,127 @@
|
||||
import React, { type ReactNode } from 'react';
|
||||
|
||||
import type { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { ActionsColumn } from './actions-column';
|
||||
import { AlbumArtistColumn } from './album-artist-column';
|
||||
import { AlbumColumn } from './album-column';
|
||||
import { ArtistColumn } from './artist-column';
|
||||
import { BitDepthColumn } from './bit-depth-column';
|
||||
import { BitRateColumn } from './bit-rate-column';
|
||||
import { BpmColumn } from './bpm-column';
|
||||
import { ChannelsColumn } from './channels-column';
|
||||
import { CodecColumn } from './codec-column';
|
||||
import { CommentColumn } from './comment-column';
|
||||
import { ComposerColumn } from './composer-column';
|
||||
import { DateAddedColumn } from './date-added-column';
|
||||
import { DefaultColumn } from './default-column';
|
||||
import { DiscNumberColumn } from './disc-number-column';
|
||||
import { DurationColumn } from './duration-column';
|
||||
import { FavoriteColumn } from './favorite-column';
|
||||
import { GenreBadgeColumn } from './genre-badge-column';
|
||||
import { GenreColumn } from './genre-column';
|
||||
import { ImageColumn } from './image-column';
|
||||
import { LastPlayedColumn } from './last-played-column';
|
||||
import { PathColumn } from './path-column';
|
||||
import { PlayCountColumn } from './play-count-column';
|
||||
import { RatingColumn } from './rating-column';
|
||||
import { ReleaseDateColumn } from './release-date-column';
|
||||
import { RowIndexColumn } from './row-index-column';
|
||||
import { SampleRateColumn } from './sample-rate-column';
|
||||
import { SizeColumn } from './size-column';
|
||||
import { TitleArtistColumn } from './title-artist-column';
|
||||
import { TitleColumn } from './title-column';
|
||||
import { TitleCombinedColumn } from './title-combined-column';
|
||||
import { TrackNumberColumn } from './track-number-column';
|
||||
import { YearColumn } from './year-column';
|
||||
|
||||
import { TableColumn } from '/@/shared/types/types';
|
||||
|
||||
type CellComponent = (props: ItemDetailListCellProps) => ReactNode;
|
||||
|
||||
const COLUMN_MAP: Partial<Record<TableColumn, CellComponent>> = {
|
||||
[TableColumn.ACTIONS]: ActionsColumn,
|
||||
[TableColumn.ALBUM]: AlbumColumn,
|
||||
[TableColumn.ALBUM_ARTIST]: AlbumArtistColumn,
|
||||
[TableColumn.ARTIST]: ArtistColumn,
|
||||
[TableColumn.BIT_DEPTH]: BitDepthColumn,
|
||||
[TableColumn.BIT_RATE]: BitRateColumn,
|
||||
[TableColumn.BPM]: BpmColumn,
|
||||
[TableColumn.CHANNELS]: ChannelsColumn,
|
||||
[TableColumn.CODEC]: CodecColumn,
|
||||
[TableColumn.COMMENT]: CommentColumn,
|
||||
[TableColumn.COMPOSER]: ComposerColumn,
|
||||
[TableColumn.DATE_ADDED]: DateAddedColumn,
|
||||
[TableColumn.DISC_NUMBER]: DiscNumberColumn,
|
||||
[TableColumn.DURATION]: DurationColumn,
|
||||
[TableColumn.GENRE]: GenreColumn,
|
||||
[TableColumn.GENRE_BADGE]: GenreBadgeColumn,
|
||||
[TableColumn.IMAGE]: ImageColumn,
|
||||
[TableColumn.LAST_PLAYED]: LastPlayedColumn,
|
||||
[TableColumn.PATH]: PathColumn,
|
||||
[TableColumn.PLAY_COUNT]: PlayCountColumn,
|
||||
[TableColumn.RELEASE_DATE]: ReleaseDateColumn,
|
||||
[TableColumn.ROW_INDEX]: RowIndexColumn,
|
||||
[TableColumn.SAMPLE_RATE]: SampleRateColumn,
|
||||
[TableColumn.SIZE]: SizeColumn,
|
||||
[TableColumn.TITLE]: TitleColumn,
|
||||
[TableColumn.TITLE_ARTIST]: TitleArtistColumn,
|
||||
[TableColumn.TITLE_COMBINED]: TitleCombinedColumn,
|
||||
[TableColumn.TRACK_NUMBER]: TrackNumberColumn,
|
||||
[TableColumn.USER_FAVORITE]: FavoriteColumn,
|
||||
[TableColumn.USER_RATING]: RatingColumn,
|
||||
[TableColumn.YEAR]: YearColumn,
|
||||
};
|
||||
|
||||
export type DetailListCellComponentProps = ItemDetailListCellProps & { columnId?: string };
|
||||
|
||||
export function getDetailListCellComponent(
|
||||
columnId: string | TableColumn,
|
||||
): (props: DetailListCellComponentProps) => ReactNode {
|
||||
const Component = COLUMN_MAP[columnId as TableColumn];
|
||||
if (Component) {
|
||||
return Component as (props: DetailListCellComponentProps) => ReactNode;
|
||||
}
|
||||
return (props: DetailListCellComponentProps) =>
|
||||
React.createElement(DefaultColumn, {
|
||||
columnId: props.columnId ?? (columnId as string),
|
||||
song: props.song,
|
||||
});
|
||||
}
|
||||
|
||||
export type { ItemDetailListCellProps } from './types';
|
||||
|
||||
export {
|
||||
ActionsColumn,
|
||||
AlbumArtistColumn,
|
||||
AlbumColumn,
|
||||
ArtistColumn,
|
||||
BitDepthColumn,
|
||||
BitRateColumn,
|
||||
BpmColumn,
|
||||
ChannelsColumn,
|
||||
CodecColumn,
|
||||
CommentColumn,
|
||||
ComposerColumn,
|
||||
DateAddedColumn,
|
||||
DefaultColumn,
|
||||
DiscNumberColumn,
|
||||
DurationColumn,
|
||||
FavoriteColumn,
|
||||
GenreBadgeColumn,
|
||||
GenreColumn,
|
||||
ImageColumn,
|
||||
LastPlayedColumn,
|
||||
PathColumn,
|
||||
PlayCountColumn,
|
||||
RatingColumn,
|
||||
ReleaseDateColumn,
|
||||
RowIndexColumn,
|
||||
SampleRateColumn,
|
||||
SizeColumn,
|
||||
TitleArtistColumn,
|
||||
TitleColumn,
|
||||
TitleCombinedColumn,
|
||||
TrackNumberColumn,
|
||||
YearColumn,
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { formatDateRelative } from '/@/renderer/utils/format';
|
||||
|
||||
export const LastPlayedColumn = ({ song }: ItemDetailListCellProps) =>
|
||||
song.lastPlayedAt ? formatDateRelative(song.lastPlayedAt) : <> </>;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const PathColumn = ({ song }: ItemDetailListCellProps) => song.path ?? <> </>;
|
||||
@@ -0,0 +1,4 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const PlayCountColumn = ({ song }: ItemDetailListCellProps) =>
|
||||
song.playCount ? String(song.playCount) : <> </>;
|
||||
@@ -0,0 +1,29 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { useIsMutatingRating } from '/@/renderer/features/shared/mutations/set-rating-mutation';
|
||||
import { Rating } from '/@/shared/components/rating/rating';
|
||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||
|
||||
export const RatingColumn = ({ controls, internalState, song }: ItemDetailListCellProps) => {
|
||||
const isMutatingRating = useIsMutatingRating();
|
||||
const value = song.userRating ?? 0;
|
||||
|
||||
return (
|
||||
<Rating
|
||||
onChange={(rating) => {
|
||||
const index = internalState?.findItemIndex(song.id) ?? -1;
|
||||
controls?.onRating?.({
|
||||
event: null,
|
||||
index,
|
||||
internalState: internalState ?? undefined,
|
||||
item: song,
|
||||
itemType: LibraryItem.SONG,
|
||||
rating,
|
||||
});
|
||||
}}
|
||||
readOnly={isMutatingRating}
|
||||
size="xs"
|
||||
value={value}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { formatDateAbsoluteUTC } from '/@/renderer/utils/format';
|
||||
|
||||
export const ReleaseDateColumn = ({ song }: ItemDetailListCellProps) =>
|
||||
song.releaseDate ? formatDateAbsoluteUTC(song.releaseDate) : <> </>;
|
||||
@@ -0,0 +1,5 @@
|
||||
.icon-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import styles from './row-index-column.module.css';
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { useIsCurrentSong } from '/@/renderer/features/player/hooks/use-is-current-song';
|
||||
import { usePlayerStatus } from '/@/renderer/store';
|
||||
import { Icon } from '/@/shared/components/icon/icon';
|
||||
import { PlayerStatus } from '/@/shared/types/types';
|
||||
|
||||
export const RowIndexColumn = ({ rowIndex, song }: ItemDetailListCellProps) => {
|
||||
const status = usePlayerStatus();
|
||||
const { isActive } = useIsCurrentSong(song);
|
||||
const isPlaying = isActive && status === PlayerStatus.PLAYING;
|
||||
|
||||
if (isActive) {
|
||||
return (
|
||||
<div className={styles.iconWrapper}>
|
||||
<Icon fill="primary" icon={isPlaying ? 'mediaPlay' : 'mediaPause'} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <>{String((rowIndex ?? 0) + 1)}</>;
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const SampleRateColumn = ({ song }: ItemDetailListCellProps) =>
|
||||
song.sampleRate ? `${song.sampleRate} Hz` : <> </>;
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
import { formatSizeString } from '/@/renderer/utils/format';
|
||||
|
||||
export const SizeColumn = ({ song }: ItemDetailListCellProps) =>
|
||||
song.size ? formatSizeString(song.size) : <> </>;
|
||||
@@ -0,0 +1,18 @@
|
||||
import clsx from 'clsx';
|
||||
|
||||
import styles from './title-column.module.css';
|
||||
|
||||
import { ItemDetailListCellProps } from '/@/renderer/components/item-list/item-detail-list/columns/types';
|
||||
import { useIsCurrentSong } from '/@/renderer/features/player/hooks/use-is-current-song';
|
||||
import { ExplicitIndicator } from '/@/shared/components/explicit-indicator/explicit-indicator';
|
||||
|
||||
export const TitleArtistColumn = ({ song }: ItemDetailListCellProps) => {
|
||||
const { isActive } = useIsCurrentSong(song);
|
||||
|
||||
return (
|
||||
<span className={clsx({ [styles.active]: isActive })}>
|
||||
<ExplicitIndicator explicitStatus={song.explicitStatus} />
|
||||
{[song.name, song.artistName].filter(Boolean).join(' — ') ?? <> </>}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
.active {
|
||||
color: var(--theme-colors-primary);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import clsx from 'clsx';
|
||||
|
||||
import styles from './title-column.module.css';
|
||||
|
||||
import { ItemDetailListCellProps } from '/@/renderer/components/item-list/item-detail-list/columns/types';
|
||||
import { useIsCurrentSong } from '/@/renderer/features/player/hooks/use-is-current-song';
|
||||
import { ExplicitIndicator } from '/@/shared/components/explicit-indicator/explicit-indicator';
|
||||
|
||||
export const TitleColumn = ({ song }: ItemDetailListCellProps) => {
|
||||
const { isActive } = useIsCurrentSong(song);
|
||||
|
||||
return (
|
||||
<span className={clsx({ [styles.active]: isActive })}>
|
||||
<ExplicitIndicator explicitStatus={song.explicitStatus} />
|
||||
{song.name ?? <> </>}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import clsx from 'clsx';
|
||||
|
||||
import styles from './title-column.module.css';
|
||||
|
||||
import { ItemDetailListCellProps } from '/@/renderer/components/item-list/item-detail-list/columns/types';
|
||||
import { useIsCurrentSong } from '/@/renderer/features/player/hooks/use-is-current-song';
|
||||
import { ExplicitIndicator } from '/@/shared/components/explicit-indicator/explicit-indicator';
|
||||
|
||||
export const TitleCombinedColumn = ({ song }: ItemDetailListCellProps) => {
|
||||
const { isActive } = useIsCurrentSong(song);
|
||||
|
||||
return (
|
||||
<span className={clsx({ [styles.active]: isActive })}>
|
||||
<ExplicitIndicator explicitStatus={song.explicitStatus} />
|
||||
{[song.name, song.artistName].filter(Boolean).join(' — ') ?? <> </>}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const TrackNumberColumn = ({ song }: ItemDetailListCellProps) => {
|
||||
const disc = song.discNumber ?? 1;
|
||||
const track = song.trackNumber.toString().padStart(2, '0');
|
||||
return `${disc}-${track}`;
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
import { ItemListStateActions } from '/@/renderer/components/item-list/helpers/item-list-state';
|
||||
import { ItemControls } from '/@/renderer/components/item-list/types';
|
||||
import { Song } from '/@/shared/types/domain-types';
|
||||
|
||||
export interface ItemDetailListCellProps {
|
||||
controls?: ItemControls;
|
||||
internalState?: ItemListStateActions;
|
||||
isMutatingFavorite?: boolean;
|
||||
isRowHovered?: boolean;
|
||||
onFavoriteClick?: (song: Song) => void;
|
||||
rowIndex?: number;
|
||||
size?: 'compact' | 'default' | 'large';
|
||||
song: Song;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { ItemDetailListCellProps } from './types';
|
||||
|
||||
export const YearColumn = ({ song }: ItemDetailListCellProps) =>
|
||||
song.releaseYear ? String(song.releaseYear) : <> </>;
|
||||
Reference in New Issue
Block a user