Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { EditComment } from '../components/EditComment';
import { Markdown } from './Markdown';
import { Reply } from './Reply';
import { useScrollTop } from './use-scroll-top';
import { CodeButton } from '../components/CodeButton';

export const CommentDialog = props =>
ReactDOM.createPortal(<Dialog {...props} />, document.body);
Expand All @@ -32,7 +33,7 @@ export const Dialog: React.FC = () => {

const comment = state.comments.currentComment;

// This comment doens't exist in the database, it's an optimistic comment
// This comment doesn't exist in the database, it's an optimistic comment
const isNewComment = comment.id === OPTIMISTIC_COMMENT_ID;

const [editing, setEditing] = useState(isNewComment);
Expand Down Expand Up @@ -166,26 +167,42 @@ const DialogAddComment = ({ comment, onSave }) => {
onClick={closeDialog}
/>
</Stack>
<Textarea
autosize
autoFocus
css={css({
overflow: 'hidden',
border: 'none',
display: 'block',
borderTop: '1px solid',
borderColor: 'sideBar.border',
})}
value={value}
onChange={e => setValue(e.target.value)}
placeholder="Add comment..."
onKeyDown={async event => {
if (event.keyCode === ENTER && !event.shiftKey) {
saveComment();
event.preventDefault();
}
}}
/>
<Element css={css({ position: 'relative' })}>
<Textarea
autosize
autoFocus
css={css({
overflow: 'hidden',
border: 'none',
display: 'block',
borderTop: '1px solid',
borderColor: 'sideBar.border',
paddingRight: 10,
})}
value={value}
onChange={e => setValue(e.target.value)}
placeholder="Add comment..."
onKeyDown={async event => {
if (event.keyCode === ENTER && !event.shiftKey) {
saveComment();
event.preventDefault();
}
}}
/>
<CodeButton
onClick={() => {
setValue(
value +
`
\`\`\`


\`\`\`
`
);
}}
/>
</Element>
</Stack>
);
};
Expand Down Expand Up @@ -326,22 +343,38 @@ const AddReply = ({ comment }) => {
};

return (
<Textarea
autosize
css={css({
overflow: 'hidden',
border: 'none',
display: 'block',
borderTop: '1px solid',
borderColor: 'sideBar.border',
})}
value={value}
onChange={e => setValue(e.target.value)}
placeholder="Reply..."
onKeyDown={event => {
if (event.keyCode === ENTER && !event.shiftKey) onSubmit();
}}
/>
<Element css={css({ position: 'relative' })}>
<Textarea
autosize
css={css({
overflow: 'hidden',
border: 'none',
display: 'block',
borderTop: '1px solid',
borderColor: 'sideBar.border',
paddingRight: 10,
})}
value={value}
onChange={e => setValue(e.target.value)}
placeholder="Reply..."
onKeyDown={event => {
if (event.keyCode === ENTER && !event.shiftKey) onSubmit();
}}
/>
<CodeButton
onClick={() => {
setValue(
value +
`
\`\`\`


\`\`\`
`
);
}}
/>
</Element>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { Element } from '@codesandbox/components';
import css from '@styled-system/css';

const CodeIcon = props => (
<svg width={56} height={56} fill="none" viewBox="0 0 56 56" {...props}>
<path
fill="#999"
fillRule="evenodd"
d="M29.529 36l-1.386-.32L32.365 20l1.386.32L29.529 36zM21 27.936l4.976-5.291 1.244 1.323-3.732 3.968 3.732 3.968-1.244 1.323L21 27.937zm20 0l-4.976 5.291-1.243-1.322 3.731-3.969-3.731-3.968 1.243-1.323L41 27.936z"
clipRule="evenodd"
/>
</svg>
);

export const CodeButton = ({ onClick }) => (
<Element
css={css({
cursor: 'pointer',
position: 'absolute',
bottom: 0,
right: 0,
border: 'none',
backgroundColor: 'transparent',
padding: 0,
})}
as="button"
>
<CodeIcon onClick={onClick} />
</Element>
);