Refactor ManualInboxDialog to improve show detection logic and user selection handling
ci / build-backend (push) Successful in 2m51s
ci / build-frontend (push) Successful in 1m17s
ci / tests (push) Successful in 2m23s
ci / sonar (push) Successful in 6m14s

Updated the logic for detecting shows based on user-selected files in the ManualInboxDialog component. The changes ensure that the detection process considers only the selected files, enhancing accuracy. Additionally, modified the useEffect to streamline the handling of show ID updates, improving the overall user experience when selecting shows.
This commit is contained in:
Leonid Pershin
2026-07-27 20:51:50 +03:00
parent e55161f8f9
commit ee0b4d2d01
@@ -157,19 +157,23 @@ export function ManualInboxDialog({ onClose }: Readonly<{ onClose: () => void }>
/** /**
* Автоопределение шоу по имени релиза — то же, что в загрузке в шоу. Сначала пробуем имя файла, * Автоопределение шоу по имени релиза — то же, что в загрузке в шоу. Сначала пробуем имя файла,
* затем имя папки: в раздачах название сериала обычно есть и там, и там («Mr.Pickles.S01.1080p»). * затем имя папки: в раздачах название сериала обычно есть и там, и там («Mr.Pickles.S01.1080p»).
*
* Смотрим только на отмеченное: в manual/ лежат раздачи сразу нескольких шоу, и определять по
* первому файлу списка значило бы подставлять то, что человек даже не выбирал. Ищем в полном
* списке, а не в отфильтрованном: отметки переживают поиск по названию.
*/ */
const detectedShowId = useMemo( const detectedShowId = useMemo(() => {
() => const first = (data?.files ?? []).find((file) => selected.includes(file.relativePath))
shows && sample if (!shows || !first) return undefined
? (matchShowByName(sample.name, shows) ?? matchShowByName(sample.folder, shows)) return matchShowByName(first.name, shows) ?? matchShowByName(first.folder, shows)
: undefined, }, [shows, data, selected])
[shows, sample],
)
// Без условия на пустой showId: отметили файлы другого шоу — подстановка следует за выбором.
// Ручной выбор она по-прежнему не трогает.
useEffect(() => { useEffect(() => {
if (showPicked || showId || !detectedShowId) return if (showPicked || !detectedShowId) return
setShowId(detectedShowId) setShowId(detectedShowId)
}, [detectedShowId, showPicked, showId]) }, [detectedShowId, showPicked])
const autoDetected = !showPicked && !!detectedShowId && showId === detectedShowId const autoDetected = !showPicked && !!detectedShowId && showId === detectedShowId