2017-05-12 00:23:56 +00:00
|
|
|
// @flow
|
2017-06-01 03:23:09 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-08-03 03:45:09 +00:00
|
|
|
import { observer } from 'mobx-react';
|
2017-05-17 07:11:13 +00:00
|
|
|
import { Link } from 'react-router-dom';
|
2017-06-28 05:15:29 +00:00
|
|
|
import Document from 'models/Document';
|
2017-05-25 07:07:41 +00:00
|
|
|
import styled from 'styled-components';
|
2017-05-26 04:59:35 +00:00
|
|
|
import { color } from 'styles/constants';
|
2017-09-04 20:23:20 +00:00
|
|
|
import Icon from 'components/Icon';
|
2017-09-04 00:26:57 +00:00
|
|
|
import PublishingInfo from './components/PublishingInfo';
|
2017-05-25 07:07:41 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
document: Document,
|
2017-07-09 18:26:17 +00:00
|
|
|
highlight?: ?string,
|
2017-07-15 05:15:56 +00:00
|
|
|
showCollection?: boolean,
|
2017-06-01 03:23:09 +00:00
|
|
|
innerRef?: Function,
|
2017-05-25 07:07:41 +00:00
|
|
|
};
|
|
|
|
|
2017-09-11 07:15:27 +00:00
|
|
|
const StyledStar = styled(({ solid, ...props }) => <Icon {...props} />).attrs({
|
2017-09-04 20:23:20 +00:00
|
|
|
type: 'Star',
|
|
|
|
color: color.text,
|
|
|
|
})`
|
2017-09-12 05:08:47 +00:00
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
top: 1px;
|
2017-08-03 03:45:09 +00:00
|
|
|
margin-left: 4px;
|
2017-09-03 01:43:12 +00:00
|
|
|
opacity: ${props => (props.solid ? '1 !important' : 0)};
|
2017-10-01 23:00:18 +00:00
|
|
|
transition: all 100ms ease-in-out;
|
2017-09-11 06:23:28 +00:00
|
|
|
|
|
|
|
${props => props.solid && 'polygon { fill: #000};'}
|
2017-10-01 23:00:18 +00:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
transform: scale(1.1);
|
|
|
|
}
|
|
|
|
&:active {
|
|
|
|
transform: scale(0.95);
|
|
|
|
}
|
2017-08-03 03:45:09 +00:00
|
|
|
`;
|
|
|
|
|
2017-05-26 04:59:35 +00:00
|
|
|
const DocumentLink = styled(Link)`
|
|
|
|
display: block;
|
2017-06-26 03:32:05 +00:00
|
|
|
margin: 0 -16px;
|
2017-08-03 03:45:09 +00:00
|
|
|
padding: 10px 16px;
|
2017-05-26 04:59:35 +00:00
|
|
|
border-radius: 8px;
|
2017-06-01 03:23:09 +00:00
|
|
|
border: 2px solid transparent;
|
|
|
|
max-height: 50vh;
|
2017-06-26 00:21:33 +00:00
|
|
|
min-width: 100%;
|
2017-06-01 03:23:09 +00:00
|
|
|
overflow: hidden;
|
2017-05-26 04:59:35 +00:00
|
|
|
|
2017-06-01 03:23:09 +00:00
|
|
|
&:hover,
|
|
|
|
&:active,
|
|
|
|
&:focus {
|
|
|
|
background: ${color.smokeLight};
|
|
|
|
border: 2px solid ${color.smoke};
|
|
|
|
outline: none;
|
2017-09-03 01:43:12 +00:00
|
|
|
|
|
|
|
${StyledStar} {
|
2017-09-04 20:23:20 +00:00
|
|
|
opacity: .5;
|
2017-09-03 01:43:12 +00:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 04:59:35 +00:00
|
|
|
}
|
|
|
|
|
2017-06-01 03:23:09 +00:00
|
|
|
&:focus {
|
|
|
|
border: 2px solid ${color.slateDark};
|
|
|
|
}
|
|
|
|
|
2017-06-26 03:32:05 +00:00
|
|
|
h3 {
|
2017-06-01 03:23:09 +00:00
|
|
|
margin-top: 0;
|
2017-08-03 03:45:09 +00:00
|
|
|
margin-bottom: .25em;
|
2017-05-26 04:59:35 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2017-08-03 03:45:09 +00:00
|
|
|
@observer class DocumentPreview extends Component {
|
2017-06-01 03:23:09 +00:00
|
|
|
props: Props;
|
|
|
|
|
2017-08-03 03:45:09 +00:00
|
|
|
star = (ev: SyntheticEvent) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
this.props.document.star();
|
|
|
|
};
|
|
|
|
|
|
|
|
unstar = (ev: SyntheticEvent) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
this.props.document.unstar();
|
|
|
|
};
|
|
|
|
|
2017-06-01 03:23:09 +00:00
|
|
|
render() {
|
2017-07-15 05:15:56 +00:00
|
|
|
const { document, showCollection, innerRef, ...rest } = this.props;
|
2017-06-01 03:23:09 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<DocumentLink to={document.url} innerRef={innerRef} {...rest}>
|
2017-08-03 03:45:09 +00:00
|
|
|
<h3>
|
|
|
|
{document.title}
|
|
|
|
{document.starred
|
2017-09-04 19:14:18 +00:00
|
|
|
? <a onClick={this.unstar}>
|
2017-09-04 20:23:20 +00:00
|
|
|
<StyledStar solid />
|
2017-09-04 19:14:18 +00:00
|
|
|
</a>
|
|
|
|
: <a onClick={this.star}>
|
2017-09-04 20:23:20 +00:00
|
|
|
<StyledStar />
|
2017-09-04 19:14:18 +00:00
|
|
|
</a>}
|
2017-08-03 03:45:09 +00:00
|
|
|
</h3>
|
2017-05-26 04:59:35 +00:00
|
|
|
<PublishingInfo
|
2017-07-16 16:24:45 +00:00
|
|
|
document={document}
|
2017-07-15 05:15:56 +00:00
|
|
|
collection={showCollection ? document.collection : undefined}
|
2017-05-26 04:59:35 +00:00
|
|
|
/>
|
|
|
|
</DocumentLink>
|
2017-06-01 03:23:09 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 16:02:39 +00:00
|
|
|
|
2017-05-25 07:07:41 +00:00
|
|
|
export default DocumentPreview;
|