import React from 'react'; import { generatePath } from 'react-router'; import { Link } from 'react-router-dom'; import styled from 'styled-components'; import { Album, AlbumArtist, Artist } from '/@/renderer/api/types'; import { Text } from '/@/renderer/components/text'; import { AppRoute } from '/@/renderer/router/routes'; import { CardRow } from '/@/renderer/types'; const Row = styled.div<{ $secondary?: boolean }>` width: 100%; max-width: 100%; height: 22px; padding: 0 0.2rem; overflow: hidden; color: ${({ $secondary }) => ($secondary ? 'var(--main-fg-secondary)' : 'var(--main-fg)')}; white-space: nowrap; text-overflow: ellipsis; user-select: none; `; interface CardRowsProps { data: any; rows: CardRow[]; } export const CardRows = ({ data, rows }: CardRowsProps) => { return ( <> {rows.map((row, index: number) => { if (row.arrayProperty && row.route) { return ( 0} > {data[row.property].map((item: any, itemIndex: number) => ( {itemIndex > 0 && ( , )}{' '} 0} component={Link} overflow="hidden" size={index > 0 ? 'sm' : 'md'} to={generatePath( row.route!.route, row.route!.slugs?.reduce((acc, slug) => { return { ...acc, [slug.slugProperty]: data[slug.idProperty], }; }, {}), )} onClick={(e) => e.stopPropagation()} > {row.arrayProperty && item[row.arrayProperty]} ))} ); } if (row.arrayProperty) { return ( {data[row.property].map((item: any) => ( 0} overflow="hidden" size={index > 0 ? 'sm' : 'md'} > {row.arrayProperty && item[row.arrayProperty]} ))} ); } return ( {row.route ? ( { return { ...acc, [slug.slugProperty]: data[slug.idProperty], }; }, {}), )} onClick={(e) => e.stopPropagation()} > {data && data[row.property]} ) : ( 0} overflow="hidden" size={index > 0 ? 'sm' : 'md'} > {data && data[row.property]} )} ); })} ); }; export const ALBUM_CARD_ROWS: { [key: string]: CardRow } = { albumArtists: { arrayProperty: 'name', property: 'albumArtists', route: { route: AppRoute.LIBRARY_ALBUMARTISTS_DETAIL, slugs: [{ idProperty: 'id', slugProperty: 'albumArtistId' }], }, }, artists: { arrayProperty: 'name', property: 'artists', route: { route: AppRoute.LIBRARY_ALBUMARTISTS_DETAIL, slugs: [{ idProperty: 'id', slugProperty: 'albumArtistId' }], }, }, createdAt: { property: 'createdAt', }, duration: { property: 'duration', }, lastPlayedAt: { property: 'lastPlayedAt', }, name: { property: 'name', route: { route: AppRoute.LIBRARY_ALBUMS_DETAIL, slugs: [{ idProperty: 'id', slugProperty: 'albumId' }], }, }, playCount: { property: 'playCount', }, rating: { property: 'rating', }, releaseDate: { property: 'releaseDate', }, releaseYear: { property: 'releaseYear', }, songCount: { property: 'songCount', }, };