|
1 | 1 | import React from 'react'; |
2 | 2 | import ReactMarkdown from 'react-markdown'; |
| 3 | +import { useOvermind } from 'app/overmind'; |
3 | 4 | import { Text, Element, Link } from '@codesandbox/components'; |
4 | 5 | import css from '@styled-system/css'; |
5 | 6 | import { Code } from './Code'; |
6 | 7 |
|
7 | | -const image = props => ( |
8 | | - <img |
9 | | - {...props} |
10 | | - alt={props.alt} |
11 | | - css={css({ |
12 | | - maxWidth: '100%', |
13 | | - })} |
14 | | - /> |
15 | | -); |
| 8 | +export const Comment = ({ source }) => { |
| 9 | + const { state } = useOvermind(); |
| 10 | + const privateSandbox = |
| 11 | + state.editor.currentSandbox.privacy === 1 || |
| 12 | + state.editor.currentSandbox.privacy === 2; |
16 | 13 |
|
17 | | -export const Comment = ({ source }) => ( |
18 | | - <Element |
19 | | - paddingX={4} |
20 | | - paddingBottom={6} |
21 | | - css={css({ |
22 | | - 'ul, ol': { |
23 | | - paddingLeft: 0, |
24 | | - fontSize: 13, |
25 | | - }, |
26 | | - 'ol li': { |
27 | | - counterIncrement: 'counter', |
28 | | - }, |
29 | | - 'ol li::before': { |
30 | | - color: 'mutedForeground', |
31 | | - content: "counter(counter) '. '", |
32 | | - }, |
33 | | - li: { |
34 | | - listStyle: 'none', |
35 | | - }, |
36 | | - 'li:before': { |
37 | | - content: "'•'", |
38 | | - color: 'mutedForeground', |
39 | | - paddingRight: '0.5em', |
40 | | - }, |
41 | | - })} |
42 | | - > |
43 | | - <ReactMarkdown |
44 | | - source={source} |
45 | | - renderers={{ |
46 | | - text: ({ children }) => ( |
47 | | - <Text variant="muted" size={13}> |
48 | | - {children} |
49 | | - </Text> |
50 | | - ), |
51 | | - heading: ({ children }) => ( |
52 | | - <Text block variant="muted" size={13}> |
53 | | - {children} |
54 | | - </Text> |
55 | | - ), |
56 | | - code: props => <Code {...props} />, |
57 | | - link: props => <Link {...props}>{props.children}</Link>, |
58 | | - linkReference: props => <Link {...props}>{props.children}</Link>, |
59 | | - image: props => image(props), |
60 | | - thematicBreak: () => null, |
61 | | - imageReference: props => image(props), |
62 | | - }} |
63 | | - /> |
64 | | - </Element> |
65 | | -); |
| 14 | + const image = props => |
| 15 | + privateSandbox ? ( |
| 16 | + <img |
| 17 | + {...props} |
| 18 | + alt={props.alt} |
| 19 | + css={css({ |
| 20 | + maxWidth: '100%', |
| 21 | + })} |
| 22 | + /> |
| 23 | + ) : ( |
| 24 | + <Text marginY={4} variant="muted" block align="center"> |
| 25 | + You cannot use images in comments on public sandboxes. |
| 26 | + </Text> |
| 27 | + ); |
| 28 | + |
| 29 | + return ( |
| 30 | + <Element |
| 31 | + paddingX={4} |
| 32 | + paddingBottom={6} |
| 33 | + css={css({ |
| 34 | + 'ul, ol': { |
| 35 | + paddingLeft: 0, |
| 36 | + fontSize: 13, |
| 37 | + }, |
| 38 | + 'ol li': { |
| 39 | + counterIncrement: 'counter', |
| 40 | + }, |
| 41 | + 'ol li::before': { |
| 42 | + color: 'mutedForeground', |
| 43 | + content: "counter(counter) '. '", |
| 44 | + }, |
| 45 | + li: { |
| 46 | + listStyle: 'none', |
| 47 | + }, |
| 48 | + 'li:before': { |
| 49 | + content: "'•'", |
| 50 | + color: 'mutedForeground', |
| 51 | + paddingRight: '0.5em', |
| 52 | + }, |
| 53 | + })} |
| 54 | + > |
| 55 | + <ReactMarkdown |
| 56 | + source={source} |
| 57 | + renderers={{ |
| 58 | + text: ({ children }) => ( |
| 59 | + <Text variant="muted" size={13}> |
| 60 | + {children} |
| 61 | + </Text> |
| 62 | + ), |
| 63 | + heading: ({ children }) => ( |
| 64 | + <Text block variant="muted" size={13}> |
| 65 | + {children} |
| 66 | + </Text> |
| 67 | + ), |
| 68 | + code: props => <Code {...props} />, |
| 69 | + link: props => <Link {...props}>{props.children}</Link>, |
| 70 | + linkReference: props => <Link {...props}>{props.children}</Link>, |
| 71 | + image: props => image(props), |
| 72 | + imageReference: props => image(props), |
| 73 | + thematicBreak: () => null, |
| 74 | + inlineCode: props => ( |
| 75 | + <Element |
| 76 | + as="span" |
| 77 | + css={css({ backgroundColor: 'mutedForeground' })} |
| 78 | + > |
| 79 | + <Text variant="danger" as="code"> |
| 80 | + {props.children} |
| 81 | + </Text> |
| 82 | + </Element> |
| 83 | + ), |
| 84 | + }} |
| 85 | + /> |
| 86 | + </Element> |
| 87 | + ); |
| 88 | +}; |
0 commit comments