mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
fix post visibility & optimization
This commit is contained in:
parent
3b5b21fb19
commit
7c7fedd339
@ -35,6 +35,8 @@ export class PostsListsComponent extends React.Component {
|
|||||||
resumingLoading: false,
|
resumingLoading: false,
|
||||||
initialLoading: true,
|
initialLoading: true,
|
||||||
|
|
||||||
|
topVisible: true,
|
||||||
|
|
||||||
realtimeUpdates: true,
|
realtimeUpdates: true,
|
||||||
|
|
||||||
hasMore: true,
|
hasMore: true,
|
||||||
@ -187,18 +189,38 @@ export class PostsListsComponent extends React.Component {
|
|||||||
onScrollList = (e) => {
|
onScrollList = (e) => {
|
||||||
const { scrollTop } = e.target
|
const { scrollTop } = e.target
|
||||||
|
|
||||||
if (this.state.resumingLoading) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Scrolling => ", scrollTop)
|
console.log("Scrolling => ", scrollTop)
|
||||||
|
|
||||||
if (scrollTop > 200) {
|
if (scrollTop > 200) {
|
||||||
|
if (this.state.topVisible) {
|
||||||
|
this.setState({
|
||||||
|
topVisible: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (typeof this.props.onTopVisibility === "function") {
|
||||||
|
this.props.onTopVisibility(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.props.realtime || this.state.resumingLoading) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
realtimeUpdates: false,
|
realtimeUpdates: false,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (!this.state.realtimeUpdates && !this.state.resumingLoading) {
|
if (!this.state.topVisible) {
|
||||||
|
this.setState({
|
||||||
|
topVisible: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (typeof this.props.onTopVisibility === "function") {
|
||||||
|
this.props.onTopVisibility(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.props.realtime || !this.state.realtimeUpdates && !this.state.resumingLoading) {
|
||||||
this.onResumeRealtimeUpdates()
|
this.onResumeRealtimeUpdates()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,10 +249,8 @@ export class PostsListsComponent extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.realtime) {
|
if (this.listRef && this.listRef.current) {
|
||||||
if (this.listRef && this.listRef.current) {
|
this.listRef.current.addEventListener("scroll", this.onScrollList)
|
||||||
this.listRef.current.addEventListener("scroll", this.onScrollList)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window._hacks = this._hacks
|
window._hacks = this._hacks
|
||||||
@ -251,10 +271,8 @@ export class PostsListsComponent extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.realtime) {
|
if (this.listRef && this.listRef.current) {
|
||||||
if (this.listRef && this.listRef.current) {
|
this.listRef.current.removeEventListener("scroll", this.onScrollList)
|
||||||
this.listRef.current.removeEventListener("scroll", this.onScrollList)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window._hacks = null
|
window._hacks = null
|
||||||
|
@ -44,9 +44,7 @@ const TabRender = React.memo((props, ref) => {
|
|||||||
// forwards ref to the tab
|
// forwards ref to the tab
|
||||||
return <div className={classnames("fade-opacity-active", { "fade-opacity-leave": transitionActive })}>
|
return <div className={classnames("fade-opacity-active", { "fade-opacity-leave": transitionActive })}>
|
||||||
{
|
{
|
||||||
React.createElement(Tab, {
|
React.createElement(Tab, props)
|
||||||
...props,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
})
|
})
|
||||||
@ -66,6 +64,8 @@ export default class Account extends React.Component {
|
|||||||
isNotExistent: false,
|
isNotExistent: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profileRef = React.createRef()
|
||||||
|
|
||||||
contentRef = React.createRef()
|
contentRef = React.createRef()
|
||||||
|
|
||||||
coverComponent = React.createRef()
|
coverComponent = React.createRef()
|
||||||
@ -133,27 +133,15 @@ export default class Account extends React.Component {
|
|||||||
isFollowed,
|
isFollowed,
|
||||||
followers,
|
followers,
|
||||||
})
|
})
|
||||||
|
|
||||||
// create intersection observer for cover
|
|
||||||
this.coverIntersectionObserver = new IntersectionObserver((e) => {
|
|
||||||
if (e[0].intersectionRatio > 0) {
|
|
||||||
this.leftPanelRef.current.style.transform = "translate(0, -100px)"
|
|
||||||
this.actionsRef.current.style.opacity = "1"
|
|
||||||
} else {
|
|
||||||
this.leftPanelRef.current.style.transform = "translate(0, 0)"
|
|
||||||
this.actionsRef.current.style.opacity = "0"
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
root: document.querySelector("#root"),
|
|
||||||
threshold: 0
|
|
||||||
})
|
|
||||||
|
|
||||||
this.coverIntersectionObserver.observe(this.coverComponent.current)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount = () => {
|
onPostListTopVisibility = (to) => {
|
||||||
if (this.coverIntersectionObserver) {
|
console.log("onPostListTopVisibility", to)
|
||||||
this.coverIntersectionObserver.disconnect()
|
|
||||||
|
if (to) {
|
||||||
|
this.profileRef.current.classList.remove("topHidden")
|
||||||
|
} else {
|
||||||
|
this.profileRef.current.classList.add("topHidden")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,6 +173,8 @@ export default class Account extends React.Component {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.onPostListTopVisibility(true)
|
||||||
|
|
||||||
key = key.toLowerCase()
|
key = key.toLowerCase()
|
||||||
|
|
||||||
if (this.state.tabActiveKey === key) {
|
if (this.state.tabActiveKey === key) {
|
||||||
@ -213,6 +203,7 @@ export default class Account extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return <div
|
return <div
|
||||||
|
ref={this.profileRef}
|
||||||
className="accountProfile"
|
className="accountProfile"
|
||||||
id="profile"
|
id="profile"
|
||||||
>
|
>
|
||||||
@ -257,6 +248,7 @@ export default class Account extends React.Component {
|
|||||||
<TabRender
|
<TabRender
|
||||||
renderKey={this.state.tabActiveKey}
|
renderKey={this.state.tabActiveKey}
|
||||||
state={this.state}
|
state={this.state}
|
||||||
|
onTopVisibility={this.onPostListTopVisibility}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -8,6 +8,27 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
|
&.topHidden {
|
||||||
|
.cover {
|
||||||
|
height: 0;
|
||||||
|
min-height: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panels {
|
||||||
|
padding-top: 0;
|
||||||
|
|
||||||
|
.leftPanel {
|
||||||
|
transform: translate(0, 0);
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.cover {
|
.cover {
|
||||||
z-index: 50;
|
z-index: 50;
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -47,6 +68,8 @@
|
|||||||
|
|
||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
|
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
.leftPanel {
|
.leftPanel {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
@ -60,6 +83,8 @@
|
|||||||
|
|
||||||
transition: all 0.3s ease-in-out;
|
transition: all 0.3s ease-in-out;
|
||||||
|
|
||||||
|
transform: translate(0, -100px);
|
||||||
|
|
||||||
.userCard {
|
.userCard {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
@ -88,6 +113,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
.fade-opacity-active {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.tabMenuWrapper {
|
.tabMenuWrapper {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -18,14 +18,13 @@ const emptyListRender = () => {
|
|||||||
|
|
||||||
export default class UserPosts extends React.Component {
|
export default class UserPosts extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return <div className="userPosts">
|
return <PostsList
|
||||||
<PostsList
|
onTopVisibility={this.props.onTopVisibility}
|
||||||
emptyListRender={emptyListRender}
|
emptyListRender={emptyListRender}
|
||||||
loadFromModel={PostModel.getUserPosts}
|
loadFromModel={PostModel.getUserPosts}
|
||||||
loadFromModelProps={{
|
loadFromModelProps={{
|
||||||
user_id: this.props.state.user._id,
|
user_id: this.props.state.user._id,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user