Skip to content

Commit

Permalink
feat(Collective): Add initial page with proper styleguidist config
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Apr 23, 2019
1 parent ae62638 commit e34e4fa
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/components/collective-page/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Flex } from '@rebass/grid';

/**
* This is the collective page main layout, holding different blocks together
* and watching scroll to synchronise the view for children properly.
*
* See design: https://www.figma.com/file/e71tBo0Sr8J7R5n6iMkqI42d/09.-Collectives?node-id=2338%3A36062
*/
export default class CollectivePage extends Component {
static propTypes = {
collective: PropTypes.shape({
id: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
slug: PropTypes.string.isRequired,
}).isRequired,
};

render() {
const { name } = this.props.collective;
return (
<Flex justifyContent="center" p={5}>
Hello {name} V2!
</Flex>
);
}
}
85 changes: 85 additions & 0 deletions src/pages/new-collective-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react';
import PropTypes from 'prop-types';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { get } from 'lodash';

import withIntl from '../lib/withIntl';
import { withUser } from '../components/UserProvider';
import ErrorPage from '../components/ErrorPage';
import Page from '../components/Page';
import Loading from '../components/Loading';
import CollectivePage from '../components/collective-page';

/**
* The main page to display collectives. Wrap route parameters and GraphQL query
* to render `components/collective-page` with everything needed.
*/
class NewCollectivePage extends React.Component {
static propTypes = {
data: PropTypes.object.isRequired, // from withData
slug: PropTypes.string.isRequired,
};

static getInitialProps({ query: { slug } }) {
return { slug };
}

// See https://github.com/opencollective/opencollective/issues/1872
shouldComponentUpdate(newProps) {
if (get(this.props, 'data.Collective') && !get(newProps, 'data.Collective')) {
return false;
} else {
return true;
}
}

getPageMetaData(collective) {
if (collective) {
return {
title: collective.name,
description: collective.description || collective.longDescription,
twitterHandle: collective.twitterHandle || get(collective, 'parentCollective.twitterHandle'),
image: collective.image || get(collective, 'parentCollective.image'),
};
} else {
return {
title: 'Collective',
image: '/static/images/defaultBackgroundImage.png',
};
}
}

render() {
const { data } = this.props;

return !data || data.error ? (
<ErrorPage data={data} />
) : (
<Page {...this.getPageMetaData(data.collective)}>
{data.loading || !data.Collective ? <Loading /> : <CollectivePage collective={data.Collective} />}
</Page>
);
}
}

const getCollective = graphql(gql`
query NewCollectivePage($slug: String!) {
Collective(slug: $slug) {
id
slug
name
description
image
twitterHandle
githubHandle
parentCollective {
id
image
twitterHandle
}
}
}
`);

export default withUser(getCollective(withIntl(NewCollectivePage)));
3 changes: 3 additions & 0 deletions src/server/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ pages.add(
// Collective
// ----------

// New collective page
pages.add('new-collective-page', '/:slug/v2');

pages.add('collective', '/:slug');

export default pages;
Expand Down
11 changes: 9 additions & 2 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const fileExistsCaseInsensitive = require('react-styleguidist/lib/scripts/utils/
module.exports = {
assetsDir: 'styleguide',
getExampleFilename(componentPath) {
const examplePath = path.join(__dirname, 'styleguide', 'examples', `${path.parse(componentPath).name}.md`);
const parsedPath = path.parse(componentPath);
const parentDir = parsedPath.dir.split('src/components/')[1] || '';
const examplePath = path.join(__dirname, 'styleguide', 'examples', parentDir, `${parsedPath.name}.md`);
return fileExistsCaseInsensitive(examplePath) || false;
},
pagePerSection: true,
Expand All @@ -21,7 +23,12 @@ module.exports = {
name: 'UI',
content: 'styleguide/pages/UI.md',
components: 'src/components/*.js',
ignore: ['src/components/Contribute*.js', 'src/components/Styled*.js'],
ignore: ['src/components/Contribute*.js', 'src/components/Styled*.js', 'src/components/collective-page/*.js'],
},
{
name: 'Collective Page',
components: 'src/components/collective-page/*.js',
description: 'These components are used on the donate/contribute flow.',
},
{
name: 'Contribution Flow',
Expand Down

0 comments on commit e34e4fa

Please sign in to comment.