path selector添加当前目录选项,修复上层目录 (#144)

This commit is contained in:
WeidiDeng 2023-01-09 19:18:16 +08:00 committed by GitHub
parent a205cb4da6
commit 95ff68b995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 14 deletions

View File

@ -111,6 +111,7 @@
"name": "Name",
"size": "Size",
"lastModified": "Last modified",
"currentFolder": "Current Folder",
"backToParentFolder": "Back to the parent",
"folders": "Folders",
"files": "Files",

View File

@ -111,6 +111,7 @@
"name": "名称",
"size": "大小",
"lastModified": "修改日期",
"currentFolder": "当前目录",
"backToParentFolder": "上级目录",
"folders": "文件夹",
"files": "文件",

View File

@ -98,17 +98,20 @@ class PathSelectorCompoment extends Component {
} else {
let path = toBeLoad;
let name = toBeLoad;
const paths = path.split("/");
name = paths.pop();
name = name === "" ? "/" : name;
path = paths.join("/");
dirList.unshift({
name: name,
path: path,
displayName: this.props.t(
"fileManager.backToParentFolder"
),
});
const displayNames = ["fileManager.currentFolder", "fileManager.backToParentFolder"];
for (let i = 0; i < 2; i++) {
const paths = path.split("/");
name = paths.pop();
name = name === "" ? "/" : name;
path = paths.join("/");
dirList.unshift({
name: name,
path: path,
displayName: this.props.t(
displayNames[i]
),
});
}
}
this.setState({
presentPath: toBeLoad,
@ -134,6 +137,24 @@ class PathSelectorCompoment extends Component {
render() {
const { classes, t } = this.props;
const showActionIcon = (index) => {
if (this.state.presentPath === "/") {
return index !== 0;
}
return index !== 1;
};
const actionIcon = (index) => {
if (this.state.presentPath === "/") {
return <RightIcon />;
}
if (index === 0) {
return <UpIcon />;
}
return <RightIcon />;
};
return (
<div className={classes.container}>
<MenuList className={classes.selector}>
@ -156,7 +177,7 @@ class PathSelectorCompoment extends Component {
style: { whiteSpace: "normal" },
}}
/>
{(index !== 0 || value.name !== "/") && (
{showActionIcon(index) && (
<ListItemSecondaryAction
className={classes.buttonIcon}
>
@ -179,8 +200,7 @@ class PathSelectorCompoment extends Component {
)
}
>
{index === 0 && <UpIcon />}
{index !== 0 && <RightIcon />}
{actionIcon(index)}
</IconButton>
</ListItemSecondaryAction>
)}