Skip to content

Commit

Permalink
optimize codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael18811380328 committed May 7, 2024
1 parent c1392ba commit 1857314
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
7 changes: 7 additions & 0 deletions frontend/src/pages/wiki/css/view-structure.css
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@
color: #fff;
}

.dtable-dropdown-menu.large .dropdown-item {
min-height: 32px;
padding: 3px 12px;
display: flex;
align-items: center;
}

/* dark mode */
.view-structure-dark.view-structure,
.view-structure-dark.view-structure .view-folder .icon-expand-folder {
Expand Down
28 changes: 18 additions & 10 deletions frontend/src/pages/wiki/view-structure/add-exist-file-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class AddExistFileDialog extends React.Component {
repo: null,
selectedPath: '',
errMessage: '',
newFileName: '',
};
}

Expand All @@ -34,20 +33,29 @@ class AddExistFileDialog extends React.Component {
}
};

onFileNameChange = (event) => {
this.setState({ newFileName: event.target.value });
};

toggle = () => {
this.props.toggle();
};

checkName = (newName) => {
if (newName === '') {
toaster.danger(gettext('Name cannot be empty'));
return false;
}
if (newName.includes('/')) {
toaster.danger(gettext('Name cannot contain slash'));
return false;
}
if (newName.includes('\\')) {
toaster.danger(gettext('Name cannot contain backslash'));
return false;
}
return true;
};

onSubmit = () => {
const pageName = this.state.pageName.trim();
if (pageName === '') {
toaster.danger(gettext('Page name cannot be empty'));
return;
}
if (!this.checkName(pageName)) return;
let { selectedPath } = this.state;
if (selectedPath.endsWith('.sdoc') === false && selectedPath.endsWith('.md') === false) {
toaster.danger(gettext('Please select an existing sdoc or markdown file'));
Expand Down Expand Up @@ -91,7 +99,7 @@ class AddExistFileDialog extends React.Component {
return (
<Modal isOpen={true} toggle={this.toggle} autoFocus={false} className="add-exist-file-dialog" style={{ maxHeight: DIALOG_MAX_HEIGHT }}>
<ModalHeader toggle={this.toggle}>{gettext('Add existing file')}</ModalHeader>
<ModalBody className={'pr-4'}>
<ModalBody className='pr-4'>
<Form>
<FormGroup>
<Label>{gettext('Page name')}</Label>
Expand Down
15 changes: 7 additions & 8 deletions frontend/src/pages/wiki/view-structure/add-new-page-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ const propTypes = {
onAddNewPage: PropTypes.func,
};

const NEW_WIKI_FILE_PATH = '/wiki-pages/';

class AddNewPageDialog extends React.Component {

constructor(props) {
super(props);
this.state = {
pageName: '',
isLoading: true,
repo: null,
errMessage: '',
newFileName: '',
};
}

componentDidMount() {
const path = '/wiki-pages/';
seafileAPI.getDirInfo(repoID, path).then((res) => {
if (res.data.path === path) {
seafileAPI.getDirInfo(repoID, NEW_WIKI_FILE_PATH).then((res) => {
if (res.data.path === NEW_WIKI_FILE_PATH) {
this.setState({ isLoading: false });
}
}).catch((error) => {
if (error.response.data.error_msg === 'Folder /wiki-pages/ not found.') {
seafileAPI.createDir(repoID, path).then((res) => {
seafileAPI.createDir(repoID, NEW_WIKI_FILE_PATH).then((res) => {
if (res.data === 'success') {
this.setState({ isLoading: false });
}
Expand Down Expand Up @@ -86,8 +86,7 @@ class AddNewPageDialog extends React.Component {
const newFileName = this.state.newFileName.trim();
if (this.checkName(pageName) && this.checkName(newFileName)) {
this.setState({ isLoading: true });
const path = '/wiki-pages/';
this.createFile(pageName, `${path}${newFileName}.sdoc`);
this.createFile(pageName, `${NEW_WIKI_FILE_PATH}${newFileName}.sdoc`);
}
};

Expand Down Expand Up @@ -120,7 +119,7 @@ class AddNewPageDialog extends React.Component {
return (
<Modal isOpen={true} toggle={this.toggle} autoFocus={false}>
<ModalHeader toggle={this.toggle}>{gettext('Add page')}</ModalHeader>
<ModalBody className={'pr-4'}>
<ModalBody className='pr-4'>
<Form>
<FormGroup>
<Label>{gettext('Page name')}</Label>
Expand Down

0 comments on commit 1857314

Please sign in to comment.