mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-26 00:33:12 +09:00
Merge pull request #1258 from bbassie/feature/mod-pack-upload
Add mod upload to the mod pack view
This commit is contained in:
1 parent
ef3b4cb8fc
commit
bee6714ff8
1 file changed
+53
-2
@@ -4,8 +4,9 @@ import { useNavigate, useParams } from "react-router-dom";
|
||||
import {
|
||||
Button, Card, ColorPicker, Checkbox, Col, ConfigProvider, Descriptions, Form, Input, Pagination,
|
||||
Popconfirm, Row, Table, Tag, Typography, Select, Skeleton, Space, Switch, Modal, Tooltip,
|
||||
TablePaginationConfig, Alert, notification, FormProps, Collapse,
|
||||
TablePaginationConfig, Alert, notification, FormProps, Collapse, Upload,
|
||||
} from "antd";
|
||||
import type { UploadChangeParam } from "antd/es/upload";
|
||||
|
||||
import {
|
||||
ExportOutlined, FileUnknownOutlined, FileExclamationOutlined, FileSyncOutlined,
|
||||
@@ -31,6 +32,9 @@ import SectionHeader from "./SectionHeader";
|
||||
import ResourceNotes from "./ResourceNotes";
|
||||
import ResourceState from "./ResourceState";
|
||||
import ModDetails from "./ModDetails";
|
||||
import { Dropzone } from "./Dropzone";
|
||||
import UploadButton from "./UploadButton";
|
||||
import { useUploadProgress } from "./UploadProgress";
|
||||
import { InputPartialVersion } from "./InputVersion";
|
||||
import Link from "./Link";
|
||||
|
||||
@@ -526,6 +530,16 @@ function DownloadDependenciesButton(props: DownloadDependenciesProps) {
|
||||
</>;
|
||||
}
|
||||
|
||||
function UploadDragger(props: React.ComponentProps<typeof Upload.Dragger>) {
|
||||
if (props.disabled) {
|
||||
return <>{props.children}</>;
|
||||
}
|
||||
return <Upload.Dragger className="save-list-dragger" openFileDialogOnClick={false} {...props}>
|
||||
<Dropzone />
|
||||
{props.children}
|
||||
</Upload.Dragger>;
|
||||
}
|
||||
|
||||
type ModsTableProps = {
|
||||
modPack: lib.ModPack;
|
||||
changes: ModChange[];
|
||||
@@ -535,6 +549,8 @@ type ModsTableProps = {
|
||||
};
|
||||
function ModsTable(props: ModsTableProps) {
|
||||
const account = useAccount();
|
||||
const control = useContext(ControlContext);
|
||||
const { customRequest, list: uploadList } = useUploadProgress();
|
||||
const [modInfos] = useMods();
|
||||
|
||||
const [showAddMods, setShowAddMods] = useState(false);
|
||||
@@ -743,6 +759,33 @@ function ModsTable(props: ModsTableProps) {
|
||||
</Space>;
|
||||
}
|
||||
|
||||
function onUpload({ file }: UploadChangeParam) {
|
||||
if (file.status !== "done") {
|
||||
return;
|
||||
}
|
||||
for (const json of file.response.mods) {
|
||||
const mod = lib.ModInfo.fromJSON(json);
|
||||
props.onChange({
|
||||
type: "mods.set",
|
||||
name: mod.name,
|
||||
value: { name: mod.name, enabled: true, version: mod.version, sha1: mod.sha1 },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const canUpload = account.hasPermission("core.mod.upload");
|
||||
const uploadProps = {
|
||||
disabled: !canUpload,
|
||||
name: "file",
|
||||
accept: ".zip",
|
||||
multiple: true,
|
||||
showUploadList: false,
|
||||
headers: { "X-Access-Token": control.connector.token || "" },
|
||||
action: `${webRoot}api/upload-mod`,
|
||||
customRequest,
|
||||
onChange: onUpload,
|
||||
};
|
||||
|
||||
return <>
|
||||
<SectionHeader
|
||||
title="Mods"
|
||||
@@ -779,6 +822,7 @@ function ModsTable(props: ModsTableProps) {
|
||||
builtInModNames={props.builtInModNames}
|
||||
checkForUpdates
|
||||
/>}
|
||||
{canUpload && <Upload {...uploadProps}><UploadButton /></Upload>}
|
||||
<Button icon={<PlusOutlined />} onClick={() => setShowAddMods(true)}>Add</Button>
|
||||
</Space>}
|
||||
/>
|
||||
@@ -790,6 +834,8 @@ function ModsTable(props: ModsTableProps) {
|
||||
>
|
||||
<SearchModsTable modPack={props.modPack} changes={props.changes} onChange={props.onChange} />
|
||||
</Card>}
|
||||
{uploadList}
|
||||
<UploadDragger {...uploadProps}>
|
||||
<Table
|
||||
size="small"
|
||||
rowSelection={{
|
||||
@@ -881,7 +927,11 @@ function ModsTable(props: ModsTableProps) {
|
||||
},
|
||||
]}
|
||||
expandable={{
|
||||
expandedRowRender: mod => <ModDetails mod={mod} mods={mods.filter(m => m.enabled)} actions={actions} />,
|
||||
expandedRowRender: mod => <ModDetails
|
||||
mod={mod}
|
||||
mods={mods.filter(m => m.enabled)}
|
||||
actions={actions}
|
||||
/>,
|
||||
expandedRowClassName: () => "no-expanded-padding",
|
||||
}}
|
||||
dataSource={mods}
|
||||
@@ -897,6 +947,7 @@ function ModsTable(props: ModsTableProps) {
|
||||
return "";
|
||||
}}
|
||||
/>
|
||||
</UploadDragger>
|
||||
</>;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user