diff --git a/packages/app/src/app/overmind/namespaces/comments/state.ts b/packages/app/src/app/overmind/namespaces/comments/state.ts
index 68d4af8a697..4ed9f3a32f4 100644
--- a/packages/app/src/app/overmind/namespaces/comments/state.ts
+++ b/packages/app/src/app/overmind/namespaces/comments/state.ts
@@ -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';
@@ -27,6 +28,13 @@ type State = {
}>;
}
>;
+ currentCommentsByDate: Derive<
+ State,
+ {
+ today: CommentFragment[];
+ prev: CommentFragment[];
+ }
+ >;
multiCommentsSelector: {
ids: string[];
x: number;
@@ -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: [],
+ }
+ );
+ },
};
diff --git a/packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Comment.tsx b/packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Comment.tsx
index cdb10b30db1..ba33113f58c 100644
--- a/packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Comment.tsx
+++ b/packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Comment.tsx
@@ -67,6 +67,17 @@ export const Comment = React.memo<{
});
}}
>
+
+ {comment.references[0]
+ ? comment.references[0].metadata.path
+ : 'General'}
+
@@ -118,11 +129,6 @@ export const Comment = React.memo<{
borderColor: 'sideBar.border',
})}
>
- {comment.references[0] && (
-
- {comment.references[0].metadata.path}
-
- )}
{comment.content}
diff --git a/packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/index.tsx b/packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/index.tsx
index 0d26a408c99..109b22f0e87 100644
--- a/packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/index.tsx
+++ b/packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/index.tsx
@@ -23,6 +23,7 @@ export const Comments: React.FC = () => {
currentComments,
currentCommentId,
multiCommentsSelector,
+ currentCommentsByDate,
},
},
actions: { comments: commentsActions },
@@ -111,9 +112,26 @@ export const Comments: React.FC = () => {
overflow: 'auto',
}}
>
- {currentComments.map(comment => (
-
- ))}
+ {currentCommentsByDate.today.length ? (
+ <>
+
+ Today
+
+ {currentCommentsByDate.today.map(comment => (
+
+ ))}
+ >
+ ) : null}
+ {currentCommentsByDate.prev.length ? (
+ <>
+
+ Earlier
+
+ {currentCommentsByDate.prev.map(comment => (
+
+ ))}
+ >
+ ) : null}
) : null}