mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 02:13:33 +00:00
feat: Add explicit status for Navidrome and OpenSubsonic (#1220)
* add navidrome explicit status * add ExplicitStatus enum and support opensubsonic * add explicit status to cards
This commit is contained in:
parent
68f242d208
commit
4dd52b0cef
16 changed files with 131 additions and 10 deletions
|
|
@ -34,6 +34,7 @@ const ALBUM_LIST_SORT_MAPPING: Record<AlbumListSort, AlbumListSortType | undefin
|
|||
[AlbumListSort.COMMUNITY_RATING]: undefined,
|
||||
[AlbumListSort.CRITIC_RATING]: undefined,
|
||||
[AlbumListSort.DURATION]: undefined,
|
||||
[AlbumListSort.EXPLICIT_STATUS]: undefined,
|
||||
[AlbumListSort.FAVORITED]: AlbumListSortType.STARRED,
|
||||
[AlbumListSort.NAME]: AlbumListSortType.ALPHABETICAL_BY_NAME,
|
||||
[AlbumListSort.PLAY_COUNT]: AlbumListSortType.FREQUENT,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import clsx from 'clsx';
|
||||
import formatDuration from 'format-duration';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { generatePath } from 'react-router';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
|
|
@ -9,7 +10,14 @@ import styles from './card-rows.module.css';
|
|||
import { AppRoute } from '/@/renderer/router/routes';
|
||||
import { formatDateAbsolute, formatDateRelative, formatRating } from '/@/renderer/utils/format';
|
||||
import { Text } from '/@/shared/components/text/text';
|
||||
import { Album, AlbumArtist, Artist, Playlist, Song } from '/@/shared/types/domain-types';
|
||||
import {
|
||||
Album,
|
||||
AlbumArtist,
|
||||
Artist,
|
||||
ExplicitStatus,
|
||||
Playlist,
|
||||
Song,
|
||||
} from '/@/shared/types/domain-types';
|
||||
import { CardRow } from '/@/shared/types/types';
|
||||
|
||||
interface CardRowsProps {
|
||||
|
|
@ -18,6 +26,8 @@ interface CardRowsProps {
|
|||
}
|
||||
|
||||
export const CardRows = ({ data, rows }: CardRowsProps) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
{rows.map((row, index: number) => {
|
||||
|
|
@ -66,7 +76,7 @@ export const CardRows = ({ data, rows }: CardRowsProps) => {
|
|||
>
|
||||
{row.arrayProperty &&
|
||||
(row.format
|
||||
? row.format(item)
|
||||
? row.format(item, t)
|
||||
: item[row.arrayProperty])}
|
||||
</Text>
|
||||
</React.Fragment>
|
||||
|
|
@ -92,7 +102,9 @@ export const CardRows = ({ data, rows }: CardRowsProps) => {
|
|||
size={index > 0 ? 'sm' : 'md'}
|
||||
>
|
||||
{row.arrayProperty &&
|
||||
(row.format ? row.format(item) : item[row.arrayProperty])}
|
||||
(row.format
|
||||
? row.format(item, t)
|
||||
: item[row.arrayProperty])}
|
||||
</Text>
|
||||
))}
|
||||
</div>
|
||||
|
|
@ -123,7 +135,7 @@ export const CardRows = ({ data, rows }: CardRowsProps) => {
|
|||
}, {}),
|
||||
)}
|
||||
>
|
||||
{data && (row.format ? row.format(data) : data[row.property])}
|
||||
{data && (row.format ? row.format(data, t) : data[row.property])}
|
||||
</Text>
|
||||
) : (
|
||||
<Text
|
||||
|
|
@ -132,7 +144,7 @@ export const CardRows = ({ data, rows }: CardRowsProps) => {
|
|||
overflow="hidden"
|
||||
size={index > 0 ? 'sm' : 'md'}
|
||||
>
|
||||
{data && (row.format ? row.format(data) : data[row.property])}
|
||||
{data && (row.format ? row.format(data, t) : data[row.property])}
|
||||
</Text>
|
||||
)}
|
||||
</div>
|
||||
|
|
@ -167,6 +179,15 @@ export const ALBUM_CARD_ROWS: { [key: string]: CardRow<Album> } = {
|
|||
format: (album) => (album.duration === null ? null : formatDuration(album.duration)),
|
||||
property: 'duration',
|
||||
},
|
||||
explicitStatus: {
|
||||
format: (album, t) =>
|
||||
album.explicitStatus === ExplicitStatus.EXPLICIT
|
||||
? t('common.explicit', { postProcess: 'sentenceCase' })
|
||||
: album.explicitStatus === ExplicitStatus.CLEAN
|
||||
? t('common.clean', { postProcess: 'sentenceCase' })
|
||||
: null,
|
||||
property: 'explicitStatus',
|
||||
},
|
||||
lastPlayedAt: {
|
||||
format: (album) => formatDateRelative(album.lastPlayedAt),
|
||||
property: 'lastPlayedAt',
|
||||
|
|
@ -228,6 +249,15 @@ export const SONG_CARD_ROWS: { [key: string]: CardRow<Song> } = {
|
|||
format: (song) => (song.duration === null ? null : formatDuration(song.duration)),
|
||||
property: 'duration',
|
||||
},
|
||||
explicitStatus: {
|
||||
format: (song, t) =>
|
||||
song.explicitStatus === ExplicitStatus.EXPLICIT
|
||||
? t('common.explicit', { postProcess: 'sentenceCase' })
|
||||
: song.explicitStatus === ExplicitStatus.CLEAN
|
||||
? t('common.clean', { postProcess: 'sentenceCase' })
|
||||
: null,
|
||||
property: 'explicitStatus',
|
||||
},
|
||||
lastPlayedAt: {
|
||||
format: (song) => formatDateRelative(song.lastPlayedAt),
|
||||
property: 'lastPlayedAt',
|
||||
|
|
|
|||
|
|
@ -58,6 +58,10 @@ export const AlbumListGridView = ({ gridRef, itemCount }: any) => {
|
|||
rows.push(ALBUM_CARD_ROWS.albumArtists);
|
||||
rows.push(ALBUM_CARD_ROWS.duration);
|
||||
break;
|
||||
case AlbumListSort.EXPLICIT_STATUS:
|
||||
rows.push(ALBUM_CARD_ROWS.albumArtists);
|
||||
rows.push(ALBUM_CARD_ROWS.explicitStatus);
|
||||
break;
|
||||
case AlbumListSort.FAVORITED:
|
||||
rows.push(ALBUM_CARD_ROWS.albumArtists);
|
||||
rows.push(ALBUM_CARD_ROWS.releaseYear);
|
||||
|
|
|
|||
|
|
@ -102,6 +102,11 @@ const FILTERS = {
|
|||
name: i18n.t('filter.duration', { postProcess: 'titleCase' }),
|
||||
value: AlbumListSort.DURATION,
|
||||
},
|
||||
{
|
||||
defaultOrder: SortOrder.DESC,
|
||||
name: i18n.t('filter.explicitStatus', { postProcess: 'titleCase' }),
|
||||
value: AlbumListSort.EXPLICIT_STATUS,
|
||||
},
|
||||
{
|
||||
defaultOrder: SortOrder.DESC,
|
||||
name: i18n.t('filter.mostPlayed', { postProcess: 'titleCase' }),
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { Separator } from '/@/shared/components/separator/separator';
|
|||
import { Spoiler } from '/@/shared/components/spoiler/spoiler';
|
||||
import { Table } from '/@/shared/components/table/table';
|
||||
import { Text } from '/@/shared/components/text/text';
|
||||
import { ExplicitStatus } from '/@/shared/types/domain-types';
|
||||
import {
|
||||
Album,
|
||||
AlbumArtist,
|
||||
|
|
@ -34,14 +35,14 @@ type ItemDetailRow<T> = {
|
|||
key?: keyof T;
|
||||
label: string;
|
||||
postprocess?: string[];
|
||||
render?: (item: T) => ReactNode;
|
||||
render?: (item: T, t: TFunction) => ReactNode;
|
||||
};
|
||||
|
||||
const handleRow = <T extends AnyLibraryItem>(t: TFunction, item: T, rule: ItemDetailRow<T>) => {
|
||||
let value: ReactNode;
|
||||
|
||||
if (rule.render) {
|
||||
value = rule.render(item);
|
||||
value = rule.render(item, t);
|
||||
} else {
|
||||
const prop = item[rule.key!];
|
||||
value = prop !== undefined && prop !== null ? String(prop) : null;
|
||||
|
|
@ -128,6 +129,15 @@ const AlbumPropertyMapping: ItemDetailRow<Album>[] = [
|
|||
},
|
||||
{ key: 'releaseYear', label: 'filter.releaseYear' },
|
||||
{ key: 'songCount', label: 'filter.songCount' },
|
||||
{
|
||||
label: 'filter.explicitStatus',
|
||||
render: (album, t) =>
|
||||
album.explicitStatus === ExplicitStatus.EXPLICIT
|
||||
? t('common.explicit', { postProcess: 'sentenceCase' })
|
||||
: album.explicitStatus === ExplicitStatus.CLEAN
|
||||
? t('common.clean', { postProcess: 'sentenceCase' })
|
||||
: null,
|
||||
},
|
||||
{ label: 'filter.isCompilation', render: (album) => BoolField(album.isCompilation || false) },
|
||||
{
|
||||
key: 'size',
|
||||
|
|
@ -266,6 +276,15 @@ const SongPropertyMapping: ItemDetailRow<Song>[] = [
|
|||
{ key: 'discNumber', label: 'common.disc' },
|
||||
{ key: 'trackNumber', label: 'common.trackNumber' },
|
||||
{ key: 'releaseYear', label: 'filter.releaseYear' },
|
||||
{
|
||||
label: 'filter.explicitStatus',
|
||||
render: (song, t) =>
|
||||
song.explicitStatus === ExplicitStatus.EXPLICIT
|
||||
? t('common.explicit', { postProcess: 'sentenceCase' })
|
||||
: song.explicitStatus === ExplicitStatus.CLEAN
|
||||
? t('common.clean', { postProcess: 'sentenceCase' })
|
||||
: null,
|
||||
},
|
||||
{ label: 'entity.genre_other', render: FormatGenre },
|
||||
{
|
||||
label: 'common.duration',
|
||||
|
|
|
|||
|
|
@ -85,6 +85,9 @@ export const SongListGridView = ({ gridRef, itemCount }: SongListGridViewProps)
|
|||
case SongListSort.DURATION:
|
||||
rows.push(SONG_CARD_ROWS.duration);
|
||||
break;
|
||||
case SongListSort.EXPLICIT_STATUS:
|
||||
rows.push(SONG_CARD_ROWS.explicitStatus);
|
||||
break;
|
||||
case SongListSort.FAVORITED:
|
||||
break;
|
||||
case SongListSort.NAME:
|
||||
|
|
|
|||
|
|
@ -133,6 +133,11 @@ const FILTERS = {
|
|||
name: i18n.t('filter.duration', { postProcess: 'titleCase' }),
|
||||
value: SongListSort.DURATION,
|
||||
},
|
||||
{
|
||||
defaultOrder: SortOrder.DESC,
|
||||
name: i18n.t('filter.explicitStatus', { postProcess: 'titleCase' }),
|
||||
value: SongListSort.EXPLICIT_STATUS,
|
||||
},
|
||||
{
|
||||
defaultOrder: SortOrder.DESC,
|
||||
name: i18n.t('filter.isFavorited', { postProcess: 'titleCase' }),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue