Add bulk poster filling endpoint and enhance show deletion options
Introduced a new endpoint for bulk filling collection posters, allowing for automatic assignment of posters to collections without existing images. Updated the DeleteShowCommand to include an option for cutting shows from future airings, enhancing the deletion process. Refactored related components and API calls to support these features, ensuring a seamless user experience. Additionally, updated localization strings to reflect the new functionalities and adjusted tests to verify correct behavior.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { Image as ImageIcon } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { imageUrl } from '@/features/admin/images/api'
|
||||
@@ -7,9 +8,10 @@ import { qk } from '@/shared/api/query-keys'
|
||||
import { useApiError } from '@/shared/lib/use-api-error'
|
||||
import { Button } from '@/shared/ui/button'
|
||||
import { Input } from '@/shared/ui/input'
|
||||
import { toast } from '@/shared/ui/toast-store'
|
||||
import { sortRows, useTableSort } from '@/shared/lib/table-sort'
|
||||
import { SortHeader } from '@/shared/ui/sortable'
|
||||
import { createCollection, deleteCollection, listCollections } from './api'
|
||||
import { createCollection, deleteCollection, fillCollectionPosters, listCollections } from './api'
|
||||
import { CollectionSuggestions } from './CollectionSuggestions'
|
||||
|
||||
export function CollectionsPanel() {
|
||||
@@ -39,6 +41,14 @@ export function CollectionsPanel() {
|
||||
onSuccess: invalidate,
|
||||
onError,
|
||||
})
|
||||
const postersMutation = useMutation({
|
||||
mutationFn: () => fillCollectionPosters(),
|
||||
onSuccess: (filled) => {
|
||||
toast.success(t('admin.collections.postersDone', { count: filled }))
|
||||
invalidate()
|
||||
},
|
||||
onError,
|
||||
})
|
||||
|
||||
const rows = sortRows(data ?? [], sort, {
|
||||
name: (c) => c.name.toLowerCase(),
|
||||
@@ -67,6 +77,19 @@ export function CollectionsPanel() {
|
||||
>
|
||||
{t('common.create')}
|
||||
</Button>
|
||||
|
||||
{/* Постер коллекции — обложка её первой части: своей картинки у франшизы нет, а без
|
||||
обложки она теряется в списке одинаковых строк. */}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={postersMutation.isPending}
|
||||
onClick={() => postersMutation.mutate()}
|
||||
title={t('admin.collections.postersHint')}
|
||||
>
|
||||
<ImageIcon className="h-4 w-4" />
|
||||
{t('admin.collections.posters')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<CollectionSuggestions />
|
||||
|
||||
@@ -39,6 +39,17 @@ export function addShowsToCollection(body: {
|
||||
}
|
||||
|
||||
/** Какие франшизы имеет смысл собрать из уже загруженных полнометражек. */
|
||||
/**
|
||||
* Проставляет постеры по частям коллекций. Без списка — всем, у кого постера ещё нет: после
|
||||
* массового импорта фильмов франшиз сразу десятки. Возвращает, скольким постер нашёлся.
|
||||
*/
|
||||
export function fillCollectionPosters(collectionIds?: string[]) {
|
||||
return apiRequest<number>('/admin/collections/bulk/posters', {
|
||||
method: 'POST',
|
||||
body: { collectionIds: collectionIds ?? null },
|
||||
})
|
||||
}
|
||||
|
||||
export function suggestCollections() {
|
||||
return apiRequest<CollectionSuggestionDto[]>('/admin/collections/suggestions')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user