Skip to content

Commit

Permalink
Move tagColors outside of package
Browse files Browse the repository at this point in the history
  • Loading branch information
usulpro committed Jan 14, 2020
1 parent 6d9439a commit c35948a
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 111 deletions.
6 changes: 4 additions & 2 deletions .storybook/index.stories.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const stories = require('../src/content.stories');
const {
passConferenceSettings,
} =require('../src/content.stories');

module.exports = [stories];
passConferenceSettings({warning: 'settings should come from conferences projects'});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@focus-reactive/graphql-content-layer",
"version": "1.0.1",
"version": "1.0.2",
"private": false,
"main": "dist/index.js",
"scripts": {
Expand Down
77 changes: 37 additions & 40 deletions src/content.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ const React = require('react');
const ReactJson = require('react-json-view').default;
const {
Query,
QueryParams,
withGraphCMS,
} = require('@focus-reactive/storybook-addon-graphcms');
const { storiesOf } = require('@storybook/react');

const { credentials, conferenceTitle, eventYear } = require('./config');
const { queriesData, getContent } = require('./index');
const { tagColors } = require('./utils');
// const { tagColors } = require('./utils');

const allStories = {};

const AwaitForData = ({ promise }) => {
const [content, setContent] = React.useState(null);
React.useEffect(() => {
promise.then(res => setContent(res));
}, [getContent]);
const AwaitForData = ({ content }) => {
if (!content) return 'Loading data from GraphCMS';
return <ReactJson src={content} name="content" collapsed={2} />;
};
Expand All @@ -39,43 +36,43 @@ const TagColor = ({ title, tag }) => (
</div>
);

/**
* getContent is async
* but when it starts it populate `queriesData` with queries
* we need to get it first for creating stories
* after that we can wait for real data and show inner content
*/
const contentPromise = getContent();
const passConferenceSettings = async conferenceSettings => {
const content = await getContent(conferenceSettings);

queriesData.forEach(
({ queryPages, getData, story, vars }) => {
allStories[story] = Query({
name: story,
query: queryPages,
vars: { conferenceTitle, eventYear, ...vars },
searchVars: { search: '' },
getData,
storiesOf('Content Layer', module)
.add('content', () => <AwaitForData content={content} />)
.add('tag colors', () => {
const { tagColors } = content.conferenceSettings;
const tags = Object.keys(tagColors);
return (
<div>
{tags.map(tag => (
<TagColor key={tag} title={tag} tag={tagColors[tag]} />
))}
</div>
);
});
},
);

module.exports = {
default: {
title: 'GraphCMS content',
decorators: [withGraphCMS(credentials)],
},
...allStories,
};
const cmsStories = storiesOf('CMS Layer', module).addDecorator(
withGraphCMS(credentials),
);

storiesOf('Inner structure', module)
.add('content', () => <AwaitForData promise={contentPromise} />)
.add('tag colors', () => {
const tags = Object.keys(tagColors);
return (
<div>
{tags.map(tag => (
<TagColor key={tag} title={tag} tag={tagColors[tag]} />
))}
</div>
queriesData.forEach(({ queryPages, getData, story, vars }) => {
cmsStories.add(
story,
() => null,
QueryParams({
name: story,
query: queryPages,
vars: { conferenceTitle, eventYear, ...vars },
searchVars: { search: '' },
getData,
isConnected: true,
}),
);
});
};

module.exports = {
passConferenceSettings,
};
3 changes: 2 additions & 1 deletion src/fetch-committee.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const fetchData = async (client, vars) => {
.then(res => res.conf.year[0].committee);

const speakers = await prepareSpeakers(
data.map(speaker => ({ speaker, decor: true }))
data.map(speaker => ({ speaker, decor: true })),
{}
);

return {
Expand Down
13 changes: 9 additions & 4 deletions src/fetch-mc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const selectSettings = trySelectSettings(s => s.speakerAvatar.dimensions, {
});

const queryPages = /* GraphQL */ `
query($conferenceTitle: ConferenceTitle, $eventYear: EventYear, $avatarWidth: Int, $avatarHeight: Int) {
query(
$conferenceTitle: ConferenceTitle
$eventYear: EventYear
$avatarWidth: Int
$avatarHeight: Int
) {
conf: conferenceBrand(where: { title: $conferenceTitle }) {
id
status
Expand All @@ -17,7 +22,7 @@ const queryPages = /* GraphQL */ `
mcs {
id
speaker {
...person
...person
}
}
}
Expand All @@ -27,12 +32,12 @@ const queryPages = /* GraphQL */ `
${personFragment}
`;

const fetchData = async(client, vars) => {
const fetchData = async (client, vars) => {
const data = await client
.request(queryPages, vars)
.then(res => res.conf.year[0].mcs);

const mcs = await prepareSpeakers(data);
const mcs = await prepareSpeakers(data, {});

return {
mcs: await Promise.all(mcs),
Expand Down
10 changes: 8 additions & 2 deletions src/fetch-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const selectSettings = trySelectSettings(s => s.speakerAvatar.dimensions, {
});

const queryPages = /* GraphQL */ `
query($conferenceTitle: ConferenceTitle, $eventYear: EventYear, $avatarWidth: Int, $avatarHeight: Int) {
query(
$conferenceTitle: ConferenceTitle
$eventYear: EventYear
$avatarWidth: Int
$avatarHeight: Int
) {
conf: conferenceBrand(where: { title: $conferenceTitle }) {
id
status
Expand All @@ -30,7 +35,8 @@ const fetchData = async (client, vars) => {
.then(res => res.conf.year[0].performanceTeam);

const speakers = await prepareSpeakers(
data.map(speaker => ({ speaker, decor: true }))
data.map(speaker => ({ speaker, decor: true })),
{},
);

return {
Expand Down
26 changes: 19 additions & 7 deletions src/fetch-speakers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
const { prepareSpeakers, trySelectSettings } = require('./utils');
const { speakerInfoFragment } = require('./fragments');

const selectSettings = trySelectSettings(s => s.speakerAvatar.dimensions, {
avatarWidth: 500,
avatarHeight: 500,
});
const selectSettings = trySelectSettings(
s => ({
...s.speakerAvatar.dimensions,
tagColors: s.tagColors,
}),
{
avatarWidth: 500,
avatarHeight: 500,
tagColors: {},
},
);

const queryPages = /* GraphQL */ `
query($conferenceTitle: ConferenceTitle, $eventYear: EventYear, $avatarWidth: Int, $avatarHeight: Int) {
query(
$conferenceTitle: ConferenceTitle
$eventYear: EventYear
$avatarWidth: Int
$avatarHeight: Int
) {
conf: conferenceBrand(where: { title: $conferenceTitle }) {
id
status
Expand All @@ -25,15 +37,15 @@ const queryPages = /* GraphQL */ `
${speakerInfoFragment}
`;

const fetchData = async (client, vars) => {
const fetchData = async (client, { tagColors, ...vars }) => {
const data = await client.request(queryPages, vars).then(res => ({
speakers: res.conf.year[0].speakers,
openForTalks: res.conf.year[0].openForTalks,
}));

const { openForTalks } = data;

const speakers = await prepareSpeakers(data.speakers);
const speakers = await prepareSpeakers(data.speakers, tagColors);

return {
speakers: { main: await Promise.all(speakers) },
Expand Down
38 changes: 27 additions & 11 deletions src/fetch-workshops.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ const selectSettings = trySelectSettings(s => s.speakerAvatar.dimensions, {
});

const queryPages = /* GraphQL */ `
query ($conferenceTitle: ConferenceTitle, $eventYear: EventYear, $avatarWidth: Int, $avatarHeight: Int) {
conf: conferenceBrand(where: {title: $conferenceTitle}) {
query(
$conferenceTitle: ConferenceTitle
$eventYear: EventYear
$avatarWidth: Int
$avatarHeight: Int
) {
conf: conferenceBrand(where: { title: $conferenceTitle }) {
id
status
year: conferenceEvents(where: {year: $eventYear}) {
year: conferenceEvents(where: { year: $eventYear }) {
id
status
schedule: daySchedules(where: {workshops_some: {}}) {
schedule: daySchedules(where: { workshops_some: {} }) {
id
status
additionalEvents
Expand All @@ -30,7 +35,14 @@ const queryPages = /* GraphQL */ `
level
speaker {
name
info: pieceOfSpeakerInfoes(where: {conferenceEvent: {year: $eventYear, conferenceBrand: {title: $conferenceTitle}}}) {
info: pieceOfSpeakerInfoes(
where: {
conferenceEvent: {
year: $eventYear
conferenceBrand: { title: $conferenceTitle }
}
}
) {
...speakerInfo
}
}
Expand Down Expand Up @@ -58,26 +70,30 @@ const fetchData = async (client, vars) => {
day.additionalEvents.find(({ title }) => title === ws.title)),
})),
],
[]
[],
);


const allWorkshops = await Promise.all(
workshops.map(async wrp => ({
...wrp,
description: await markdownToHtml(wrp.description),
additionalInfo: await markdownToHtml(wrp.additionalInfo),
}))
})),
);

const trainers = await Promise.all(await prepareSpeakers(allWorkshops.map(ws => ws.speaker.info[0])));
const trainers = await Promise.all(
await prepareSpeakers(
allWorkshops.map(ws => ws.speaker.info[0]),
{},
),
);

return {
trainers,
workshops: allWorkshops,
speakers: {
workshops: trainers
}
workshops: trainers,
},
};
};

Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const getContent = async conferenceSettings => {
} catch (err) {}
return { ...content, ...piece };
}, {});
contentMap.conferenceSettings = conferenceSettings;
return contentMap;
};

Expand Down
Loading

0 comments on commit c35948a

Please sign in to comment.