Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"next-runtime-env": "^3.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hot-toast": "^2.6.0",
"react-icons": "^5.5.0",
"react-leaflet": "^5.0.0",
"react-mosaic-component": "^6.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/app/launch/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import Layout from "../../components/Layout";
import { Toaster } from "react-hot-toast";
import dynamic from 'next/dynamic';

const ContainerListPage = dynamic(() => import("../../components/ContainerList"), { ssr: false });
Expand All @@ -9,6 +10,7 @@ export default function Launch() {
return (
<Layout>
<ContainerListPage/>
<Toaster />
</Layout>
);
}
40 changes: 37 additions & 3 deletions src/components/ContainerList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
import React, { useEffect, useState, useRef } from 'react';
import ContainerCard, { ContainerOption } from './ContainerCard';
import SetResetPanel from './SetResetPanel';
import toast from "react-hot-toast";


const dockersToPull = [
'cprtsoftware/rover:arm64',
'cprtsoftware/web-ui:latest',
'cprtsoftware/container-launcher:latest',
];

const DEFAULT_API_BASE = 'http://localhost:8080';

Expand Down Expand Up @@ -97,10 +105,35 @@ const ContainerList: React.FC = () => {
setApiBase(url);
};

const handleReset = () => {
setApiBase(DEFAULT_API_BASE);
const handlePull = async () => {
const ok = confirm(
`This updates the rover to the latest merged version. Are you sure you want to continue?`
);
if (!ok) return;

const promises = dockersToPull.map(async (docker) => {
const id = toast.loading(`Pulling ${docker}…`);

try {
const encoded = encodeURIComponent(docker);
const res = await fetch(`${apiBase}/pull/${encoded}`, { method: "PUT" });
const data = await res.json();

if (res.ok) {
toast.success(`Pulled ${docker} successfully`, { id });
} else {
toast.error(`Failed to pull ${docker}: ${data?.error}`, { id });
}
} catch (err: any) {
toast.error(`Error pulling ${docker}: ${err.message}`, { id });
}
});

await Promise.all(promises);
toast("All pulls finished");
};


return (
<div style={{ padding: 20, fontFamily: 'Arial, sans-serif' }}>
<h2>Docker Launch Options</h2>
Expand All @@ -109,7 +142,8 @@ const ContainerList: React.FC = () => {
id="launch_server_url"
defaultUrl={DEFAULT_API_BASE}
onUrlChange={handleUrlChange}
onReset={handleReset}
onReset={handlePull}
button2Name='Update system'
/>
</div>
<div
Expand Down
8 changes: 5 additions & 3 deletions src/components/SetResetPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ interface SetResetPanelProps {
onReset: () => void;
defaultUrl: string;
id: string;
button1Name?: string;
button2Name?: string;
}

const SetResetPanel: React.FC<SetResetPanelProps> = ({ onUrlChange, onReset, defaultUrl, id }) => {
const SetResetPanel: React.FC<SetResetPanelProps> = ({ onUrlChange, onReset, defaultUrl, id, button1Name="Set Server", button2Name="Reset" }) => {
const [url, setUrl] = useState(defaultUrl);

useEffect(() => {
Expand Down Expand Up @@ -77,7 +79,7 @@ const SetResetPanel: React.FC<SetResetPanelProps> = ({ onUrlChange, onReset, def
onMouseDown={(e) => (e.currentTarget.style.transform = 'scale(0.97)')}
onMouseUp={(e) => (e.currentTarget.style.transform = 'scale(1)')}
>
Set Server
{button1Name}
</button>
<button
onClick={onReset}
Expand All @@ -97,7 +99,7 @@ const SetResetPanel: React.FC<SetResetPanelProps> = ({ onUrlChange, onReset, def
onMouseDown={(e) => (e.currentTarget.style.transform = 'scale(0.97)')}
onMouseUp={(e) => (e.currentTarget.style.transform = 'scale(1)')}
>
Reset
{button2Name}
</button>
</div>
);
Expand Down