import * as React from "react" import styled from "styled-components" import { BookThumbnail } from "./components/BookThumbnail" import gql from "graphql-tag" import { BookTitle } from "./components/BookTitle" import breakpoint from "styled-components-breakpoint" import { AuthorItemWithSubLabel } from "../Author" import withTranslate from "jamplay-common/i18n/withTranslate" import { Link } from "jamplay-common/routing" import { getCategory } from "jamplay-common/enum/book-categories" const Container = styled.div` position: relative; .BookItem--meta { padding: 0 8px; } ${breakpoint("mobile")` padding: 0 8px; `}; ${breakpoint("tablet")` padding: 0 8px; `}; ${breakpoint("desktop")` padding: 0 13px; `}; a { text-decoration: none; color: inherit; } ` export interface BookItemPropTypes extends withTranslatePropType { book: BookItemData className?: string loading?: boolean opts?: { width?: number | string } } type BookItemComponent = React.SFC & { fragments?: { book: any } } export const BookItem: BookItemComponent = (props: BookItemPropTypes) => { let { t } = props const { book, opts } = props if (!opts) { return null } if (!t) { t = (s) => s } if (!book.categories) { return
{`[BookItem] ${book._id} is not provide categories `}
} const category = getCategory(book.categories[0]) return (
{props.book.author ? ( ) : null}
) } BookItem.defaultProps = { opts: { width: "100%" } } BookItem.displayName = "BookItem" BookItem.fragments = { book: gql` fragment BookItemData on Book { _id title thumbnailImage _id viewCount lastEpisodePublishedAt categories publishedAt author { _id name profilePicture } } ` } BookItem.defaultProps = { opts: {}, book: { _id: "NO_CONTENT", categories: ["NONE"], author: { _id: "NO_CONTENT", profilePicture: "NO_CONTENT", name: "NO_CONTENT" } } } export default withTranslate(BookItem)