Skip to content

Commit d34292d

Browse files
authored
Add Ability to close the multi comment selector (codesandbox#3793)
* add close to multi comment * delete comment * remove button * fix text align
1 parent 192ddfa commit d34292d

File tree

2 files changed

+62
-51
lines changed
  • packages/app/src/app

2 files changed

+62
-51
lines changed

packages/app/src/app/overmind/namespaces/comments/actions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ export const closeComment: Action = ({ state }) => {
122122
state.comments.currentCommentPositions = null;
123123
};
124124

125+
export const closeMultiCommentsSelector: Action = ({ state }) => {
126+
state.comments.multiCommentsSelector = null;
127+
};
128+
125129
export const selectComment: AsyncAction<{
126130
commentId: string;
127131
bounds: {
@@ -131,8 +135,7 @@ export const selectComment: AsyncAction<{
131135
bottom: number;
132136
};
133137
}> = async ({ state, effects, actions }, { commentId, bounds }) => {
134-
// Should close from somewhere else probably
135-
state.comments.multiCommentsSelector = null;
138+
actions.comments.closeMultiCommentsSelector();
136139

137140
const sandbox = state.editor.currentSandbox;
138141

packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/components/MultiComment.tsx

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Element, Text } from '@codesandbox/components';
2+
import OutsideClickHandler from 'react-outside-click-handler';
23
import { css } from '@styled-system/css';
34
import { useOvermind } from 'app/overmind';
45
import { formatDistanceStrict } from 'date-fns';
@@ -69,6 +70,7 @@ export const MultiComment = ({ x, y, ids }: MultiCommentProps) => {
6970
width: 200,
7071
cursor: 'pointer',
7172
position: 'relative',
73+
textAlign: 'left',
7274
'&:hover': {
7375
color: 'list.hoverForeground',
7476
backgroundColor: 'list.hoverBackground',
@@ -85,57 +87,63 @@ export const MultiComment = ({ x, y, ids }: MultiCommentProps) => {
8587
);
8688

8789
return (
88-
<Element as="ul" css={list}>
89-
{ids
90-
.map(id => comments.comments[editor.currentSandbox.id][id])
91-
.sort((commentA, commentB) => {
92-
const dateA = new Date(commentA.insertedAt);
93-
const dateB = new Date(commentB.insertedAt);
94-
if (dateA < dateB) {
95-
return 1;
96-
}
90+
<Element css={css({ position: 'absolute' })}>
91+
<OutsideClickHandler
92+
onOutsideClick={() => actions.comments.closeMultiCommentsSelector()}
93+
>
94+
<Element as="ul" css={list}>
95+
{ids
96+
.map(id => comments.comments[editor.currentSandbox.id][id])
97+
.sort((commentA, commentB) => {
98+
const dateA = new Date(commentA.insertedAt);
99+
const dateB = new Date(commentB.insertedAt);
100+
if (dateA < dateB) {
101+
return 1;
102+
}
97103

98-
if (dateA > dateB) {
99-
return -1;
100-
}
104+
if (dateA > dateB) {
105+
return -1;
106+
}
101107

102-
return 0;
103-
})
104-
.map(comment => (
105-
<Element as="li" key={comment.id}>
106-
<Element
107-
as="button"
108-
type="button"
109-
onClick={event => {
110-
const bounds = event.currentTarget.getBoundingClientRect();
111-
actions.comments.selectComment({
112-
commentId: comment.id,
113-
bounds: {
114-
left: bounds.left,
115-
right: bounds.right,
116-
top: bounds.top,
117-
bottom: bounds.bottom,
118-
},
119-
});
120-
}}
121-
css={item}
122-
>
123-
<Text
124-
size={2}
125-
weight="bold"
126-
paddingRight={2}
127-
css={css({
128-
color: 'sideBar.foreground',
129-
})}
130-
>
131-
{comment.user.username}
132-
</Text>
133-
<Text size={2} variant="muted">
134-
{date(comment)}
135-
</Text>
136-
</Element>
137-
</Element>
138-
))}
108+
return 0;
109+
})
110+
.map(comment => (
111+
<Element as="li" key={comment.id}>
112+
<Element
113+
as="button"
114+
type="button"
115+
onClick={event => {
116+
const bounds = event.currentTarget.getBoundingClientRect();
117+
actions.comments.selectComment({
118+
commentId: comment.id,
119+
bounds: {
120+
left: bounds.left,
121+
right: bounds.right,
122+
top: bounds.top,
123+
bottom: bounds.bottom,
124+
},
125+
});
126+
}}
127+
css={item}
128+
>
129+
<Text
130+
size={2}
131+
weight="bold"
132+
paddingRight={2}
133+
css={css({
134+
color: 'sideBar.foreground',
135+
})}
136+
>
137+
{comment.user.username}
138+
</Text>
139+
<Text size={2} variant="muted">
140+
{date(comment)}
141+
</Text>
142+
</Element>
143+
</Element>
144+
))}
145+
</Element>
146+
</OutsideClickHandler>
139147
</Element>
140148
);
141149
};

0 commit comments

Comments
 (0)