From 675fa0dfbac2e592a0354cb42a784416a22b1d5b Mon Sep 17 00:00:00 2001 From: Benjamin Guedj Date: Fri, 23 Apr 2021 11:29:48 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20je=20consulte=20les=20ar?= =?UTF-8?q?ticles=20li=C3=A9s=20=C3=A0=20une=20=C3=A9tape?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #26 --- front/screens/ListArticles.tsx | 176 +++++++++++++++++---------------- 1 file changed, 92 insertions(+), 84 deletions(-) diff --git a/front/screens/ListArticles.tsx b/front/screens/ListArticles.tsx index 3bbbd3ac8..7bc55a275 100644 --- a/front/screens/ListArticles.tsx +++ b/front/screens/ListArticles.tsx @@ -7,12 +7,12 @@ import * as React from "react"; import { ActivityIndicator, ScrollView, StyleSheet } from "react-native"; import { Image, ListItem } from "react-native-elements"; +import Button from "../components/form/Button"; import { CommonText } from "../components/StyledText"; import { View } from "../components/Themed"; import Colors from "../constants/Colors"; import Labels from "../constants/Labels"; import type { Article, Step, TabHomeParamList } from "../types"; -import Button from "../components/form/Button"; interface Props { navigation: StackNavigationProp; @@ -25,28 +25,31 @@ const ETAPE_ENFANT_3_PREMIERS_MOIS = 6; const ListArticles: FC = ({ navigation, route }) => { const screenTitle = route.params.step.nom; const description = route.params.step.description; - const stepIsFirstThreeMonths = route.params.step.id == ETAPE_ENFANT_3_PREMIERS_MOIS; - - const ALL_ARTICLES = gql` - query GetAllArticles { - articles { - id - titre - resume - visuel { - url + const stepIsFirstThreeMonths = + route.params.step.id == ETAPE_ENFANT_3_PREMIERS_MOIS; + + const STEP_ARTICLES = gql` + query GetStepArticles { + etape(id: ${route.params.step.id}) { + articles { + id + titre + resume + visuel { + url + } } } } `; - const { loading, error, data } = useQuery(ALL_ARTICLES, { + const { loading, error, data } = useQuery(STEP_ARTICLES, { fetchPolicy: "no-cache", }); if (loading) return ; if (error) return {Labels.errorMsg}; - const result = data as { articles: Article[] }; + const articles = (data as { etape: { articles: Article[] } }).etape.articles; const navigateToSurvey = () => { console.log("navigateToSurvey"); @@ -54,63 +57,68 @@ const ListArticles: FC = ({ navigation, route }) => { return ( - - {screenTitle} - {description} - - {stepIsFirstThreeMonths && ( - - {Labels.article.firstThreeMonths.title} - {Labels.article.firstThreeMonths.description} -