Refactor ManualInboxDialog to improve show detection logic and user selection handling
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:
@@ -157,19 +157,23 @@ export function ManualInboxDialog({ onClose }: Readonly<{ onClose: () => void }>
|
||||
/**
|
||||
* Автоопределение шоу по имени релиза — то же, что в загрузке в шоу. Сначала пробуем имя файла,
|
||||
* затем имя папки: в раздачах название сериала обычно есть и там, и там («Mr.Pickles.S01.1080p»).
|
||||
*
|
||||
* Смотрим только на отмеченное: в manual/ лежат раздачи сразу нескольких шоу, и определять по
|
||||
* первому файлу списка значило бы подставлять то, что человек даже не выбирал. Ищем в полном
|
||||
* списке, а не в отфильтрованном: отметки переживают поиск по названию.
|
||||
*/
|
||||
const detectedShowId = useMemo(
|
||||
() =>
|
||||
shows && sample
|
||||
? (matchShowByName(sample.name, shows) ?? matchShowByName(sample.folder, shows))
|
||||
: undefined,
|
||||
[shows, sample],
|
||||
)
|
||||
const detectedShowId = useMemo(() => {
|
||||
const first = (data?.files ?? []).find((file) => selected.includes(file.relativePath))
|
||||
if (!shows || !first) return undefined
|
||||
return matchShowByName(first.name, shows) ?? matchShowByName(first.folder, shows)
|
||||
}, [shows, data, selected])
|
||||
|
||||
// Без условия на пустой showId: отметили файлы другого шоу — подстановка следует за выбором.
|
||||
// Ручной выбор она по-прежнему не трогает.
|
||||
useEffect(() => {
|
||||
if (showPicked || showId || !detectedShowId) return
|
||||
if (showPicked || !detectedShowId) return
|
||||
setShowId(detectedShowId)
|
||||
}, [detectedShowId, showPicked, showId])
|
||||
}, [detectedShowId, showPicked])
|
||||
|
||||
const autoDetected = !showPicked && !!detectedShowId && showId === detectedShowId
|
||||
|
||||
|
||||
Reference in New Issue
Block a user