Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 = '__OPTIMISTIC_COMMENT_ID__';
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 @@ -119,4 +127,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 @@ -66,6 +66,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 @@ -117,11 +128,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 @@ -24,6 +24,7 @@ export const Comments: React.FC = () => {
currentComments,
currentCommentId,
multiCommentsSelector,
currentCommentsByDate,
},
},
actions: { comments: commentsActions },
Expand Down Expand Up @@ -112,11 +113,30 @@ export const Comments: React.FC = () => {
overflow: 'auto',
}}
>
{currentComments.map(comment =>
comment.id === OPTIMISTIC_COMMENT_ID ? null : (
<Comment key={comment.id} comment={comment} />
)
)}
{currentCommentsByDate.today.length ? (
<>
<Text size={3} weight="bold" block margin={2}>
Today
</Text>
{currentCommentsByDate.today.map(comment =>
comment.id === OPTIMISTIC_COMMENT_ID ? null : (
<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.id === OPTIMISTIC_COMMENT_ID ? null : (
<Comment key={comment.id} comment={comment} />
)
)}
</>
) : null}
</List>
) : null}
</div>
Expand Down