1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 10:50:24 +00:00

style: optimize code

This commit is contained in:
liuhongbo
2024-06-11 17:21:11 +08:00
parent be3b792852
commit 2d4d8ed0ff
3 changed files with 11 additions and 2 deletions

View File

@@ -39,17 +39,21 @@ class Wiki extends Component {
assets_url: '', assets_url: '',
}; };
} }
UNSAFE_componentWillMount() { UNSAFE_componentWillMount() {
if (!Utils.isDesktop()) { if (!Utils.isDesktop()) {
this.setState({ closeSideBar: true }); this.setState({ closeSideBar: true });
} }
} }
componentDidMount() { componentDidMount() {
this.getWikiConfig(); this.getWikiConfig();
} }
handlePath = () => { handlePath = () => {
return isWiki2 ? 'wikis/' : 'published/'; return isWiki2 ? 'wikis/' : 'published/';
}; };
getWikiConfig = () => { getWikiConfig = () => {
wikiAPI.getWiki2Config(wikiId).then(res => { wikiAPI.getWiki2Config(wikiId).then(res => {
const { wiki_config, repo_id } = res.data.wiki; const { wiki_config, repo_id } = res.data.wiki;
@@ -85,6 +89,7 @@ class Wiki extends Component {
onError && onError(); onError && onError();
}); });
}; };
getFirstPageId = (config) => { getFirstPageId = (config) => {
if (!config || !Array.isArray(config.navigation)) return ''; if (!config || !Array.isArray(config.navigation)) return '';
for (let i = 0; i < config.navigation.length; i++) { for (let i = 0; i < config.navigation.length; i++) {
@@ -97,6 +102,7 @@ class Wiki extends Component {
} }
} }
}; };
getSdocFileContent = (docUuid, accessToken) => { getSdocFileContent = (docUuid, accessToken) => {
const config = { const config = {
docUuid, docUuid,
@@ -114,9 +120,11 @@ class Wiki extends Component {
toaster.danger(errorMsg); toaster.danger(errorMsg);
}); });
}; };
onCloseSide = () => { onCloseSide = () => {
this.setState({ closeSideBar: !this.state.closeSideBar }); this.setState({ closeSideBar: !this.state.closeSideBar });
}; };
showPage = (pageId, filePath) => { showPage = (pageId, filePath) => {
this.setState({ this.setState({
isDataLoading: true, isDataLoading: true,
@@ -142,6 +150,7 @@ class Wiki extends Component {
const fileUrl = `${siteRoot}${this.handlePath()}${wikiId}/?${params.toString()}`; const fileUrl = `${siteRoot}${this.handlePath()}${wikiId}/?${params.toString()}`;
window.history.pushState({ url: fileUrl, path: filePath }, filePath, fileUrl); window.history.pushState({ url: fileUrl, path: filePath }, filePath, fileUrl);
}; };
setCurrentPage = (pageId, callback) => { setCurrentPage = (pageId, callback) => {
const { currentPageId, config } = this.state; const { currentPageId, config } = this.state;
if (pageId === currentPageId) { if (pageId === currentPageId) {
@@ -162,6 +171,7 @@ class Wiki extends Component {
callback && callback(); callback && callback();
}); });
}; };
onUpdatePage = (pageId, newPage) => { onUpdatePage = (pageId, newPage) => {
if (newPage.name === '') { if (newPage.name === '') {
toaster.danger(gettext('Page name cannot be empty')); toaster.danger(gettext('Page name cannot be empty'));

View File

@@ -36,7 +36,6 @@ function getPaths(navigation, currentPageId, pages) {
} }
function WikiTopNav({ config, currentPageId }) { function WikiTopNav({ config, currentPageId }) {
console.log('config in wiki top nav',config)
const { navigation, pages } = config; const { navigation, pages } = config;
const paths = getPaths(navigation, currentPageId, pages); const paths = getPaths(navigation, currentPageId, pages);
return ( return (