blob: 4cf367471beab51950be93cdd5b98848ffbadb52 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
import React from 'react';
import { Link } from 'react-router-dom';
import * as qs from 'query-string';
import moment from 'moment';
import Message from './Message';
import Spinner from './Spinner';
import Avatar from './Avatar';
import { format } from '../utils/embed';
export default class Thread extends React.Component {
constructor(props) {
super(props);
this.state = {
msg: {},
replies: []
};
this.loaded = this.loaded.bind(this);
}
componentDidMount() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
this.loadReplies();
}
loadReplies() {
this.setState({ replies: [] })
const { mid } = this.props.match.params;
let params = {
mid: mid
}
if (this.props.visitor && this.props.visitor.hash) {
params.hash = this.props.visitor.hash
};
const url = `https://api.juick.com/thread?${qs.stringify(params)}`;
fetch(url)
.then(response => {
return response.json()
})
.then(data => {
let msg = data.shift();
this.setState({
msg: msg,
replies: data
})
}
).catch(ex => {
console.log(ex);
});
}
loaded() {
return this.state.msg.mid;
}
render() {
const msg = this.state.msg;
return (
<React.Fragment>
<ul id="0">
<li className="msg msgthread">
{
this.loaded() ? (
<Message data={msg} visitor={this.props.visitor}>
<form className="msg-comment-target">
<input type="hidden" name="mid" value={msg.mid} />
<div className="msg-comment">
<div className="ta-wrapper">
<textarea name="body" rows="1" className="reply" placeholder="Write a comment..."></textarea>
</div>
</div>
</form>
{
msg.recommendations && (
<div className="msg-recomms">{`Recommended by (${msg.recommendations.length}): `}
{
msg.recommendations.map(it => (
<Link to={`/${it}/`}>{it}</Link>
)).reduce((prev, curr) => [prev, ', ', curr])
}
</div>
)
}
</Message>
) : (
<Spinner />
)
}
</li>
</ul>
{
this.loaded() && (
<React.Fragment>
<div className="title2">
{
this.props.visitor.uid > 0 &&
<img src={`https://api.juick.com/thread/mark_read/${msg.mid}-${msg.rid || 0}.gif?hash=${this.props.visitor.hash}`} />
}
<h2>{msg.replies && `Replies (${msg.replies})`}</h2>
</div>
<ul id="replies">
{
this.state.replies.map((msg) => (
<li id={msg.rid} key={msg.rid} className="msg">
<div className="msg-cont">
<div className="msg-header">
{!msg.user.banned ? (
<React.Fragment>
<span itemProp="author" itemScope="" itemType="http://schema.org/Person">
<Link to={`/${msg.user.uname}/`} itemProp="url" rel="author"><span itemProp="name">{msg.user.uname}</span></Link>
</span><Avatar user={msg.user} />
</React.Fragment>) : (
<React.Fragment>
<span>[удалено]:</span><Avatar user={{ uid: 0 }} />
</React.Fragment>
)}
<div className="msg-ts">
<a href={`/${msg.user.uname}/${msg.mid}`}>
<time itemProp="datePublished dateModified" itemType="http://schema.org/Date" dateTime={msg.timestamp}
title={moment.utc(msg.timestamp).local().format('lll')}>
{moment.utc(msg.timestamp).fromNow()}
</time>
</a>
</div>
</div>
<div className="msg-txt"><p dangerouslySetInnerHTML={{ __html: format(msg.body, msg.mid, (msg.tags || []).indexOf('code') >= 0) }}></p></div>
{
msg.photo &&
<p className="ir"><a href={`//i.juick.com/p/${msg.mid}-${msg.rid}.${msg.attach}`} data-fname={`${msg.mid}-${msg.rid}.${msg.attach}`}>
<img itemProp="image" src={`//i.juick.com/p/${msg.mid}-${msg.rid}.${msg.attach}`} alt="" /></a>
</p>
}
<div className="msg-links">{`/${msg.rid}`}
{
msg.replyto > 0 &&
(
<a href={`#${msg.replyto}`}> in reply to {msg.to.uname} </a>
)
}
{
this.props.visitor.uid > 0 ? (
<React.Fragment>
<span>· </span>
<a href={`/post?body=%23${msg.mid}/${msg.rid}%20`} className="a-thread-comment">Reply</a>
<div className="msg-comment-target msg-comment-hidden"></div>
</React.Fragment>
) : (
<React.Fragment>
<span> · </span><a href="#" className="a-login">Reply</a>
</React.Fragment>
)
}
</div>
</div>
</li>
))
}
</ul>
</React.Fragment>
)
}
</React.Fragment>
)
}
}
|