From f50a35ba7da4847336e09799454553f24ce59da7 Mon Sep 17 00:00:00 2001 From: Bastien Teissier Date: Thu, 6 May 2021 17:20:55 +0200 Subject: [PATCH 1/2] fix(coalition): non followed marked coalitions on login --- .../CoalitionCards/CoalitionCards.tsx | 5 +--- .../Coalition/hooks/useFetchCoalitions.ts | 7 ++++-- .../hooks/useFetchFollowedCoalitions.ts | 23 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/components/CoalitionCards/CoalitionCards.tsx b/src/components/CoalitionCards/CoalitionCards.tsx index 4bc56456..a480a9c0 100644 --- a/src/components/CoalitionCards/CoalitionCards.tsx +++ b/src/components/CoalitionCards/CoalitionCards.tsx @@ -20,10 +20,7 @@ const CoalitionCards: FunctionComponent = ({ const { fetchCoalitions, isFetchingCoalitions } = useFetchCoalitions(); useEffect(() => { - if (coalitions.length === 0) { - fetchCoalitions(); - } - // eslint-disable-next-line react-hooks/exhaustive-deps + fetchCoalitions(); }, [fetchCoalitions]); const renderCoalitionCard = (coalition: Coalition) => { diff --git a/src/redux/Coalition/hooks/useFetchCoalitions.ts b/src/redux/Coalition/hooks/useFetchCoalitions.ts index 1107b483..b88d7b75 100644 --- a/src/redux/Coalition/hooks/useFetchCoalitions.ts +++ b/src/redux/Coalition/hooks/useFetchCoalitions.ts @@ -6,9 +6,12 @@ import { updateCoalitions, markCoalitionsAsFollowed } from '../slice'; import { Coalition } from '../types'; import HandleErrorService from 'services/HandleErrorService'; import { useFetchFollowedCoalitions } from './useFetchFollowedCoalitions'; +import useSelector from 'redux/useSelector'; +import { isUserLogged } from 'redux/Login/selectors'; export const useFetchCoalitions = () => { const dispatch = useDispatch(); + const isUserLoggedIn = Boolean(useSelector(isUserLogged)); const { loading: loadingFollowed, doFetchFollowedCoalitions } = useFetchFollowedCoalitions(); @@ -30,11 +33,11 @@ export const useFetchCoalitions = () => { return; } - const followedCoalitions = await doFetchFollowedCoalitions(); + const followedCoalitions = await doFetchFollowedCoalitions(isUserLoggedIn); dispatch(updateCoalitions(coalitions)); dispatch(markCoalitionsAsFollowed(followedCoalitions)); - }, [dispatch, doFetchCoalitions, doFetchFollowedCoalitions]); + }, [dispatch, doFetchCoalitions, doFetchFollowedCoalitions, isUserLoggedIn]); return { fetchCoalitions, isFetchingCoalitions: isFetchingCoalitions || loadingFollowed }; }; diff --git a/src/redux/Coalition/hooks/useFetchFollowedCoalitions.ts b/src/redux/Coalition/hooks/useFetchFollowedCoalitions.ts index e9eaf74b..38800115 100644 --- a/src/redux/Coalition/hooks/useFetchFollowedCoalitions.ts +++ b/src/redux/Coalition/hooks/useFetchFollowedCoalitions.ts @@ -1,18 +1,17 @@ import { useTypedAsyncFn } from 'redux/useTypedAsyncFn'; import { authenticatedApiClient } from 'services/networking/client'; -import { isUserLogged } from 'redux/Login'; -import useSelector from 'redux/useSelector'; export const useFetchFollowedCoalitions = () => { - const isUserLoggedIn = Boolean(useSelector(isUserLogged)); - - const [{ loading, error }, doFetchFollowedCoalitions] = useTypedAsyncFn(async () => { - if (!isUserLoggedIn) return []; - try { - return await authenticatedApiClient.get('v3/coalitions/followed'); - } catch (error) { - return []; - } - }, []); + const [{ loading, error }, doFetchFollowedCoalitions] = useTypedAsyncFn( + async (isUserLoggedIn: boolean) => { + if (!isUserLoggedIn) return []; + try { + return await authenticatedApiClient.get('v3/coalitions/followed'); + } catch (error) { + return []; + } + }, + [], + ); return { loading, error, doFetchFollowedCoalitions }; }; From 5b78e50d68833a0493ce474352279ccf864cfff2 Mon Sep 17 00:00:00 2001 From: Bastien Teissier Date: Thu, 6 May 2021 17:40:51 +0200 Subject: [PATCH 2/2] feat(author): display anonymous author --- .../AuthorAndSupports/AuthorAndSupports.tsx | 28 +++++++++---------- src/components/Cause/Cause.tsx | 10 ++++--- src/translations/fr.json | 1 + 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/components/AuthorAndSupports/AuthorAndSupports.tsx b/src/components/AuthorAndSupports/AuthorAndSupports.tsx index bc948f15..42918bcf 100644 --- a/src/components/AuthorAndSupports/AuthorAndSupports.tsx +++ b/src/components/AuthorAndSupports/AuthorAndSupports.tsx @@ -15,26 +15,26 @@ const AuthorAndSupports: FunctionComponent = ({ cause, s const isUserLoggedIn = Boolean(useSelector(isUserLogged)); const intl = useIntl(); - if (cause.author === undefined || cause.author === null) { - return null; - } - return ( {showAuthor === true ? ( ) : null} diff --git a/src/components/Cause/Cause.tsx b/src/components/Cause/Cause.tsx index fe7a5de5..805aef8e 100644 --- a/src/components/Cause/Cause.tsx +++ b/src/components/Cause/Cause.tsx @@ -59,8 +59,8 @@ const Cause: FunctionComponent = ({ cause }: CauseProps) => { {cause.name} - {cause.author !== undefined && cause.author !== null ? ( - + + {cause.author !== undefined && cause.author !== null ? ( = ({ cause }: CauseProps) => { : cause.author.last_name_initial, }} /> - - ) : null} + ) : ( + + )} + {Boolean(cause.supported) || ( diff --git a/src/translations/fr.json b/src/translations/fr.json index 4d267b35..cb0954bd 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -100,6 +100,7 @@ }, "cause": { "author": "Par {firstName} {lastName}", + "anonymous-author": "Auteur Anonyme", "support": "{supportsNumber} soutien", "supports": "{supportsNumber} soutiens", "support-button": "Soutenir",