Skip to content

Commit 904aeed

Browse files
SaraVieiraDanny Ruchtie
andauthored
more polish (codesandbox#3833)
* more polish * more polish * Added text align left First Commit woot Co-authored-by: Danny Ruchtie <[email protected]>
1 parent 74e563e commit 904aeed

File tree

9 files changed

+228
-178
lines changed

9 files changed

+228
-178
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const closeMultiCommentsSelector: Action = ({ state }) => {
142142

143143
export const selectComment: AsyncAction<{
144144
commentId: string;
145-
bounds: {
145+
bounds?: {
146146
left: number;
147147
top: number;
148148
right: number;
@@ -161,6 +161,11 @@ export const selectComment: AsyncAction<{
161161

162162
actions.comments.getComments(commentId);
163163

164+
if (!bounds) {
165+
state.comments.currentCommentId = commentId;
166+
return;
167+
}
168+
164169
if (
165170
comment &&
166171
comment.references.length &&

packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Dialog/Markdown.tsx

Lines changed: 0 additions & 174 deletions
This file was deleted.

packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Dialog/Code.tsx renamed to packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Dialog/Markdown/Code.tsx

File renamed without changes.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import React, { useState } from 'react';
2+
import { useOvermind } from 'app/overmind';
3+
import Modal from 'react-modal';
4+
import { Text, Element, Button, IconButton } from '@codesandbox/components';
5+
import css from '@styled-system/css';
6+
7+
export const Image = props => {
8+
const { state } = useOvermind();
9+
const [modalOpen, setModalOpen] = useState(false);
10+
const privateSandbox =
11+
state.editor.currentSandbox.privacy === 1 ||
12+
state.editor.currentSandbox.privacy === 2;
13+
return privateSandbox ? (
14+
<>
15+
<Button
16+
padding={0}
17+
margin={0}
18+
marginTop={2}
19+
variant="link"
20+
onClick={() => setModalOpen(true)}
21+
css={css({
22+
maxWidth: '100%',
23+
border: 'none',
24+
})}
25+
>
26+
<img
27+
{...props}
28+
alt={props.alt}
29+
css={css({
30+
maxWidth: '100%',
31+
borderRadius: 'small',
32+
})}
33+
/>
34+
</Button>
35+
<Modal
36+
isOpen={modalOpen}
37+
style={{
38+
content: {
39+
border: 'none',
40+
padding: 0,
41+
background: 'transparent',
42+
top: '50%',
43+
left: '50%',
44+
right: 'auto',
45+
bottom: 'auto',
46+
marginRight: '-50%',
47+
transform: 'translate(-50%, -50%)',
48+
},
49+
overlay: {
50+
zIndex: 10,
51+
backgroundColor: 'rgba(0, 0, 0, 0.4)',
52+
},
53+
}}
54+
contentLabel={props.alt}
55+
onRequestClose={() => setModalOpen(false)}
56+
>
57+
<IconButton
58+
name="cross"
59+
size={10}
60+
title="Close Modal"
61+
onClick={() => setModalOpen(false)}
62+
css={{
63+
position: 'absolute',
64+
right: 4,
65+
top: 4,
66+
color: 'white',
67+
}}
68+
/>
69+
<img
70+
{...props}
71+
alt={props.alt}
72+
css={css({
73+
maxWidth: '100%',
74+
borderRadius: 'small',
75+
maxHeight: '80vh',
76+
})}
77+
/>
78+
</Modal>
79+
</>
80+
) : (
81+
<Element
82+
paddingY={4}
83+
marginY={2}
84+
css={css({
85+
backgroundColor: 'sideBar.border',
86+
borderRadius: 'small',
87+
})}
88+
>
89+
<Text size={3} variant="muted" block align="center">
90+
Images are not shown in public sandboxes
91+
</Text>
92+
</Element>
93+
);
94+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { Text, Element } from '@codesandbox/components';
3+
import css from '@styled-system/css';
4+
5+
export const InlineCode = props => (
6+
<Element
7+
as="span"
8+
css={css({
9+
backgroundColor: 'grays.200',
10+
paddingX: '2px',
11+
borderRadius: 'small',
12+
})}
13+
>
14+
<Text
15+
css={css({
16+
color: 'reds.500',
17+
})}
18+
size={3}
19+
as="code"
20+
>
21+
{props.children}
22+
</Text>
23+
</Element>
24+
);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { useOvermind } from 'app/overmind';
3+
import { Link, Button } from '@codesandbox/components';
4+
import css from '@styled-system/css';
5+
6+
export const LinkElement = ({ href, children, ...props }) => {
7+
const { state, actions } = useOvermind();
8+
const { id, alias } = state.editor.currentSandbox;
9+
const commentId = new URLSearchParams(new URL(href).search).get('comment');
10+
if (
11+
href.includes(window.location.href) &&
12+
(href.includes(id) || href.includes(alias)) &&
13+
commentId
14+
) {
15+
return (
16+
<Button
17+
variant="link"
18+
css={css({
19+
display: 'inline',
20+
width: 'auto',
21+
padding: 0,
22+
textAlign: 'left',
23+
})}
24+
onClick={() => actions.comments.selectComment({ commentId })}
25+
>
26+
{children}
27+
</Button>
28+
);
29+
}
30+
31+
if (!href.includes('codesandbox')) {
32+
return (
33+
<Link target="_blank" rel="noopener noreferrer" {...props}>
34+
{children}
35+
</Link>
36+
);
37+
}
38+
39+
return <Link {...props}>{children}</Link>;
40+
};

0 commit comments

Comments
 (0)