Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edit page UI #6083

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/src/pages/wiki2/css/add-new-page-dialog.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.add-new-page-dialog .modal-footer .loading-icon {
margin: 0;
}
17 changes: 16 additions & 1 deletion frontend/src/pages/wiki2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ class Wiki extends Component {
getWikiConfig = () => {
wikiAPI.getWiki2Config(wikiId).then(res => {
const { wiki_config, repo_id } = res.data.wiki;
const config = new WikiConfig(JSON.parse(wiki_config) || {});
this.setState({
config: new WikiConfig(JSON.parse(wiki_config) || {}),
config,
isConfigLoading: false,
repoId: repo_id,
}, () => {
const pageId = this.getFirstPageId(config);
if (pageId) {
this.setCurrentPage(pageId);
}
});
}).catch((error) => {
let errorMsg = Utils.getErrorMsg(error);
Expand All @@ -107,6 +113,15 @@ class Wiki extends Component {
});
};

getFirstPageId = (config) => {
const item = config.navigation[0] || {};
if (item.type === 'page') {
return item.id;
} else if (item.type === 'folder') {
return item.children[0].id;
}
};

loadSidePanel = (initialPath) => {
if (hasIndex) {
this.loadIndexNode();
Expand Down
27 changes: 19 additions & 8 deletions frontend/src/pages/wiki2/view-structure/add-new-page-dialog.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalHeader, ModalBody, ModalFooter, Form, FormGroup, Label, Input, Button } from 'reactstrap';
import { Modal, ModalHeader, ModalBody, ModalFooter, Label, Input, Button } from 'reactstrap';
import { gettext, repoID } from '../../../utils/constants';
import { seafileAPI } from '../../../utils/seafile-api';
import { Utils } from '../../../utils/utils';
import toaster from '../../../components/toast';
import Loading from '../../../components/loading';

import '../css/add-new-page-dialog.css';

const propTypes = {
toggle: PropTypes.func.isRequired,
onAddNewPage: PropTypes.func,
Expand Down Expand Up @@ -56,6 +58,13 @@ class AddNewPageDialog extends React.Component {
}
};

handleKeyDown = (e) => {
if (e.keyCode === 13) {
e.preventDefault();
this.onSubmit();
}
};

toggle = () => {
this.props.toggle();
};
Expand Down Expand Up @@ -111,15 +120,17 @@ class AddNewPageDialog extends React.Component {

render() {
return (
<Modal isOpen={true} toggle={this.toggle} autoFocus={false}>
<Modal isOpen={true} toggle={this.toggle} autoFocus={false} className='add-new-page-dialog'>
<ModalHeader toggle={this.toggle}>{gettext('Add page')}</ModalHeader>
<ModalBody className='pr-4'>
<Form>
<FormGroup>
<Label>{gettext('Page name')}</Label>
<Input value={this.state.pageName} onChange={this.handleChange} autoFocus={true} />
</FormGroup>
</Form>
<Label>{gettext('Page name')}</Label>
<Input
className="mb-4"
value={this.state.pageName}
onChange={this.handleChange}
autoFocus={true}
onKeyDown={this.handleKeyDown}
/>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
Expand Down
Loading