Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
parkpow
GitHub Repository: parkpow/deep-license-plate-recognition
Path: blob/master/docker/dd-extension/ui/src/components/Update.tsx
1091 views
1
import { useState } from "react";
2
import { Button, Row } from "react-bootstrap";
3
import Form from "react-bootstrap/Form";
4
import { useDockerDesktopClient } from "../hooks/useDockerDesktopClient";
5
6
import Loader from "./Loader";
7
8
interface UpdateProps {
9
isEnabled: boolean;
10
image: string;
11
}
12
export default function Update({ isEnabled, image }: UpdateProps) {
13
const [isLoading, setLoading] = useState(false);
14
const ddClient = useDockerDesktopClient();
15
16
if (!isEnabled) return null;
17
18
const handleUpdateImage = () => {
19
setLoading(true);
20
ddClient.docker.cli
21
.exec("pull", [image])
22
.then((result) => {
23
console.debug(result);
24
setLoading(false);
25
})
26
.catch((err) => {
27
console.error(err);
28
ddClient.desktopUI.toast.error(`Update Snapshot: ${err.message}`);
29
setLoading(false);
30
});
31
};
32
33
return (
34
<Form.Group as={Row} className="mb-3 {'d-none': uninstall }">
35
<div className="col-2">
36
<Button
37
className="btn btn-secondary"
38
type="button"
39
onClick={handleUpdateImage}
40
id="update-image-btn"
41
disabled={isLoading}
42
>
43
<Loader isLoading={isLoading} />
44
Update
45
</Button>
46
</div>
47
<label
48
className="col-auto align-self-center form-label"
49
htmlFor="update-image-btn"
50
>
51
Update the Docker image.
52
</label>
53
</Form.Group>
54
);
55
}
56
57