Skip to content

Commit 524c4ca

Browse files
author
Lazhari
committed
Get the course from graph cms
1 parent 50501df commit 524c4ca

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

components/CoursesQuery.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from "react";
2+
import gql from "graphql-tag";
3+
import { Query } from "react-apollo";
4+
5+
const CoursesQuery = gql`
6+
{
7+
courses {
8+
id
9+
title
10+
subtitle
11+
caption
12+
author
13+
image {
14+
url
15+
}
16+
logo {
17+
url
18+
}
19+
avatar {
20+
url
21+
}
22+
}
23+
}
24+
`;
25+
26+
const CoursesQueryContainer = ({ children }) => (
27+
<Query query={CoursesQuery}>{children}</Query>
28+
);
29+
30+
export default CoursesQueryContainer;

screens/HomeScreen.js

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Course from "../components/Course";
1717
import Menu from "../components/Menu";
1818
import Avatar from "../components/Avatar";
1919
import CardsQuery from "../components/CardsQuery";
20+
import CoursesQuery from "../components/CoursesQuery";
2021

2122
function mapDispatchToProps(dispatch) {
2223
return {
@@ -148,9 +149,20 @@ class HomeScreen extends React.Component {
148149
</CardsQuery>
149150
</ScrollView>
150151
<Subtitle>Popular Courses</Subtitle>
151-
{courses.map(course => (
152-
<Course {...course} key={course.title} />
153-
))}
152+
<CoursesQuery>
153+
{({ loading, error, data }) => {
154+
if (loading) {
155+
return <Message>Loading...</Message>;
156+
}
157+
if (error) {
158+
return <Message>Error...</Message>;
159+
}
160+
const { courses } = data;
161+
return courses.map(course => (
162+
<Course {...course} key={course.id} />
163+
));
164+
}}
165+
</CoursesQuery>
154166
</ScrollView>
155167
</SafeAreaView>
156168
</AnimatedContainer>
@@ -237,43 +249,3 @@ const logos = [
237249
text: "Sketch"
238250
}
239251
];
240-
241-
const courses = [
242-
{
243-
title: "Prototype in InVision Studio",
244-
subtitle: "10 sections",
245-
image: require("../assets/background13.jpg"),
246-
logo: require("../assets/logo-studio.png"),
247-
author: "Meng To",
248-
avatar: require("../assets/avatar.jpg"),
249-
caption: "Design an interactive prototype"
250-
},
251-
{
252-
title: "React for Designers",
253-
subtitle: "12 sections",
254-
image: require("../assets/background11.jpg"),
255-
logo: require("../assets/logo-react.png"),
256-
author: "Meng To",
257-
avatar: require("../assets/avatar.jpg"),
258-
caption: "Learn to design and code a React site"
259-
},
260-
{
261-
title: "Design and Code with Framer X",
262-
subtitle: "10 sections",
263-
image: require("../assets/background14.jpg"),
264-
logo: require("../assets/logo-framerx.png"),
265-
author: "Meng To",
266-
avatar: require("../assets/avatar.jpg"),
267-
caption: "Create powerful design and code components for your app"
268-
},
269-
{
270-
title: "Design System in Figma",
271-
subtitle: "10 sections",
272-
image: require("../assets/background6.jpg"),
273-
logo: require("../assets/logo-figma.png"),
274-
author: "Meng To",
275-
avatar: require("../assets/avatar.jpg"),
276-
caption:
277-
"Complete guide to designing a site using a collaborative design tool"
278-
}
279-
];

0 commit comments

Comments
 (0)