Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
stephensu66 authored and 杨国璇 committed Oct 11, 2024
1 parent be50b2e commit f67adaf
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ class HeaderToolbar extends React.Component {

constructor(props) {
super(props);
const { repoID, filePath } = window.app.pageOptions;
const dirPath = filePath.substring(0, filePath.lastIndexOf('/') || 0) || '/';
this.state = {
repoID: repoID,
filePath: filePath,
dirPath: dirPath,
currentDirent: null,
dirPath: '/',
};
}

Expand Down Expand Up @@ -72,8 +76,8 @@ class HeaderToolbar extends React.Component {
};

getDirentList = () => {
const { repoID, filePath } = window.app.pageOptions;
return seafileAPI.listDir(repoID, this.dirPath, { 'with_thumbnail': true }).then(res => {
const { repoID, filePath, dirPath } = this.state;
return seafileAPI.listDir(repoID, dirPath, { 'with_thumbnail': true }).then(res => {
res.data.dirent_list.forEach(item => {
const dirent = new Dirent(item);
if (Utils.joinPath(item.parent_dir, item.name) === filePath) {
Expand All @@ -86,8 +90,7 @@ class HeaderToolbar extends React.Component {
};

onArticleInfoDetailToggle = () => {
const { repoID, filePath } = window.app.pageOptions;
const { currentDirent } = this.state;
const { repoID, filePath, currentDirent } = this.state;
const repoInfo = { permission: 'rw' };

const eventBus = EventBus.getInstance();
Expand Down Expand Up @@ -151,7 +154,7 @@ class HeaderToolbar extends React.Component {
/>
)}
<ButtonItem
id='info'
id='file-info'
text={gettext('Info')}
icon='info'
onMouseDown={() => {
Expand Down

0 comments on commit f67adaf

Please sign in to comment.