mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Merge pull request #602 from Danielv123/react-to-drag-and-drop
React to drag and drop
This commit is contained in:
7 files changed
+282
-116
No files matched your search
@@ -0,0 +1,51 @@
|
|||||||
|
import { InboxOutlined } from "@ant-design/icons";
|
||||||
|
import { DraggingContext } from "../model/is_dragging";
|
||||||
|
import { useContext } from "react";
|
||||||
|
|
||||||
|
// This component is used to display a dropzone when a file is being dragged over the parent component
|
||||||
|
export function Dropzone({ disabled = false }: { disabled?: boolean }) {
|
||||||
|
const isDroppingFile = useContext(DraggingContext);
|
||||||
|
|
||||||
|
const textStyle: { color?: string } = {};
|
||||||
|
let text = "Drop to upload";
|
||||||
|
if (disabled) {
|
||||||
|
textStyle.color = "red";
|
||||||
|
text = "Target is offline";
|
||||||
|
}
|
||||||
|
const borderColor = disabled ? "gray" : "rgb(22, 119, 255)";
|
||||||
|
|
||||||
|
return <div
|
||||||
|
className={`dropzone ${disabled ? "disabled" : "enabled"}`} // Don't remove this class, linked to SiteLayout
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
top: "0",
|
||||||
|
left: "0",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
zIndex: "90",
|
||||||
|
backgroundColor: "#88888844",
|
||||||
|
borderRadius: "20px",
|
||||||
|
border: `dashed 2px ${borderColor}`,
|
||||||
|
display: isDroppingFile ? "block" : "none",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="dropzone-icon"
|
||||||
|
style={{
|
||||||
|
fontSize: "72px",
|
||||||
|
color: "rgb(22, 119, 255)",
|
||||||
|
display: "flex",
|
||||||
|
zIndex: "100",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
flexDirection: "column",
|
||||||
|
height: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<InboxOutlined style={textStyle} />
|
||||||
|
<p style={{ ...textStyle, fontSize: "24px", display: "block", textAlign: "center", marginTop: "8px" }}>
|
||||||
|
{text}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import { Button, Form, Input, Modal, Popconfirm, Space, Table, Typography, Upload } from "antd";
|
import { Button, Form, Input, Modal, Popconfirm, Space, Table, Typography, Upload } from "antd";
|
||||||
import ImportOutlined from "@ant-design/icons/ImportOutlined";
|
import ImportOutlined from "@ant-design/icons/ImportOutlined";
|
||||||
import PlusOutlined from "@ant-design/icons/PlusOutlined";
|
import PlusOutlined from "@ant-design/icons/PlusOutlined";
|
||||||
import UploadOutlined from "@ant-design/icons/UploadOutlined";
|
|
||||||
|
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
|
|
||||||
@@ -17,6 +16,8 @@ import PageLayout from "./PageLayout";
|
|||||||
import PluginExtra from "./PluginExtra";
|
import PluginExtra from "./PluginExtra";
|
||||||
import SectionHeader from "./SectionHeader";
|
import SectionHeader from "./SectionHeader";
|
||||||
import ModDetails from "./ModDetails";
|
import ModDetails from "./ModDetails";
|
||||||
|
import { Dropzone } from "./Dropzone";
|
||||||
|
import UploadButton from "./UploadButton";
|
||||||
|
|
||||||
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
|
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
|
||||||
|
|
||||||
@@ -55,11 +56,13 @@ function ImportModPackButton() {
|
|||||||
name="string"
|
name="string"
|
||||||
rules={[
|
rules={[
|
||||||
{ required: true },
|
{ required: true },
|
||||||
{ async validator(rule, value) {
|
{
|
||||||
if (value) {
|
async validator(rule, value) {
|
||||||
lib.ModPack.fromModPackString(value);
|
if (value) {
|
||||||
}
|
lib.ModPack.fromModPackString(value);
|
||||||
}},
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Input.TextArea autoSize={{ minRows: 6, maxRows: 6 }} />
|
<Input.TextArea autoSize={{ minRows: 6, maxRows: 6 }} />
|
||||||
@@ -172,12 +175,13 @@ export default function ModsPage() {
|
|||||||
name="file"
|
name="file"
|
||||||
accept=".zip"
|
accept=".zip"
|
||||||
multiple
|
multiple
|
||||||
|
showUploadList={false}
|
||||||
headers={{
|
headers={{
|
||||||
"X-Access-Token": control.connector.token||"",
|
"X-Access-Token": control.connector.token || "",
|
||||||
}}
|
}}
|
||||||
action={`${webRoot}api/upload-mod`}
|
action={`${webRoot}api/upload-mod`}
|
||||||
>
|
>
|
||||||
<Button icon={<UploadOutlined/>}>Upload</Button>
|
<UploadButton />
|
||||||
</Upload>;
|
</Upload>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,54 +223,76 @@ export default function ModsPage() {
|
|||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<SectionHeader title="Stored Mods" extra={uploadButton} />
|
<SectionHeader title="Stored Mods" extra={uploadButton} />
|
||||||
<Table
|
|
||||||
columns={[
|
<Upload.Dragger
|
||||||
{
|
className="save-list-dragger"
|
||||||
title: "Name",
|
openFileDialogOnClick={false}
|
||||||
dataIndex: "title",
|
name="file"
|
||||||
defaultSortOrder: "ascend",
|
accept=".zip"
|
||||||
sorter: (a, b) => (
|
multiple
|
||||||
strcmp(a.name, b.name) || a.integerVersion - b.integerVersion
|
headers={{
|
||||||
),
|
"X-Access-Token": control.connector.token || "",
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Version",
|
|
||||||
key: "version",
|
|
||||||
align: "right",
|
|
||||||
render: (_, mod) => <>
|
|
||||||
{`${mod.version} `}
|
|
||||||
<Typography.Text type="secondary">{`/ ${mod.factorioVersion}`}</Typography.Text>
|
|
||||||
</>,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Filename",
|
|
||||||
dataIndex: "filename",
|
|
||||||
responsive: ["xl"],
|
|
||||||
sorter: (a, b) => strcmp(a.filename, b.filename),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Size",
|
|
||||||
key: "size",
|
|
||||||
responsive: ["lg"],
|
|
||||||
render: (_, mod) => lib.formatBytes(mod.size),
|
|
||||||
align: "right",
|
|
||||||
sorter: (a, b) => a.size - b.size,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Action",
|
|
||||||
key: "action",
|
|
||||||
responsive: ["lg"],
|
|
||||||
render: (_, mod) => actions(mod),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
expandable={{
|
|
||||||
expandedRowRender: (mod: lib.ModInfo) => <ModDetails mod={mod} actions={actions} />,
|
|
||||||
expandedRowClassName: () => "no-expanded-padding",
|
|
||||||
}}
|
}}
|
||||||
dataSource={[...mods.values()]}
|
action={`${webRoot}api/upload-mod`}
|
||||||
pagination={false}
|
showUploadList={false}
|
||||||
rowKey={mod => mod.id}
|
>
|
||||||
/>
|
<div
|
||||||
|
style={{
|
||||||
|
position: "relative",
|
||||||
|
zIndex: "1010",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Dropzone />
|
||||||
|
<Table
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
title: "Name",
|
||||||
|
dataIndex: "title",
|
||||||
|
defaultSortOrder: "ascend",
|
||||||
|
sorter: (a, b) => (
|
||||||
|
strcmp(a.name, b.name) || a.integerVersion - b.integerVersion
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Version",
|
||||||
|
key: "version",
|
||||||
|
align: "right",
|
||||||
|
render: (_, mod) => <>
|
||||||
|
{`${mod.version} `}
|
||||||
|
<Typography.Text type="secondary">{`/ ${mod.factorioVersion}`}</Typography.Text>
|
||||||
|
</>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Filename",
|
||||||
|
dataIndex: "filename",
|
||||||
|
responsive: ["xl"],
|
||||||
|
sorter: (a, b) => strcmp(a.filename, b.filename),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Size",
|
||||||
|
key: "size",
|
||||||
|
responsive: ["lg"],
|
||||||
|
render: (_, mod) => lib.formatBytes(mod.size),
|
||||||
|
align: "right",
|
||||||
|
sorter: (a, b) => a.size - b.size,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Action",
|
||||||
|
key: "action",
|
||||||
|
responsive: ["lg"],
|
||||||
|
render: (_, mod) => actions(mod),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
expandable={{
|
||||||
|
expandedRowRender: (mod: lib.ModInfo) => <ModDetails mod={mod} actions={actions} />,
|
||||||
|
expandedRowClassName: () => "no-expanded-padding",
|
||||||
|
}}
|
||||||
|
dataSource={[...mods.values()]}
|
||||||
|
pagination={false}
|
||||||
|
rowKey={mod => mod.id}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Upload.Dragger>
|
||||||
<PluginExtra component="ModsPage" />
|
<PluginExtra component="ModsPage" />
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,8 @@ import SectionHeader from "./SectionHeader";
|
|||||||
import { useInstances } from "../model/instance";
|
import { useInstances } from "../model/instance";
|
||||||
import { useSavesOfInstance } from "../model/saves";
|
import { useSavesOfInstance } from "../model/saves";
|
||||||
import { notifyErrorHandler } from "../util/notify";
|
import { notifyErrorHandler } from "../util/notify";
|
||||||
|
import { Dropzone } from "./Dropzone";
|
||||||
|
import UploadButton from "./UploadButton";
|
||||||
|
|
||||||
|
|
||||||
type ModalProps = {
|
type ModalProps = {
|
||||||
@@ -150,7 +152,7 @@ function TransferModal(props: ModalProps) {
|
|||||||
autoFocus
|
autoFocus
|
||||||
showSearch
|
showSearch
|
||||||
filterOption={(input, option) => (
|
filterOption={(input, option) => (
|
||||||
(option?.title!.toLowerCase().indexOf(input.toLowerCase())??-1) >= 0
|
(option?.title!.toLowerCase().indexOf(input.toLowerCase()) ?? -1) >= 0
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{[...instances.values()].filter(
|
{[...instances.values()].filter(
|
||||||
@@ -214,8 +216,8 @@ export default function SavesList(props: { instance: lib.InstanceDetails }) {
|
|||||||
title: "Name",
|
title: "Name",
|
||||||
render: (_, save) => <>
|
render: (_, save) => <>
|
||||||
{save.name}
|
{save.name}
|
||||||
{save.loaded && <Tooltip title="Currently loaded save"><CaretLeftOutlined/></Tooltip>}
|
{save.loaded && <Tooltip title="Currently loaded save"><CaretLeftOutlined /></Tooltip>}
|
||||||
{save.loadByDefault && <Tooltip title="Save loaded by default"><LeftOutlined/></Tooltip>}
|
{save.loadByDefault && <Tooltip title="Save loaded by default"><LeftOutlined /></Tooltip>}
|
||||||
</>,
|
</>,
|
||||||
sorter: (a, b) => a.name.localeCompare(b.name),
|
sorter: (a, b) => a.name.localeCompare(b.name),
|
||||||
},
|
},
|
||||||
@@ -240,7 +242,7 @@ export default function SavesList(props: { instance: lib.InstanceDetails }) {
|
|||||||
expandable={{
|
expandable={{
|
||||||
columnWidth: 33,
|
columnWidth: 33,
|
||||||
expandRowByClick: true,
|
expandRowByClick: true,
|
||||||
expandedRowRender: save => <Space wrap style={{marginBottom: 0}}>
|
expandedRowRender: save => <Space wrap style={{ marginBottom: 0 }}>
|
||||||
{account.hasPermission("core.instance.start") && <Button
|
{account.hasPermission("core.instance.start") && <Button
|
||||||
loading={starting}
|
loading={starting}
|
||||||
disabled={props.instance.status !== "stopped"}
|
disabled={props.instance.status !== "stopped"}
|
||||||
@@ -346,14 +348,24 @@ export default function SavesList(props: { instance: lib.InstanceDetails }) {
|
|||||||
return <div>
|
return <div>
|
||||||
<SectionHeader title="Saves" extra={<Space>
|
<SectionHeader title="Saves" extra={<Space>
|
||||||
{account.hasPermission("core.instance.save.upload") && <Upload {...uploadProps} >
|
{account.hasPermission("core.instance.save.upload") && <Upload {...uploadProps} >
|
||||||
<Button disabled={hostOffline}>Upload save</Button>
|
<UploadButton disabled={hostOffline}>
|
||||||
|
Upload save
|
||||||
|
</UploadButton>
|
||||||
</Upload>}
|
</Upload>}
|
||||||
{account.hasPermission("core.instance.save.create") && <CreateSaveModal instance={props.instance} />}
|
{account.hasPermission("core.instance.save.create") && <CreateSaveModal instance={props.instance} />}
|
||||||
</Space>} />
|
</Space>} />
|
||||||
{
|
{
|
||||||
account.hasPermission("core.instance.save.upload")
|
account.hasPermission("core.instance.save.upload")
|
||||||
? <Upload.Dragger className="save-list-dragger" openFileDialogOnClick={false} {...uploadProps}>
|
? <Upload.Dragger className="save-list-dragger" openFileDialogOnClick={false} {...uploadProps}>
|
||||||
{saveTable}
|
<div
|
||||||
|
style={{
|
||||||
|
position: "relative",
|
||||||
|
zIndex: "1010",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Dropzone disabled={hostOffline} />
|
||||||
|
{saveTable}
|
||||||
|
</div>
|
||||||
</Upload.Dragger>
|
</Upload.Dragger>
|
||||||
: saveTable
|
: saveTable
|
||||||
}
|
}
|
||||||
@@ -362,7 +374,7 @@ export default function SavesList(props: { instance: lib.InstanceDetails }) {
|
|||||||
{file.name}
|
{file.name}
|
||||||
<Progress
|
<Progress
|
||||||
percent={file.percent}
|
percent={file.percent}
|
||||||
format={percent => `${Math.floor(percent||0)}%`}
|
format={percent => `${Math.floor(percent || 0)}%`}
|
||||||
status={file.status === "error" ? "exception" : "normal"}
|
status={file.status === "error" ? "exception" : "normal"}
|
||||||
/>
|
/>
|
||||||
</List.Item>)}
|
</List.Item>)}
|
||||||
|
|||||||
@@ -9,16 +9,34 @@ import ErrorBoundary from "./ErrorBoundary";
|
|||||||
import ErrorPage from "./ErrorPage";
|
import ErrorPage from "./ErrorPage";
|
||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
import { pages } from "../pages";
|
import { pages } from "../pages";
|
||||||
|
import { DraggingContext } from "../model/is_dragging";
|
||||||
|
|
||||||
const { Header, Sider } = Layout;
|
const { Header, Sider } = Layout;
|
||||||
|
|
||||||
|
function isActiveDropzone(element: HTMLElement | null): boolean {
|
||||||
|
if (!element) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const checkDepth = 5;
|
||||||
|
let depth = 0;
|
||||||
|
while (element && depth < checkDepth) {
|
||||||
|
if (element.classList.contains("dropzone")) {
|
||||||
|
return element.classList.contains("enabled");
|
||||||
|
}
|
||||||
|
element = element.parentElement;
|
||||||
|
depth += 1;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
export default function SiteLayout() {
|
export default function SiteLayout() {
|
||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
let [currentSidebarPath, setCurrentSidebarPath] = useState<string|null>(null);
|
let [currentSidebarPath, setCurrentSidebarPath] = useState<string | null>(null);
|
||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
let plugins = useContext(ControlContext).plugins;
|
let plugins = useContext(ControlContext).plugins;
|
||||||
|
const [dragging, setDragging] = useState(0);
|
||||||
|
|
||||||
function SetSidebar(props: { path: string|null }) {
|
function SetSidebar(props: { path: string | null }) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCurrentSidebarPath(props.path);
|
setCurrentSidebarPath(props.path);
|
||||||
});
|
});
|
||||||
@@ -26,7 +44,7 @@ export default function SiteLayout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let accountMenuProps: MenuProps = {
|
let accountMenuProps: MenuProps = {
|
||||||
onClick: ({ key }: {key:string}) => {
|
onClick: ({ key }: { key: string }) => {
|
||||||
if (key === "user") {
|
if (key === "user") {
|
||||||
navigate(`/users/${account.name}/view`);
|
navigate(`/users/${account.name}/view`);
|
||||||
} else if (key === "logOut") {
|
} else if (key === "logOut") {
|
||||||
@@ -72,59 +90,91 @@ export default function SiteLayout() {
|
|||||||
menuItems.push({ type: "group", label: name, children: group, key: name });
|
menuItems.push({ type: "group", label: name, children: group, key: name });
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Layout style={{ minHeight: "100vh" }}>
|
// Prevent issues with event ordering
|
||||||
<Header className="header">
|
let dragChange = 0;
|
||||||
<div className="site-logo" />
|
function setDraggingProxy(value: number) {
|
||||||
<span className="site-name">Clusterio</span>
|
dragChange += value;
|
||||||
<span className="site-version">{ webUiPackage.version }</span>
|
setDragging(dragging + dragChange);
|
||||||
<Menu
|
}
|
||||||
theme="dark"
|
|
||||||
mode="horizontal"
|
return <Layout
|
||||||
defaultSelectedKeys={["1"]}
|
style={{ minHeight: "100vh" }}
|
||||||
items={[{ label: "Dashboard", key: "1" }]}
|
onDragEnter={() => setDraggingProxy(1)}
|
||||||
/>
|
onDragLeave={() => setDraggingProxy(-1)}
|
||||||
<Dropdown
|
// Reset dragging state when dropped
|
||||||
className="account-dropdown-header"
|
onDrop={(e) => {
|
||||||
placement="bottomRight"
|
setDragging(0);
|
||||||
trigger={["click"]}
|
// Prevent dropping outside of dropzone
|
||||||
menu={accountMenuProps}
|
if (!isActiveDropzone(e.target as HTMLElement)) {
|
||||||
>
|
e.preventDefault();
|
||||||
<UserOutlined/>
|
e.stopPropagation();
|
||||||
</Dropdown>
|
}
|
||||||
</Header>
|
}}
|
||||||
<Layout className="site-layout">
|
// Allow entire document to be a drag target
|
||||||
<Sider
|
onDragOver={(e) => {
|
||||||
collapsible
|
e.preventDefault();
|
||||||
collapsedWidth={0}
|
// Change cursor
|
||||||
breakpoint="md"
|
if (isActiveDropzone(e.target as HTMLElement)) {
|
||||||
zeroWidthTriggerStyle={{ top: 6, zIndex: -1 }}
|
e.dataTransfer.dropEffect = "copy";
|
||||||
width={250}
|
} else {
|
||||||
className="site-layout-sider"
|
e.dataTransfer.dropEffect = "none";
|
||||||
>
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DraggingContext.Provider value={dragging > 0}>
|
||||||
|
<Header className="header">
|
||||||
|
<div className="site-logo" />
|
||||||
|
<span className="site-name">Clusterio</span>
|
||||||
|
<span className="site-version">{webUiPackage.version}</span>
|
||||||
<Menu
|
<Menu
|
||||||
mode="inline"
|
theme="dark"
|
||||||
defaultOpenKeys={[...menuGroups.keys()]}
|
mode="horizontal"
|
||||||
selectedKeys={currentSidebarPath ? [currentSidebarPath] : []}
|
defaultSelectedKeys={["1"]}
|
||||||
style={{ height: "100%", borderRight: 0 }}
|
items={[{ label: "Dashboard", key: "1" }]}
|
||||||
onClick={({ key }) => navigate(key)}
|
|
||||||
items={menuItems}
|
|
||||||
/>
|
/>
|
||||||
</Sider>
|
<Dropdown
|
||||||
<Layout className="site-layout-content-container">
|
className="account-dropdown-header"
|
||||||
<Routes>
|
placement="bottomRight"
|
||||||
{combinedPages.map(({path, sidebarPath, content}) => <Route
|
trigger={["click"]}
|
||||||
path={path}
|
menu={accountMenuProps}
|
||||||
key={path}
|
>
|
||||||
element={<Fragment key={path}>
|
<UserOutlined />
|
||||||
<SetSidebar path={sidebarPath ? sidebarPath : path} />
|
</Dropdown>
|
||||||
<ErrorBoundary Component={ErrorPage}>
|
</Header>
|
||||||
{content}
|
<Layout className="site-layout">
|
||||||
</ErrorBoundary>
|
<Sider
|
||||||
</Fragment>}
|
collapsible
|
||||||
/>)}
|
collapsedWidth={0}
|
||||||
<Route element={<SetSidebar path={null} />} />
|
breakpoint="md"
|
||||||
</Routes>
|
zeroWidthTriggerStyle={{ top: 6, zIndex: -1 }}
|
||||||
|
width={250}
|
||||||
|
className="site-layout-sider"
|
||||||
|
>
|
||||||
|
<Menu
|
||||||
|
mode="inline"
|
||||||
|
defaultOpenKeys={[...menuGroups.keys()]}
|
||||||
|
selectedKeys={currentSidebarPath ? [currentSidebarPath] : []}
|
||||||
|
style={{ height: "100%", borderRight: 0 }}
|
||||||
|
onClick={({ key }) => navigate(key)}
|
||||||
|
items={menuItems}
|
||||||
|
/>
|
||||||
|
</Sider>
|
||||||
|
<Layout className="site-layout-content-container">
|
||||||
|
<Routes>
|
||||||
|
{combinedPages.map(({ path, sidebarPath, content }) => <Route
|
||||||
|
path={path}
|
||||||
|
key={path}
|
||||||
|
element={<Fragment key={path}>
|
||||||
|
<SetSidebar path={sidebarPath ? sidebarPath : path} />
|
||||||
|
<ErrorBoundary Component={ErrorPage}>
|
||||||
|
{content}
|
||||||
|
</ErrorBoundary>
|
||||||
|
</Fragment>}
|
||||||
|
/>)}
|
||||||
|
<Route element={<SetSidebar path={null} />} />
|
||||||
|
</Routes>
|
||||||
|
</Layout>
|
||||||
</Layout>
|
</Layout>
|
||||||
</Layout>
|
</DraggingContext.Provider>
|
||||||
</Layout>;
|
</Layout>;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { useContext } from "react";
|
||||||
|
import { Button } from "antd";
|
||||||
|
import { InboxOutlined, UploadOutlined } from "@ant-design/icons";
|
||||||
|
|
||||||
|
import { DraggingContext } from "../model/is_dragging";
|
||||||
|
|
||||||
|
export default function UploadButton(props: React.ComponentProps<typeof Button>) {
|
||||||
|
const isDroppingFile = useContext(DraggingContext);
|
||||||
|
const borderColor = props.disabled ? "gray" : "rgb(22, 119, 255)";
|
||||||
|
return <Button
|
||||||
|
className={`dropzone ${props.disabled ? "disabled" : "enabled"}`}
|
||||||
|
{...props}
|
||||||
|
style={{
|
||||||
|
...props.style,
|
||||||
|
// Distinct border when dropping file
|
||||||
|
border: isDroppingFile ? `dashed 2px ${borderColor}` : undefined,
|
||||||
|
}}
|
||||||
|
icon={isDroppingFile ? <InboxOutlined /> : props.icon || <UploadOutlined />}
|
||||||
|
>
|
||||||
|
{props.children || "Upload"}
|
||||||
|
</Button>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { createContext } from "react";
|
||||||
|
|
||||||
|
export const DraggingContext = createContext(false);
|
||||||
@@ -185,6 +185,8 @@ body {
|
|||||||
.save-list-dragger .ant-upload.ant-upload-drag {
|
.save-list-dragger .ant-upload.ant-upload-drag {
|
||||||
border: none;
|
border: none;
|
||||||
background: none;
|
background: none;
|
||||||
|
height: auto;
|
||||||
|
cursor: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
.save-list-dragger .ant-upload.ant-upload-btn {
|
.save-list-dragger .ant-upload.ant-upload-btn {
|
||||||
|
|||||||
Reference in new issue
Block a user