utilisation d'un service pour la gestion d'un téléchargement

This commit is contained in:
MathieuG-P
2022-05-17 23:53:58 +02:00
parent 2b24cfae3c
commit 97e70e946d
@@ -2,24 +2,23 @@ import { BSVersion } from "../../main/services/bs-version-manager.service";
import { useSelector } from "react-redux";
import { AvailableVersionsArray } from "renderer/components/available-versions-array.component";
import { useState } from "react";
import { ModalService, ModalType } from "renderer/services/modale.service";
import { BsDownloaderService } from "renderer/services/bs-downloader.service";
export function AvailableVersionsList() {
const { availableVersions }: {availableVersions: BSVersion[]} = useSelector((state: any) => state.availableBsReducer);
const [versionSelected, setVersionSelected] = useState(null as BSVersion);
const [needIds, setNeedIds] = useState(false);
const [stay, setStay] = useState(false);
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const bsDownloaderService: BsDownloaderService = BsDownloaderService.getInstance();
const selectedVersionCallback = (v: BSVersion) => {
setVersionSelected(v);
}
const startInstall = (username = localStorage.getItem("username")) => {
if(!username){ setNeedIds(true); return; }
localStorage.setItem("username", username);
const startInstall = () => {
bsDownloaderService.download(versionSelected);
}
console.log(availableVersions);
@@ -35,10 +34,6 @@ export function AvailableVersionsList() {
<button onClick={() => startInstall()} className="m-4 bg-white text-xl font-bold p-3">INSTALL</button>
<button className="m-4 bg-white text-xl font-bold p-3">VERSION NOTES</button>
</div>
{ needIds && <input onChange={(e) => setUsername(e.target.value)} value={username} type="text" name="" id="" placeholder="username"/> }
{ needIds && <input onChange={(e) => setPassword(e.target.value)} value={password} type="password" name="" id="" placeholder="password"/> }
{ needIds && (<> <label htmlFor="stay">STAY</label> <input onChange={(e) => setStay(e.target.checked)} checked={stay} id="stay" type="checkbox"/> </>) }
{ needIds && <button onClick={() => startInstall(username)}>SUBMIT</button> }
</>
)}
</div>