Skip to content

Commit

Permalink
Merge pull request #43 from Okabe-Rintarou-0/fix-assignment-submit-bug
Browse files Browse the repository at this point in the history
fix: 2 bugs in submitting assignment
  • Loading branch information
Okabe-Rintarou-0 authored Oct 27, 2024
2 parents 004539a + 975da5f commit f87939b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
tauri-build = { version = "1", features = [] }

[dependencies]
tauri = { version = "1", features = [
tauri = { version = "1", features = [ "path-all",
"dialog-all",
"updater",
"process-relaunch",
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"confirm": true,
"message": true,
"open": true
},
"path": {
"all": true
}
},
"windows": [
Expand Down
41 changes: 32 additions & 9 deletions src/components/submit_modal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Button, Col, Form, List, Modal, Row, Space } from "antd";
import { useEffect, useState } from "react";
import { open } from '@tauri-apps/api/dialog';
import { DialogFilter, open } from '@tauri-apps/api/dialog';
import TextArea from "antd/es/input/TextArea";
import { FaUpload } from "react-icons/fa";
import useMessage from "antd/es/message/useMessage";
import { useForm } from "antd/lib/form/Form";
import { invoke } from "@tauri-apps/api";
import { invoke, path } from "@tauri-apps/api";

interface SubmitParam {
filePaths: string[];
Expand All @@ -18,20 +18,43 @@ function FilesSelector({ value, onChange, allowed_extensions }: {
onChange?: (value: string[]) => void,
}) {
const [filePaths, setFilePaths] = useState<string[]>([]);
const [fileBaseNames, setFileBaseNames] = useState<string[]>([]);
const [messageApi, contextHolder] = useMessage();
useEffect(() => {
if (value) {
setFilePaths(value);
}
}, [value]);
useEffect(() => {
const fileBaseNamesPromise = Promise.all(
filePaths.map(async (filePath) => await path.basename(filePath))
);
fileBaseNamesPromise.then(fileBaseNames => {
setFileBaseNames(fileBaseNames);
});
}, [filePaths]);

const handleSelectFiles = async () => {
let filters: DialogFilter[];
if (allowed_extensions.length) {
filters = [{
name: `所有文件(${allowed_extensions.join(',')})`,
extensions: allowed_extensions
}].concat(
allowed_extensions.map(extension => ({
name: extension,
extensions: [extension],
})));
} else {
filters = [{
name: '所有文件(*)',
extensions: ['*'],
}];
}

const selected = await open({
multiple: true,
filters: [{
name: "请选择支持的上传格式",
extensions: allowed_extensions
}]
filters: filters,
});
if (selected == null) {
messageApi.warning("未选中文件⚠️!", 1);
Expand All @@ -55,12 +78,12 @@ function FilesSelector({ value, onChange, allowed_extensions }: {
{contextHolder}
<Button icon={<FaUpload size={15} />} onClick={handleSelectFiles}>选择上传文件</Button>
<List>
{filePaths.map(filePath => <List.Item key={filePath}>
{fileBaseNames.map(fileBaseName => <List.Item key={fileBaseName}>
<Row justify="space-between" style={{ width: "100%" }}>
<Col>{filePath}</Col>
<Col>{fileBaseName}</Col>
<Col><a onClick={(e) => {
e.preventDefault();
handleRemove(filePath);
handleRemove(fileBaseName);
}}>删除</a></Col>
</Row>
</List.Item>)}
Expand Down

0 comments on commit f87939b

Please sign in to comment.