-
-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Collective): Add initial page with proper styleguidist config
- Loading branch information
Showing
4 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters