diff --git a/remark.rest b/remark.rest
index a52a2126..ffaa988c 100644
--- a/remark.rest
+++ b/remark.rest
@@ -25,11 +25,7 @@ POST {{host}}/api/v1/preview
Content-Type: application/json
{
- "text": "comment *blah* http://radio-t.com",
- "locator": {
- "url": "https://radio-t.com/blah1",
- "site": "remark"
- }
+ "text": "comment *blah* http://radio-t.com"
}
### update comment
diff --git a/web/app/common/api.js b/web/app/common/api.js
index a6922633..109c2d9f 100644
--- a/web/app/common/api.js
+++ b/web/app/common/api.js
@@ -2,6 +2,8 @@ import { siteId, url } from './settings';
import fetcher from './fetcher'
+// TODO: rename actions
+
/* common */
export const logOut = () => fetcher.get({ url: `/auth/logout`, overriddenApiBase: '' });
@@ -30,13 +32,21 @@ export const send = ({ text, pid }) => fetcher.post({
text,
locator: {
site: siteId,
- url
+ url,
},
...(pid ? { pid } : {}),
},
withCredentials: true,
});
+export const getPreview = ({ text }) => fetcher.post({
+ url: '/preview',
+ body: {
+ text,
+ },
+ withCredentials: true,
+});
+
export const getUser = () => fetcher.get({
url: '/user',
withCredentials: true
@@ -83,6 +93,7 @@ export default {
vote,
send,
getUser,
+ getPreview,
pin,
unpin,
diff --git a/web/app/components/comment/__text/comment__text.scss b/web/app/components/comment/__text/comment__text.scss
index bc03e370..0859c323 100644
--- a/web/app/components/comment/__text/comment__text.scss
+++ b/web/app/components/comment/__text/comment__text.scss
@@ -1,32 +1,3 @@
.comment__text {
margin-bottom: 4px;
-
- p {
- margin: 0;
-
- + p {
- margin-top: 8px;
- }
-
- // imported comments have br instead of p
- br {
- content: '';
- display: block;
- margin-top: 8px;
- }
- }
-
- a {
- color: #0aa;
-
- &:hover {
- color: #06c5c5;
- text-decoration: none;
- }
- }
-
- img {
- max-width: 100%;
- max-height: 300px;
- }
}
diff --git a/web/app/components/comment/comment.jsx b/web/app/components/comment/comment.jsx
index 9f17bd28..a53bb52e 100644
--- a/web/app/components/comment/comment.jsx
+++ b/web/app/components/comment/comment.jsx
@@ -219,7 +219,10 @@ export default class Comment extends Component {
{o.user.name}
{' '}
-
+
);
@@ -273,7 +276,10 @@ export default class Comment extends Component {
}
-
+
{
diff --git a/web/app/components/comment/index.js b/web/app/components/comment/index.js
index b5f5e405..f926c81c 100644
--- a/web/app/components/comment/index.js
+++ b/web/app/components/comment/index.js
@@ -1,3 +1,5 @@
+import 'components/raw-content';
+
export { default } from './comment';
require('./comment.scss');
diff --git a/web/app/components/input/__preview/input__preview.scss b/web/app/components/input/__preview/input__preview.scss
new file mode 100644
index 00000000..29ad640c
--- /dev/null
+++ b/web/app/components/input/__preview/input__preview.scss
@@ -0,0 +1,10 @@
+.input__preview {
+ margin-top: 8px;
+ padding: 7px 11px;
+ font-size: 16px;
+ line-height: 1.2;
+ border: 1px dashed #eee;
+ border-radius: 2px;
+ background: #fff;
+ color: #333;
+}
diff --git a/web/app/components/input/index.js b/web/app/components/input/index.js
index b38176c9..2dc45601 100644
--- a/web/app/components/input/index.js
+++ b/web/app/components/input/index.js
@@ -1,3 +1,5 @@
+import 'components/raw-content';
+
export { default } from './input';
require('./input.scss');
@@ -8,3 +10,4 @@ require('./__button/_type/_send/input__button_type_send.scss');
require('./__buttons/input__buttons.scss');
require('./__field/input__field.scss');
+require('./__preview/input__preview.scss');
diff --git a/web/app/components/input/input.jsx b/web/app/components/input/input.jsx
index 3e75104e..cffdbd7b 100644
--- a/web/app/components/input/input.jsx
+++ b/web/app/components/input/input.jsx
@@ -6,8 +6,13 @@ export default class Input extends Component {
constructor(props) {
super(props);
+ this.state = {
+ preview: null,
+ };
+
this.autoResize = this.autoResize.bind(this);
this.send = this.send.bind(this);
+ this.getPreview = this.getPreview.bind(this);
this.onKeyDown = this.onKeyDown.bind(this);
}
@@ -46,7 +51,7 @@ export default class Input extends Component {
}
this.fieldNode.value = '';
- this.setState({ height: null });
+ this.setState({ height: null, preview: null });
})
.catch(() => {
// TODO: do smth?
@@ -54,7 +59,19 @@ export default class Input extends Component {
.finally(() => this.setState({ isFieldDisabled: false }));
}
- render(props, { height, isFieldDisabled }) {
+ getPreview() {
+ const text = this.fieldNode.value;
+
+ if (!text || !text.trim()) return;
+
+ api.getPreview({ text })
+ .then(preview => this.setState({ preview }))
+ .catch(() => {
+ // TODO: do smth?
+ });
+ }
+
+ render(props, { height, isFieldDisabled, preview }) {
return (
);
}
diff --git a/web/app/components/raw-content/index.js b/web/app/components/raw-content/index.js
new file mode 100644
index 00000000..12c85c14
--- /dev/null
+++ b/web/app/components/raw-content/index.js
@@ -0,0 +1 @@
+require('./raw-content.scss');
diff --git a/web/app/components/raw-content/raw-content.scss b/web/app/components/raw-content/raw-content.scss
new file mode 100644
index 00000000..bf4e71d0
--- /dev/null
+++ b/web/app/components/raw-content/raw-content.scss
@@ -0,0 +1,30 @@
+.raw-content {
+ p {
+ margin: 0;
+
+ + p {
+ margin-top: 8px;
+ }
+
+ // imported comments have br instead of p
+ br {
+ content: '';
+ display: block;
+ margin-top: 8px;
+ }
+ }
+
+ a {
+ color: #0aa;
+
+ &:hover {
+ color: #06c5c5;
+ text-decoration: none;
+ }
+ }
+
+ img {
+ max-width: 100%;
+ max-height: 300px;
+ }
+}