import React from 'react'; import emotion from 'preact-emotion'; import { graphql, compose } from 'react-apollo'; import gql from 'graphql-tag'; import remcalc from 'remcalc'; import { Grid, Row, Col } from 'preact-emotion-flexboxgrid'; import { ServiceCategory, ServiceName, ServiceDescription, Service, Overlay, Anchor, Sup } from '../components'; const Container = emotion('div')` padding-top: ${remcalc(30)}; background-color: #ffffff; `; const CategoryWrapper = emotion(Col)` margin-bottom: ${remcalc(48)}; `; const sliptTag = tag => tag.split('=').map(n => n.replace(/'/g, '')); const isNew = tag => sliptTag(tag)[0] === 'is-new'; const formatTag = tag => { if (sliptTag(tag)[0] === 'note') { return sliptTag(tag)[1]; } if (sliptTag(tag)[0] === 'is-new') { return 'New!'; } return tag; }; const GetProducts = gql` { categories { name services { name slug url tags description } } } `; const Services = ({ expanded = false, categories = [], loading }) => expanded ? ( {!loading && categories.map(({ name, services }) => ( {name} {services.map(({ name, description, url, tags }) => ( {name} {tags ? tags.map(tag => ( {formatTag(tag)} )) : null} {description} ))} ))} ) : null; export default compose( graphql(GetProducts, { options: () => ({ ssr: false }), props: ({ data: { categories = [], loading = false, error = null } }) => ({ categories, loading, error }) }) )(Services);