mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Fix and refactor download buttons
This commit is contained in:
1 parent
e841aa5685
commit
a79b129b0c
1 file changed
+39
-34
@@ -176,6 +176,33 @@ function SearchModsButton() {
|
|||||||
const [sort, setSort] = useState<string>("name");
|
const [sort, setSort] = useState<string>("name");
|
||||||
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc");
|
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc");
|
||||||
|
|
||||||
|
// Function to handle download from Mod Portal to Controller
|
||||||
|
const handleControllerDownload = (
|
||||||
|
modName: string,
|
||||||
|
modTitle: string | undefined,
|
||||||
|
modVersion: string | undefined,
|
||||||
|
portalFactorioVersion: FactorioVersion,
|
||||||
|
) => {
|
||||||
|
if (modVersion) {
|
||||||
|
control.send(
|
||||||
|
new lib.ModPortalDownloadRequest(
|
||||||
|
modName,
|
||||||
|
modVersion,
|
||||||
|
portalFactorioVersion
|
||||||
|
)
|
||||||
|
).then(() => {
|
||||||
|
notification.success({
|
||||||
|
message: "Download started",
|
||||||
|
description: `${modTitle || modName} v${
|
||||||
|
modVersion
|
||||||
|
} is being downloaded to the controller.`,
|
||||||
|
});
|
||||||
|
}).catch(
|
||||||
|
notifyErrorHandler("Error starting mod download")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Fetch all mods from backend when modal opens or version changes
|
// Fetch all mods from backend when modal opens or version changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open || !factorioVersion) {
|
if (!open || !factorioVersion) {
|
||||||
@@ -408,22 +435,12 @@ function SearchModsButton() {
|
|||||||
{account.hasPermission("core.mod.download") && record.latest_release && (
|
{account.hasPermission("core.mod.download") && record.latest_release && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (record.latest_release?.version) {
|
handleControllerDownload(
|
||||||
control.send(
|
record.name,
|
||||||
new lib.ModDownloadRequest(
|
record.title,
|
||||||
record.name,
|
record.latest_release?.version,
|
||||||
record.latest_release.version
|
factorioVersion
|
||||||
)
|
);
|
||||||
)
|
|
||||||
.then((streamId: string) => {
|
|
||||||
let url = new URL(webRoot, document.location.origin);
|
|
||||||
url.pathname += `api/stream/${streamId}`;
|
|
||||||
document.location = url.href;
|
|
||||||
})
|
|
||||||
.catch(
|
|
||||||
notifyErrorHandler("Error downloading mod")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
disabled={!record.latest_release?.version}
|
disabled={!record.latest_release?.version}
|
||||||
>
|
>
|
||||||
@@ -496,24 +513,12 @@ function SearchModsButton() {
|
|||||||
icon={<DownloadOutlined />}
|
icon={<DownloadOutlined />}
|
||||||
disabled={!record.latest_release?.version}
|
disabled={!record.latest_release?.version}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (record.latest_release?.version) {
|
handleControllerDownload(
|
||||||
control.send(
|
record.name,
|
||||||
new lib.ModPortalDownloadRequest(
|
record.title,
|
||||||
record.name,
|
record.latest_release?.version,
|
||||||
record.latest_release.version,
|
factorioVersion
|
||||||
factorioVersion
|
);
|
||||||
)
|
|
||||||
).then(() => {
|
|
||||||
notification.success({
|
|
||||||
message: "Download started",
|
|
||||||
description: `${record.title || record.name} v${
|
|
||||||
record.latest_release?.version
|
|
||||||
} is being downloaded to the controller.`,
|
|
||||||
});
|
|
||||||
}).catch(
|
|
||||||
notifyErrorHandler("Error starting mod download")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|||||||
Reference in new issue
Block a user