Rewrite all styles to tailwind CSS from Bootstrap by @arccik (#58)
* add tailwindcss * add header component with logo and add torrent buttons * remove bootstrap from few files replace it with tailwindcss classes, add card which diplay all nessesarry information about torrent and current state * Add modal component and reorganize components folder * add useModal hook to render modal though react portal, remove UrlPromptModal and replace it with useModal. * add taliwindcss to Desctop app * removed bootstrap from deleteTorrentModal replace it with useModal * replacing bootstrap with useModal * saving * Saving * Header and cards now look good * Modals still broken... * still doesnt work * Finally it scrolls * Continuing to fix bugs * Continuing to fix bugs * Aler * Getting better * Desktop doesnt work with tailwind somehow * Desktop now works with tailwind * Styles fully work * (De)select all buttons * fix alert styles * Animate progress bar * Progress bar + error colors * Fix error message * Torrent status icon (#56) * add statusIcon component to display icon of the torrent status * change props name and remove isDownloading variable * Tweak styles for icon * Tweak styles * Update styles --------- Co-authored-by: Artur Lozovski <arccik@gmail.com>
This commit is contained in:
parent
911bf3a0d5
commit
50fc7f2f01
62 changed files with 7454 additions and 1776 deletions
|
|
@ -1,165 +0,0 @@
|
|||
import { useContext, useEffect, useState } from "react";
|
||||
import { Button, Modal, Form, Spinner } from "react-bootstrap";
|
||||
import { AddTorrentResponse, AddTorrentOptions } from "../api-types";
|
||||
import { AppContext, APIContext } from "../context";
|
||||
import { ErrorComponent } from "./ErrorComponent";
|
||||
import { formatBytes } from "../helper/formatBytes";
|
||||
import { ErrorWithLabel } from "../rqbit-web";
|
||||
|
||||
export const FileSelectionModal = (props: {
|
||||
onHide: () => void;
|
||||
listTorrentResponse: AddTorrentResponse | null;
|
||||
listTorrentError: ErrorWithLabel | null;
|
||||
listTorrentLoading: boolean;
|
||||
data: string | File;
|
||||
}) => {
|
||||
let {
|
||||
onHide,
|
||||
listTorrentResponse,
|
||||
listTorrentError,
|
||||
listTorrentLoading,
|
||||
data,
|
||||
} = props;
|
||||
|
||||
const [selectedFiles, setSelectedFiles] = useState<number[]>([]);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [uploadError, setUploadError] = useState<ErrorWithLabel | null>(null);
|
||||
const [unpopularTorrent, setUnpopularTorrent] = useState(false);
|
||||
const [outputFolder, setOutputFolder] = useState<string>("");
|
||||
const ctx = useContext(AppContext);
|
||||
const API = useContext(APIContext);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(listTorrentResponse);
|
||||
setSelectedFiles(
|
||||
listTorrentResponse
|
||||
? listTorrentResponse.details.files.map((_, id) => id)
|
||||
: []
|
||||
);
|
||||
setOutputFolder(listTorrentResponse?.output_folder || "");
|
||||
}, [listTorrentResponse]);
|
||||
|
||||
const clear = () => {
|
||||
onHide();
|
||||
setSelectedFiles([]);
|
||||
setUploadError(null);
|
||||
setUploading(false);
|
||||
};
|
||||
|
||||
const handleToggleFile = (toggledId: number) => {
|
||||
if (selectedFiles.includes(toggledId)) {
|
||||
setSelectedFiles(selectedFiles.filter((i) => i !== toggledId));
|
||||
} else {
|
||||
setSelectedFiles([...selectedFiles, toggledId]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpload = async () => {
|
||||
if (!listTorrentResponse) {
|
||||
return;
|
||||
}
|
||||
setUploading(true);
|
||||
let initialPeers = listTorrentResponse.seen_peers
|
||||
? listTorrentResponse.seen_peers.slice(0, 32)
|
||||
: null;
|
||||
let opts: AddTorrentOptions = {
|
||||
overwrite: true,
|
||||
only_files: selectedFiles,
|
||||
initial_peers: initialPeers,
|
||||
output_folder: outputFolder,
|
||||
};
|
||||
if (unpopularTorrent) {
|
||||
opts.peer_opts = {
|
||||
connect_timeout: 20,
|
||||
read_write_timeout: 60,
|
||||
};
|
||||
}
|
||||
API.uploadTorrent(data, opts)
|
||||
.then(
|
||||
() => {
|
||||
onHide();
|
||||
ctx.refreshTorrents();
|
||||
},
|
||||
(e) => {
|
||||
setUploadError({ text: "Error starting torrent", details: e });
|
||||
}
|
||||
)
|
||||
.finally(() => setUploading(false));
|
||||
};
|
||||
|
||||
const getBody = () => {
|
||||
if (listTorrentLoading) {
|
||||
return <Spinner />;
|
||||
} else if (listTorrentError) {
|
||||
return <ErrorComponent error={listTorrentError}></ErrorComponent>;
|
||||
} else if (listTorrentResponse) {
|
||||
return (
|
||||
<Form>
|
||||
<fieldset className="mb-4">
|
||||
<legend>Pick the files to download</legend>
|
||||
{listTorrentResponse.details.files.map((file, index) => (
|
||||
<Form.Group key={index} controlId={`check-${index}`}>
|
||||
<Form.Check
|
||||
type="checkbox"
|
||||
label={`${file.name} (${formatBytes(file.length)})`}
|
||||
checked={selectedFiles.includes(index)}
|
||||
onChange={() => handleToggleFile(index)}
|
||||
></Form.Check>
|
||||
</Form.Group>
|
||||
))}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Options</legend>
|
||||
<Form.Group controlId="output-folder" className="mb-3">
|
||||
<Form.Label>Output folder</Form.Label>
|
||||
<Form.Control
|
||||
type="text"
|
||||
value={outputFolder}
|
||||
onChange={(e) => setOutputFolder(e.target.value)}
|
||||
/>
|
||||
</Form.Group>
|
||||
<Form.Group controlId="unpopular-torrent" className="mb-3">
|
||||
<Form.Check
|
||||
type="checkbox"
|
||||
label="Increase timeouts"
|
||||
checked={unpopularTorrent}
|
||||
onChange={() => setUnpopularTorrent(!unpopularTorrent)}
|
||||
></Form.Check>
|
||||
<small id="emailHelp" className="form-text text-muted">
|
||||
This might be useful for unpopular torrents with few peers. It
|
||||
will slow down fast torrents though.
|
||||
</small>
|
||||
</Form.Group>
|
||||
</fieldset>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show onHide={clear} size="lg">
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>Add torrent</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
{getBody()}
|
||||
<ErrorComponent error={uploadError} />
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
{uploading && <Spinner />}
|
||||
<Button
|
||||
variant="primary"
|
||||
onClick={handleUpload}
|
||||
disabled={
|
||||
listTorrentLoading || uploading || selectedFiles.length == 0
|
||||
}
|
||||
>
|
||||
OK
|
||||
</Button>
|
||||
<Button variant="secondary" onClick={clear}>
|
||||
Cancel
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue