Ability to change the list of files at any time, including through UI (#115)
* Now can update the list of files without pausing/unpausing * Shrink a few functions * Reopen write when updating files * Todos * opened_file abstraction * iter_pieces_within iterator * Simplify iter_pieces_within * Simplify iter_pieces_within * Add "iter_file_details" * temporarily broken: readonly by default * Live torrent - reopen files * Reopen files after changing the list * Now reopening files read only when they are completed * Fix a bug in opened_file.rs * update todos * update help * Reconnect all peers that are idling * Add a couple fields to OpenedFile * Add a couple fields to OpenedFile * Small cleanups - use the new iterator where possible * size_of_piece_in_file function * Updating have * Include file progress * Almost nothing * ugly progress bars * bad UI, saving * its not so bad * Works now * update progress bar a bit * Reopen read-only on pause * Zero bytes isnt too bad! Doesnt break anything * fix per file progress bars * progress bar not as ugly anymore? * ui tweaks * fix a react bug * TODO.md update * Fix js + TODOs * Compute per-file progress on init * Fix stats updating live * Nothing * Nothing * cleanup ui a bit * Nothing * Final fixes * Trying to fix rust 1.73 * Sorting filenames * remove unnecessary indentation * Remove unnecessary comment
This commit is contained in:
parent
d7380217f6
commit
5eb01ac226
31 changed files with 865 additions and 512 deletions
|
|
@ -105,6 +105,7 @@ export const FileSelectionModal = (props: {
|
|||
selectedFiles={selectedFiles}
|
||||
setSelectedFiles={setSelectedFiles}
|
||||
torrentDetails={listTorrentResponse.details}
|
||||
torrentStats={null}
|
||||
/>
|
||||
</Fieldset>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
import React, { useContext, useState } from "react";
|
||||
import {
|
||||
AddTorrentResponse,
|
||||
ErrorDetails,
|
||||
TorrentDetails,
|
||||
} from "../../api-types";
|
||||
import { FileListInput } from "../FileListInput";
|
||||
import { Modal } from "./Modal";
|
||||
import { ModalBody } from "./ModalBody";
|
||||
import { ModalFooter } from "./ModalFooter";
|
||||
import { Button } from "../buttons/Button";
|
||||
import { Spinner } from "../Spinner";
|
||||
import { APIContext, RefreshTorrentStatsContext } from "../../context";
|
||||
import { ErrorComponent } from "../ErrorComponent";
|
||||
import { ErrorWithLabel } from "../../stores/errorStore";
|
||||
|
||||
export const TorrentSettingsModal: React.FC<{
|
||||
id: number;
|
||||
show: boolean;
|
||||
onHide: () => void;
|
||||
details: TorrentDetails;
|
||||
}> = ({ id, show, onHide, details }) => {
|
||||
let initialSelectedFiles = new Set<number>();
|
||||
|
||||
let refreshCtx = useContext(RefreshTorrentStatsContext);
|
||||
|
||||
details.files.forEach((f, i) => {
|
||||
if (f.included) {
|
||||
initialSelectedFiles.add(i);
|
||||
}
|
||||
});
|
||||
|
||||
const API = useContext(APIContext);
|
||||
|
||||
const [selectedFiles, setSelectedFiles] =
|
||||
useState<Set<number>>(initialSelectedFiles);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<ErrorWithLabel | null>(null);
|
||||
|
||||
const close = () => {
|
||||
setSelectedFiles(initialSelectedFiles);
|
||||
onHide();
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
setSaving(true);
|
||||
API.updateOnlyFiles(id, Array.from(selectedFiles)).then(
|
||||
() => {
|
||||
setSaving(false);
|
||||
refreshCtx.refresh();
|
||||
close();
|
||||
setError(null);
|
||||
},
|
||||
(e) => {
|
||||
setSaving(false);
|
||||
setError({
|
||||
text: "Error configuring torrent",
|
||||
details: e as ErrorDetails,
|
||||
});
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal isOpen={show} onClose={close} title="Configure torrent">
|
||||
<ModalBody>
|
||||
<ErrorComponent error={error}></ErrorComponent>
|
||||
<FileListInput
|
||||
torrentDetails={details}
|
||||
selectedFiles={selectedFiles}
|
||||
setSelectedFiles={setSelectedFiles}
|
||||
/>
|
||||
</ModalBody>
|
||||
|
||||
<ModalFooter>
|
||||
{saving && <Spinner />}
|
||||
<Button onClick={close} variant="cancel">
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSave}
|
||||
variant="primary"
|
||||
disabled={saving || selectedFiles.size == 0}
|
||||
>
|
||||
OK
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue