-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quick select option to release management (#900)
- Loading branch information
1 parent
699afd6
commit e9f19f8
Showing
7 changed files
with
178 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/components/Utilities/ReleaseManagement/QuickSelectModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import React, { useEffect } from 'react'; | ||
import { map, toNumber } from 'lodash'; | ||
import { useImmer } from 'use-immer'; | ||
|
||
import Button from '@/components/Input/Button'; | ||
import Checkbox from '@/components/Input/Checkbox'; | ||
import ModalPanel from '@/components/Panels/ModalPanel'; | ||
import toast from '@/components/Toast'; | ||
import { useDeleteFilesMutation } from '@/core/react-query/file/mutations'; | ||
import { useSeriesFileSummaryQuery } from '@/core/react-query/webui/queries'; | ||
import useEventCallback from '@/hooks/useEventCallback'; | ||
|
||
type Props = { | ||
show: boolean; | ||
onClose: () => void; | ||
seriesId: number; | ||
}; | ||
|
||
const QuickSelectModal = ({ onClose, seriesId, show }: Props) => { | ||
const fileSummaryQuery = useSeriesFileSummaryQuery( | ||
seriesId, | ||
{ | ||
groupBy: 'GroupName,FileSource,VideoResolution,AudioLanguages,SubtitleLanguages', | ||
includeEpisodeDetails: true, | ||
}, | ||
show, | ||
); | ||
const fileSummary = fileSummaryQuery.data; | ||
|
||
const { isPending: isDeleting, mutate: deleteFiles } = useDeleteFilesMutation(); | ||
|
||
const [groupsToDelete, setGroupsToDelete] = useImmer<Set<number>>(new Set()); | ||
|
||
useEffect(() => { | ||
setGroupsToDelete(new Set()); | ||
}, [setGroupsToDelete, show]); | ||
|
||
const handleCheckboxChange = useEventCallback((event: React.ChangeEvent<HTMLInputElement>) => { | ||
const index = toNumber(event.target.id.split('-')[1]); | ||
setGroupsToDelete((state) => { | ||
if (event.target.checked) state.add(index); | ||
else state.delete(index); | ||
}); | ||
}); | ||
|
||
const handleSave = useEventCallback(() => { | ||
const fileIds = map( | ||
[...groupsToDelete], | ||
groupIndex => | ||
map( | ||
fileSummary?.Groups[groupIndex].Episodes, | ||
episode => episode.FileID, | ||
), | ||
).flat(); | ||
|
||
deleteFiles( | ||
{ fileIds, removeFolder: true }, | ||
{ | ||
onSuccess: () => { | ||
toast.success(`${fileIds.length} ${fileIds.length === 1 ? 'file' : 'files'} deleted!`); | ||
onClose(); | ||
}, | ||
onError: () => toast.error('Files could not be deleted!'), | ||
}, | ||
); | ||
}); | ||
|
||
return ( | ||
<ModalPanel show={show} onRequestClose={onClose} header="Quick Select" size="sm"> | ||
{fileSummaryQuery.isSuccess && ( | ||
map( | ||
fileSummary?.Groups, | ||
(group, index) => ( | ||
<div key={`group-${index}`} className="flex items-center justify-between gap-x-3"> | ||
<div className="flex flex-col gap-y-2"> | ||
<div className="font-semibold">{group.GroupName}</div> | ||
<div className="flex opacity-65"> | ||
{group.FileSource} | ||
| | ||
{group.VideoResolution} | ||
{group.AudioLanguages && ( | ||
<> | ||
| | ||
<div> | ||
{group.AudioLanguages.length > 1 ? 'Multi ' : 'Single '} | ||
Audio ( | ||
{group.AudioLanguages.join(', ')} | ||
) | ||
</div> | ||
</> | ||
)} | ||
{group.SubtitleLanguages && ( | ||
<> | ||
| | ||
<div> | ||
{group.SubtitleLanguages.length ? 'Multi ' : 'Single '} | ||
Subs ( | ||
{group.SubtitleLanguages.join(', ')} | ||
) | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
</div> | ||
<Checkbox | ||
id={`checkbox-${index}`} | ||
isChecked={groupsToDelete.has(index)} | ||
onChange={handleCheckboxChange} | ||
label="Delete" | ||
/> | ||
</div> | ||
), | ||
) | ||
)} | ||
|
||
<div className="mt-4 flex justify-end gap-x-3 font-semibold"> | ||
<Button onClick={onClose} buttonType="secondary" className="px-6 py-2">Cancel</Button> | ||
<Button | ||
onClick={handleSave} | ||
buttonType="primary" | ||
className="px-6 py-2" | ||
loading={isDeleting} | ||
> | ||
Save | ||
</Button> | ||
</div> | ||
</ModalPanel> | ||
); | ||
}; | ||
|
||
export default QuickSelectModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters