blob: 4550b84dac1e58b4e549dde8ccc2008bc36c082f (
plain)
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
|
import { Query } from 'react-apollo';
import PropTypes from 'prop-types';
import { SINGLE_ITEM_QUERY } from '../queries/queries';
import styled from 'styled-components';
import Link from 'next/link';
import Dump from './Dump';
import Error from './ErrorMessage';
const SingleItemStyles = styled.div`
max-width: 1200px;
margin: 2rem auto;
box-shadow: ${props => props.theme.bs};
img {
width: 100%;
object-fit: cover;
}
.details {
margin: 3rem;
font-size: 3rem;
}
`;
const SingleItem = props => (
<Query query={SINGLE_ITEM_QUERY} variables={{ id: props.id }}>
{({ data, loading, error }) => {
if (loading) return <p>Loading...</p>;
if (error) return <Error error={error} />;
const [item] = data.items;
return (
<SingleItemStyles data-test="SingleItem">
<img src={item.largeImage || item.image} alt={item.title} />
<div className="details">
<h2>Viewing {item.title}</h2>
<p>{item.description}</p>
<Link
href={{
pathname: '/update',
query: { id: item.id },
}}
>
<a>Edit ✏️</a>
</Link>
</div>
</SingleItemStyles>
);
}}
</Query>
);
SingleItem.propTypes = {
id: PropTypes.string.isRequired,
};
export default SingleItem;
|