@@ -6,7 +6,7 @@ import { Book } from '@/types/book';
|
||||
import { BookMetadata } from '@/libs/document';
|
||||
import { useEnv } from '@/context/EnvContext';
|
||||
import { useTranslation } from '@/hooks/useTranslation';
|
||||
import { formatAuthors, formatTitle } from '@/utils/book';
|
||||
import { flattenContributors, formatAuthors, formatPublisher, formatTitle } from '@/utils/book';
|
||||
import { FormField } from './FormField';
|
||||
import { IMAGE_ACCEPT_FORMATS, SUPPORTED_IMAGE_EXTS } from '@/services/constants';
|
||||
import { isTauriAppPlatform } from '@/services/environment';
|
||||
@@ -107,7 +107,7 @@ const BookDetailEdit: React.FC<BookDetailEditProps> = ({
|
||||
{
|
||||
field: 'publisher',
|
||||
label: _('Publisher'),
|
||||
value: metadata.publisher || '',
|
||||
value: formatPublisher(metadata.publisher || ''),
|
||||
placeholder: _('Enter publisher'),
|
||||
},
|
||||
{
|
||||
@@ -135,7 +135,7 @@ const BookDetailEdit: React.FC<BookDetailEditProps> = ({
|
||||
{
|
||||
field: 'subject',
|
||||
label: _('Subjects'),
|
||||
value: Array.isArray(metadata.subject) ? metadata.subject.join(',') : metadata.subject || '',
|
||||
value: flattenContributors(metadata.subject || []),
|
||||
placeholder: _('Fiction, Science, History'),
|
||||
},
|
||||
{
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
formatFileSize,
|
||||
formatLanguage,
|
||||
formatPublisher,
|
||||
formatSubject,
|
||||
formatTitle,
|
||||
} from '@/utils/book';
|
||||
import BookCover from '@/components/BookCover';
|
||||
@@ -120,7 +119,7 @@ const BookDetailView: React.FC<BookDetailViewProps> = ({
|
||||
<div className='overflow-hidden'>
|
||||
<span className='font-bold'>{_('Subjects')}</span>
|
||||
<p className='text-neutral-content line-clamp-3 text-sm'>
|
||||
{formatSubject(metadata.subject) || _('Unknown')}
|
||||
{formatAuthors(metadata.subject || '') || _('Unknown')}
|
||||
</p>
|
||||
</div>
|
||||
<div className='overflow-hidden'>
|
||||
|
||||
@@ -68,7 +68,7 @@ export type BookMetadata = {
|
||||
publisher?: string;
|
||||
published?: string;
|
||||
description?: string;
|
||||
subject?: string[];
|
||||
subject?: string | string[] | Contributor;
|
||||
identifier?: string;
|
||||
|
||||
subtitle?: string;
|
||||
|
||||
@@ -89,8 +89,23 @@ export const getBookLangCode = (lang: string | string[] | undefined) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const flattenContributors = (
|
||||
contributors: string | string[] | Contributor | Contributor[],
|
||||
) => {
|
||||
if (!contributors) return '';
|
||||
return Array.isArray(contributors)
|
||||
? contributors
|
||||
.map((contributor) =>
|
||||
typeof contributor === 'string' ? contributor : formatLanguageMap(contributor?.name),
|
||||
)
|
||||
.join(', ')
|
||||
: typeof contributors === 'string'
|
||||
? contributors
|
||||
: formatLanguageMap(contributors?.name);
|
||||
};
|
||||
|
||||
export const formatAuthors = (
|
||||
contributors: string | Contributor | [string | Contributor],
|
||||
contributors: string | string[] | Contributor | Contributor[],
|
||||
bookLang?: string | string[],
|
||||
) => {
|
||||
const langCode = getBookLangCode(bookLang) || 'en';
|
||||
@@ -141,11 +156,6 @@ export const formatDate = (date: string | number | Date | null | undefined, isUT
|
||||
}
|
||||
};
|
||||
|
||||
export const formatSubject = (subject: string | string[] | undefined) => {
|
||||
if (!subject) return '';
|
||||
return Array.isArray(subject) ? subject.join(', ') : subject;
|
||||
};
|
||||
|
||||
export const formatFileSize = (size: number | null) => {
|
||||
if (size === null) return '';
|
||||
const formatter = new Intl.NumberFormat('en', {
|
||||
|
||||
Reference in New Issue
Block a user