-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkingfile.js
More file actions
69 lines (58 loc) · 2.58 KB
/
Copy pathworkingfile.js
File metadata and controls
69 lines (58 loc) · 2.58 KB
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
import hljs from 'highlight.js';
import 'highlight.js/styles/vs2015.css';
import './css/index.css';
import { useParams } from 'react-router-dom';
import { useQuery } from '@apollo/client';
import { GET_SNIPPET } from '../../utils/queries';
import CommentForm from '../CommentForm/index';
import CommentsList from '../CommentsList/index';
// import Filter from '../Filter/index'
function SnippetDetail() {
const { snippetId } = useParams();
const { loading, data } = useQuery(GET_SNIPPET, {
variables: {
id: snippetId,
},
});
let hljsData = '';
if (!loading) {
if (data) {
hljsData = hljs.highlight(data.getSnippet.code.replace(/\\n/g, '\n'), {
language: data.getSnippet.language,
ignoreIllegals: true,
});
} else {
document.location.assign('/');
}
}
return (
<div className="container snippet-detail">
{/* {loading ? (
<div className="spinner-border text-primary" role="status">
<span className="visually-hidden">Loading...</span>
</div>
) : ( */}
<div class="row">
<div class="col s12 m7">
<h2 className="display-3" id="snippet-title">{data.getSnippet.title}</h2>
<p className="lead mb-3" id="snippet-description">{data.getSnippet.description}</p>
<div className="card mb-5" id="snippet-card">
<div className="card-header">
{data.getSnippet.language}
</div>
<div className="card-body p-0">
<pre className="m-0"><code className={'hljs language-' + hljsData.language.toLowerCase()} dangerouslySetInnerHTML={{__html: hljsData.value}}></code></pre>
</div>
<div class="card-footer">
<i class="bi bi-hand-thumbs-up-fill"></i>{data.getSnippet.like} <i class="bi bi-hand-thumbs-down-fill"></i>{data.getSnippet.dislike}
</div>
</div>
</div>
<div class="col s12 m" tabIndex="0" id="comments">
<CommentForm snippetId={data.getSnippet._id} />
<CommentsList comments={data.getSnippet.comments}/>
</div>
</div>
</div>
)}
export default SnippetDetail;