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

Add times and move file name #3752

Merged
merged 2 commits into from
Mar 27, 2020
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
28 changes: 28 additions & 0 deletions packages/app/src/app/overmind/namespaces/comments/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommentsFilterOption } from '@codesandbox/common/lib/types';
import { CommentFragment, CommentWithRepliesFragment } from 'app/graphql/types';
import isToday from 'date-fns/isToday';
import { Derive } from 'app/overmind';

export const OPTIMISTIC_COMMENT_ID = 'OptimisticCommentId';
Expand Down Expand Up @@ -27,6 +28,13 @@ type State = {
}>;
}
>;
currentCommentsByDate: Derive<
State,
{
today: CommentFragment[];
prev: CommentFragment[];
}
>;
multiCommentsSelector: {
ids: string[];
x: number;
Expand Down Expand Up @@ -128,4 +136,24 @@ export const state: State = {
return [];
}
},
currentCommentsByDate({ currentComments }) {
return currentComments.reduce(
(acc, comment) => {
if (
isToday(new Date(comment.insertedAt)) ||
isToday(new Date(comment.updatedAt))
) {
acc.today.push(comment);
} else {
acc.prev.push(comment);
}

return acc;
},
{
today: [],
prev: [],
}
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ export const Comment = React.memo<{
});
}}
>
<Link
variant="muted"
css={css({
paddingBottom: 2,
display: 'block',
})}
>
{comment.references[0]
? comment.references[0].metadata.path
: 'General'}
</Link>
<Stack align="flex-start" justify="space-between" marginBottom={4}>
<AvatarBlock comment={comment} />
<Stack align="center">
Expand Down Expand Up @@ -118,11 +129,6 @@ export const Comment = React.memo<{
borderColor: 'sideBar.border',
})}
>
{comment.references[0] && (
<Link style={{ color: '#3793E0' }}>
{comment.references[0].metadata.path}
</Link>
)}
<Text block css={truncateText} marginBottom={2}>
{comment.content}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const Comments: React.FC = () => {
currentComments,
currentCommentId,
multiCommentsSelector,
currentCommentsByDate,
},
},
actions: { comments: commentsActions },
Expand Down Expand Up @@ -111,9 +112,26 @@ export const Comments: React.FC = () => {
overflow: 'auto',
}}
>
{currentComments.map(comment => (
<Comment key={comment.id} comment={comment} />
))}
{currentCommentsByDate.today.length ? (
<>
<Text size={3} weight="bold" block margin={2}>
Today
</Text>
{currentCommentsByDate.today.map(comment => (
<Comment key={comment.id} comment={comment} />
))}
</>
) : null}
{currentCommentsByDate.prev.length ? (
<>
<Text size={3} weight="bold" block margin={2} marginTop={4}>
Earlier
</Text>
{currentCommentsByDate.prev.map(comment => (
<Comment key={comment.id} comment={comment} />
))}
</>
) : null}
</List>
) : null}
</div>
Expand Down