-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Dialog: Replies loader #3781
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
Merged
Merged
Dialog: Replies loader #3781
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0152189
reply loader structure
siddharthkp 39feaf9
add skeleton text component!
siddharthkp e1c7333
use the skeleton in replies
siddharthkp 465ceac
reduce height transitions to 1
siddharthkp 6288474
resize when replies load
siddharthkp 37c7bd6
simplify callback
siddharthkp 3f13333
remove redundant sate
siddharthkp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,19 +19,22 @@ import ReactDOM from 'react-dom'; | |||||||||
| import { AvatarBlock } from '../components/AvatarBlock'; | ||||||||||
| import { EditComment } from '../components/EditComment'; | ||||||||||
| import { Markdown } from './Markdown'; | ||||||||||
| import { Reply } from './Reply'; | ||||||||||
| import { Reply, SkeletonReply } from './Reply'; | ||||||||||
| import { useScrollTop } from './use-scroll-top'; | ||||||||||
|
|
||||||||||
| export const CommentDialog = props => | ||||||||||
| ReactDOM.createPortal(<Dialog {...props} />, document.body); | ||||||||||
|
|
||||||||||
| const DIALOG_WIDTH = 420; | ||||||||||
| const DIALOG_TRANSITION_DURATION = 0.25; | ||||||||||
| const REPLY_TRANSITION_DELAY = 0.25; | ||||||||||
|
|
||||||||||
| export const Dialog: React.FC = () => { | ||||||||||
| const { state } = useOvermind(); | ||||||||||
| const controller = useAnimation(); | ||||||||||
|
|
||||||||||
| const comment = state.comments.currentComment; | ||||||||||
| const replies = comment.comments; | ||||||||||
|
|
||||||||||
| // This comment doens't exist in the database, it's an optimistic comment | ||||||||||
| const isNewComment = comment.id === OPTIMISTIC_COMMENT_ID; | ||||||||||
|
|
@@ -47,6 +50,8 @@ export const Dialog: React.FC = () => { | |||||||||
| // this could rather be `getInitialPosition` | ||||||||||
| const initialPosition = getInitialPosition(currentCommentPositions); | ||||||||||
|
|
||||||||||
| const [repliesRendered, setRepliesRendered] = React.useState(false); | ||||||||||
|
|
||||||||||
| // reset editing when comment changes | ||||||||||
| React.useEffect(() => { | ||||||||||
| setEditing(isNewComment); | ||||||||||
|
|
@@ -67,8 +72,13 @@ export const Dialog: React.FC = () => { | |||||||||
| currentCommentPositions, | ||||||||||
| isCodeComment, | ||||||||||
| isNewComment, | ||||||||||
| repliesRendered, | ||||||||||
| ]); | ||||||||||
|
|
||||||||||
| React.useEffect(() => { | ||||||||||
| setRepliesRendered(false); | ||||||||||
| }, [comment.id]); | ||||||||||
|
|
||||||||||
| const onDragHandlerPan = (deltaX: number, deltaY: number) => { | ||||||||||
| controller.set((_, target) => ({ | ||||||||||
| x: Number(target.x) + deltaX, | ||||||||||
|
|
@@ -84,7 +94,7 @@ export const Dialog: React.FC = () => { | |||||||||
| key={isCodeComment ? 'code' : 'global'} | ||||||||||
| initial={{ ...initialPosition, scale: 0.5, opacity: 0 }} | ||||||||||
| animate={controller} | ||||||||||
| transition={{ duration: 0.25 }} | ||||||||||
| transition={{ duration: DIALOG_TRANSITION_DURATION }} | ||||||||||
| style={{ position: 'absolute', zIndex: 2 }} | ||||||||||
| > | ||||||||||
| <Stack | ||||||||||
|
|
@@ -127,7 +137,12 @@ export const Dialog: React.FC = () => { | |||||||||
| editing={editing} | ||||||||||
| setEditing={setEditing} | ||||||||||
| /> | ||||||||||
| <Replies replies={comment.comments} /> | ||||||||||
| {replies.length ? ( | ||||||||||
| <Replies | ||||||||||
| replies={replies} | ||||||||||
| repliesRenderedCallback={() => setRepliesRendered(true)} | ||||||||||
| /> | ||||||||||
| ) : null} | ||||||||||
| </Stack> | ||||||||||
| <AddReply comment={comment} /> | ||||||||||
| </> | ||||||||||
|
|
@@ -331,13 +346,45 @@ const CommentBody = ({ comment, editing, setEditing }) => { | |||||||||
| ); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const Replies = ({ replies }) => ( | ||||||||||
| <> | ||||||||||
| {replies.map(reply => | ||||||||||
| reply ? <Reply reply={reply} key={reply.id} /> : 'Loading...' | ||||||||||
| )} | ||||||||||
| </> | ||||||||||
| ); | ||||||||||
| const Replies = ({ replies, repliesRenderedCallback }) => { | ||||||||||
| const [isAnimating, setAnimating] = React.useState(true); | ||||||||||
| const repliesLoaded = !!replies[0]; | ||||||||||
|
|
||||||||||
| /** Wait another <delay>ms after the dialog has transitioned into view */ | ||||||||||
| const delay = DIALOG_TRANSITION_DURATION + REPLY_TRANSITION_DELAY; | ||||||||||
| const REPLY_TRANSITION_DURATION = 0.25; | ||||||||||
| const SKELETON_HEIGHT = 146; | ||||||||||
|
|
||||||||||
| React.useEffect(() => { | ||||||||||
| if (repliesLoaded && !isAnimating) repliesRenderedCallback(); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| }, [repliesLoaded, isAnimating, repliesRenderedCallback]); | ||||||||||
|
|
||||||||||
| return ( | ||||||||||
| <motion.div | ||||||||||
| initial={{ height: repliesLoaded ? 0 : SKELETON_HEIGHT }} | ||||||||||
| animate={{ height: 'auto' }} | ||||||||||
| transition={{ | ||||||||||
| delay, | ||||||||||
| duration: REPLY_TRANSITION_DURATION, | ||||||||||
| }} | ||||||||||
| style={{ | ||||||||||
| minHeight: repliesLoaded ? 0 : SKELETON_HEIGHT, | ||||||||||
| overflow: 'visible', | ||||||||||
| }} | ||||||||||
| onAnimationComplete={() => setAnimating(false)} | ||||||||||
| > | ||||||||||
| {repliesLoaded ? ( | ||||||||||
| <> | ||||||||||
| {replies.map(reply => ( | ||||||||||
| <Reply reply={reply} key={reply.id} /> | ||||||||||
| ))} | ||||||||||
| </> | ||||||||||
| ) : ( | ||||||||||
| <SkeletonReply /> | ||||||||||
| )} | ||||||||||
| </motion.div> | ||||||||||
| ); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const AddReply = ({ comment }) => { | ||||||||||
| const { actions } = useOvermind(); | ||||||||||
|
|
||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,52 @@ | ||||
| import styled, { css as styledcss, keyframes } from 'styled-components'; | ||||
| import Color from 'color'; | ||||
| import { Element } from '../Element'; | ||||
|
|
||||
| // export interface ITextProps extends React.HTMLAttributes<HTMLSpanElement> {} | ||||
|
|
||||
|
Comment on lines
+5
to
+6
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| const pulse = keyframes` | ||||
| 0% { background-position: 100% 50%; } | ||||
| 100% { background-position: -100% 50%; } | ||||
| `; | ||||
|
|
||||
| export const SkeletonText = styled(Element)(props => { | ||||
| const color = props.theme.colors.sideBar.border; | ||||
| const themeType = props.theme.type; | ||||
|
|
||||
| /** | ||||
| * This is fun, | ||||
| * We animate the background gradient to create a pulse animation | ||||
| * | ||||
| * To support all themes nicely, we can't really pick a value from the theme | ||||
| * So, we take the sidebar.border and then change it's luminosity | ||||
| * 14% for background and 16% for the pulse highlight on top | ||||
| * We need to set the value to 100 - value for light themes | ||||
| */ | ||||
|
|
||||
| const backgroundLuminosity = themeType === 'light' ? 86 : 14; | ||||
| const highlightLuminosity = themeType === 'light' ? 88 : 16; | ||||
|
|
||||
| // @ts-ignore - we have multiple versions of color in the app | ||||
| // which leads to confusing type checks | ||||
| const [h, s] = Color(color).hsl().color; | ||||
|
|
||||
| const background = Color({ h, s, l: backgroundLuminosity }).string(); | ||||
| const highlight = Color({ h, s, l: highlightLuminosity }).string(); | ||||
|
|
||||
| return styledcss` | ||||
| height: 16px; | ||||
| width: 200px; | ||||
| border-radius: 2px; | ||||
| opacity: 0.7; | ||||
| animation: ${pulse} 4s linear infinite; | ||||
| background: linear-gradient( | ||||
| 90deg, | ||||
| ${background} 0%, | ||||
| ${background} 20%, | ||||
| ${highlight} 50%, | ||||
| ${background} 80%, | ||||
| ${background} 100% | ||||
| ); | ||||
| background-size: 200% 200%; | ||||
| `; | ||||
| }); | ||||
9 changes: 9 additions & 0 deletions
9
packages/components/src/components/SkeletonText/skeleton-text.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import React from 'react'; | ||
| import { SkeletonText } from '.'; | ||
|
|
||
| export default { | ||
| title: 'components/SkeletonText', | ||
| component: SkeletonText, | ||
| }; | ||
|
|
||
| export const Basic = () => <SkeletonText />; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.