-
Notifications
You must be signed in to change notification settings - Fork 0
/
item-viewer.js
46 lines (42 loc) · 1.06 KB
/
item-viewer.js
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
import React from 'react';
import sanityClient from 'part:@sanity/base/client';
import {IntentLink} from 'part:@sanity/base/router';
import {withDocument} from 'part:@sanity/form-builder';
class ItemViewer extends React.Component {
state = {
items: []
};
componentDidMount() {
const query = `
*[references("${this.props.document._id}")] {
title,
"id": _id,
preachedDate,
preacher ->{name}
}`;
sanityClient.fetch(query).then(response => {
console.log(response);
this.setState({
items: response
});
});
}
render() {
return (
<div>
<h2>Members of this series</h2>
<ul>
{this.state.items.map(item => (
<li key={item.id}>
<IntentLink intent="edit" params={{type: 'sermons', id: item.id}}>
{item.title} - {item.preacher.name}
<br /><small>{item.preachedDate}</small>
</IntentLink>
</li>
))}
</ul>
</div>
);
}
}
export default withDocument(ItemViewer)