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

Bugfix/render optimization #327

Merged
merged 15 commits into from
Aug 26, 2021
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
83 changes: 34 additions & 49 deletions packages/asc-web-common/components/PageLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ class PageLayout extends React.Component {
constructor(props) {
super(props);

const isArticleVisibleAndPinned = !!this.props.isArticlePinned;

this.state = {
isBackdropVisible: false,
isArticleVisible: isArticleVisibleAndPinned,
isArticlePinned: isArticleVisibleAndPinned,
};

this.timeoutHandler = null;
this.intervalHandler = null;

Expand All @@ -95,13 +87,9 @@ class PageLayout extends React.Component {
}

if (
(this.props.hideAside &&
!this.state.isArticlePinned &&
this.props.hideAside !== prevProps.hideAside) ||
(this.props.isLoading !== prevProps.isLoading &&
this.props.isLoaded &&
this.state.isArticleVisible &&
!this.state.isArticlePinned)
this.props.hideAside &&
!this.props.isArticlePinned &&
this.props.hideAside !== prevProps.hideAside
) {
this.backdropClick();
}
Expand Down Expand Up @@ -136,42 +124,30 @@ class PageLayout extends React.Component {
};

backdropClick = () => {
this.setState({
isBackdropVisible: false,
isArticleVisible: false,
isArticlePinned: false,
});
this.props.setArticlePinned(false);
this.props.setIsBackdropVisible(false);
this.props.setIsArticleVisible(false);
isMobile && this.props.setArticleVisibleOnUnpin(false);
};

pinArticle = () => {
this.setState({
isBackdropVisible: false,
isArticlePinned: true,
isArticleVisible: true,
});

this.props.setIsBackdropVisible(false);
this.props.setIsArticleVisible(true);
this.props.setArticlePinned(true);
isMobile && this.props.setArticleVisibleOnUnpin(false);
};

unpinArticle = () => {
this.setState({
isBackdropVisible: true,
isArticlePinned: false,
isArticleVisible: true,
});

this.props.setIsBackdropVisible(true);
this.props.setIsArticleVisible(true);
this.props.setArticlePinned(false);
isMobile && this.props.setArticleVisibleOnUnpin(true);
};

showArticle = () => {
this.setState({
isBackdropVisible: true,
isArticleVisible: true,
isArticlePinned: false,
});
this.props.setArticlePinned(false);
this.props.setIsBackdropVisible(true);
this.props.setIsArticleVisible(true);
isMobile && this.props.setArticleVisibleOnUnpin(true);
};

Expand Down Expand Up @@ -221,8 +197,10 @@ class PageLayout extends React.Component {
onOpenUploadPanel,
isTabletView,
firstLoad,
isLoading,
dragging,
isArticleVisible,
isBackdropVisible,
isArticlePinned,
} = this.props;
let articleHeaderContent = null;
let articleMainButtonContent = null;
Expand Down Expand Up @@ -291,17 +269,16 @@ class PageLayout extends React.Component {
{isBackdropAvailable && (
<Backdrop
zIndex={400}
visible={this.state.isBackdropVisible}
visible={isBackdropVisible}
onClick={this.backdropClick}
/>
)}
{isArticleAvailable && (
<Article
visible={this.state.isArticleVisible}
pinned={this.state.isArticlePinned}
visible={isArticleVisible}
pinned={isArticlePinned}
isLoaded={isLoaded}
firstLoad={firstLoad}
isLoading={!isLoading}
>
{isArticleHeaderAvailable && (
<SubArticleHeader>
Expand All @@ -318,15 +295,15 @@ class PageLayout extends React.Component {
</SubArticleMainButton>
)}
{isArticleBodyAvailable && (
<SubArticleBody pinned={this.state.isArticlePinned}>
<SubArticleBody pinned={isArticlePinned}>
{articleBodyContent
? articleBodyContent.props.children
: null}
</SubArticleBody>
)}
{isArticleBodyAvailable && (
<ArticlePinPanel
pinned={this.state.isArticlePinned}
pinned={isArticlePinned}
onPin={this.pinArticle}
onUnpin={this.unpinArticle}
/>
Expand All @@ -349,12 +326,12 @@ class PageLayout extends React.Component {
<Section
widthProp={width}
unpinArticle={this.unpinArticle}
pinned={this.state.isArticlePinned}
pinned={isArticlePinned}
>
{isSectionHeaderAvailable && (
<SubSectionHeader
isHeaderVisible={isHeaderVisible}
isArticlePinned={this.state.isArticlePinned}
isArticlePinned={isArticlePinned}
>
{sectionHeaderContent
? sectionHeaderContent.props.children
Expand Down Expand Up @@ -386,7 +363,7 @@ class PageLayout extends React.Component {
uploadFiles={uploadFiles}
withScroll={withBodyScroll}
autoFocus={isMobile || isTabletView ? false : true}
pinned={this.state.isArticlePinned}
pinned={isArticlePinned}
viewAs={viewAs}
>
{isSectionFilterAvailable && (
Expand Down Expand Up @@ -449,7 +426,7 @@ class PageLayout extends React.Component {

{isArticleAvailable && (
<SectionToggler
visible={!this.state.isArticleVisible}
visible={!isArticleVisible}
onClick={this.showArticle}
/>
)}
Expand Down Expand Up @@ -519,7 +496,6 @@ PageLayout.propTypes = {
isTabletView: PropTypes.bool,
isHeaderVisible: PropTypes.bool,
firstLoad: PropTypes.bool,
isLoading: PropTypes.bool,
};

PageLayout.defaultProps = {
Expand All @@ -541,15 +517,24 @@ export default inject(({ auth }) => {
isHeaderVisible,
isTabletView,
isArticlePinned,
isArticleVisible,
isBackdropVisible,
setArticlePinned,
setArticleVisibleOnUnpin,
setIsArticleVisible,
setIsBackdropVisible,
} = settingsStore;

return {
isLoaded,
isTabletView,
isHeaderVisible,
isArticlePinned,
isArticleVisible,
setArticlePinned,
setArticleVisibleOnUnpin,
setIsArticleVisible,
isBackdropVisible,
setIsBackdropVisible,
};
})(observer(PageLayout));
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const StyledArticle = styled.article`
? props.pinned
? `
min-width: 240px;
max-width: ${props.isLoading ? "calc(100vw - 368px)" : "240px"};
max-width: 240px;


.increaseHeight {
Expand Down
15 changes: 15 additions & 0 deletions packages/asc-web-common/store/SettingsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class SettingsStore {
isTabletView = false;
isArticlePinned =
localStorage.getItem(ARTICLE_PINNED_KEY) === "true" || false;
isArticleVisible = false;
isBackdropVisible = false;

isArticleVisibleOnUnpin = false;

Expand Down Expand Up @@ -105,6 +107,19 @@ class SettingsStore {
return `https://helpcenter.onlyoffice.com/${lang}/administration/configuration.aspx#CustomizingPortal_block`;
}

setIsArticleVisible = (visible) => {
this.isArticleVisible = this.isArticlePinned ? true : visible;
};

setIsBackdropVisible = (visible) => {
this.isBackdropVisible = visible;
};

hideArticle = () => {
this.setIsArticleVisible(false);
this.setIsBackdropVisible(false);
};

setValue = (key, value) => {
this[key] = value;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class TreeFolders extends React.Component {
return false;
}

if (draggableItems.find((x) => x.id === item.id)) return false;
if (!draggableItems || draggableItems.find((x) => x.id === item.id))
return false;

// const isMy = rootFolderType === FolderType.USER;
// const isCommon = rootFolderType === FolderType.COMMON;
Expand Down Expand Up @@ -472,7 +473,10 @@ TreeFolders.defaultProps = {
};

export default inject(
({ auth, filesStore, treeFoldersStore, selectedFolderStore }) => {
(
{ auth, filesStore, treeFoldersStore, selectedFolderStore },
{ useDefaultSelectedKeys, selectedKeys }
) => {
const {
filter,
selection,
Expand Down Expand Up @@ -504,9 +508,12 @@ export default inject(
commonId: commonFolderId,
isPrivacy: isPrivacyFolder,
filter,
draggableItems: dragging ? selection : [],
draggableItems: dragging ? selection : null,
expandedKeys,
treeFolders,
selectedKeys: useDefaultSelectedKeys
? treeFoldersStore.selectedKeys
: selectedKeys,

setDragging,
setIsLoading,
Expand Down
Loading