mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
improve code quality
This commit is contained in:
parent
d17d3da6be
commit
fda663d835
@ -8,9 +8,6 @@ import loadable from "@loadable/component"
|
|||||||
|
|
||||||
import { processString } from "utils"
|
import { processString } from "utils"
|
||||||
|
|
||||||
import CSSMotion from "rc-animate/lib/CSSMotion"
|
|
||||||
import useLayoutEffect from "rc-util/lib/hooks/useLayoutEffect"
|
|
||||||
|
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
|
|
||||||
const mediaTypes = {
|
const mediaTypes = {
|
||||||
@ -59,14 +56,6 @@ const ContentFailed = () => {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
const getCurrentHeight = (node) => ({ height: node.offsetHeight })
|
|
||||||
|
|
||||||
const getMaxHeight = (node) => {
|
|
||||||
return { height: node.scrollHeight }
|
|
||||||
}
|
|
||||||
|
|
||||||
const getCollapsedHeight = () => ({ height: 0, opacity: 0 })
|
|
||||||
|
|
||||||
export function PostHeader(props) {
|
export function PostHeader(props) {
|
||||||
const [timeAgo, setTimeAgo] = React.useState(0)
|
const [timeAgo, setTimeAgo] = React.useState(0)
|
||||||
|
|
||||||
@ -397,6 +386,8 @@ export const PostCard = React.memo(({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onDataUpdate = (data) => {
|
const onDataUpdate = (data) => {
|
||||||
|
console.log("onDataUpdate", data)
|
||||||
|
|
||||||
setLikes(data.likes)
|
setLikes(data.likes)
|
||||||
setComments(data.comments)
|
setComments(data.comments)
|
||||||
}
|
}
|
||||||
@ -415,22 +406,17 @@ export const PostCard = React.memo(({
|
|||||||
app.eventBus.emit("style.compactMode", true)
|
app.eventBus.emit("style.compactMode", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
|
||||||
app.eventBus.emit("style.compactMode", false)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
// first listen to post changes
|
// first listen to post changes
|
||||||
window.app.api.namespaces["main"].listenEvent(`post.dataUpdate.${data._id}`, onDataUpdate)
|
window.app.api.namespaces["main"].listenEvent(`post.dataUpdate.${data._id}`, onDataUpdate)
|
||||||
|
|
||||||
// proccess post info
|
|
||||||
// {...}
|
|
||||||
|
|
||||||
// then load
|
// then load
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
if (fullmode) {
|
||||||
|
app.eventBus.emit("style.compactMode", false)
|
||||||
|
}
|
||||||
|
|
||||||
// remove the listener
|
// remove the listener
|
||||||
window.app.api.namespaces["main"].unlistenEvent(`post.dataUpdate.${data._id}`, onDataUpdate)
|
window.app.api.namespaces["main"].unlistenEvent(`post.dataUpdate.${data._id}`, onDataUpdate)
|
||||||
}
|
}
|
||||||
@ -503,42 +489,4 @@ export const PostCard = React.memo(({
|
|||||||
</div>
|
</div>
|
||||||
})
|
})
|
||||||
|
|
||||||
export const PostCardAnimated = (props, ref,) => {
|
|
||||||
const motionRef = React.useRef(false)
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
return () => {
|
|
||||||
if (motionRef.current) {
|
|
||||||
props.onAppear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return <CSSMotion
|
|
||||||
ref={ref}
|
|
||||||
motionName="motion"
|
|
||||||
motionAppear={props.motionAppear}
|
|
||||||
onAppearStart={getCollapsedHeight}
|
|
||||||
onAppearActive={node => {
|
|
||||||
motionRef.current = true
|
|
||||||
return getMaxHeight(node)
|
|
||||||
}}
|
|
||||||
onAppearEnd={props.onAppear}
|
|
||||||
onLeaveStart={getCurrentHeight}
|
|
||||||
onLeaveActive={getCollapsedHeight}
|
|
||||||
onLeaveEnd={() => {
|
|
||||||
props.onLeave(id)
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{(_args, passedMotionRef) => {
|
|
||||||
return <PostCard
|
|
||||||
ref={passedMotionRef}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
}}
|
|
||||||
</CSSMotion>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ForwardedPostCardAnimated = React.forwardRef(PostCardAnimated)
|
|
||||||
|
|
||||||
export default PostCard
|
export default PostCard
|
Loading…
x
Reference in New Issue
Block a user