From bc9aa1721aae10c25c393efecac665175bdee7cf Mon Sep 17 00:00:00 2001
From: William Petit
Date: Wed, 22 Jul 2020 09:18:50 +0200
Subject: [PATCH] Remplacement du Loader par WithLoader
---
client/src/components/App.tsx | 2 +
client/src/components/HomePage/HomePage.tsx | 10 +---
.../components/HomePage/WorkgroupsPanel.tsx | 58 +++++++++----------
client/src/components/Loader.tsx | 14 -----
.../components/ProfilePage/ProfilePage.tsx | 9 +--
client/src/components/WithLoader.tsx | 7 +--
.../WorkgroupPage/WorkgroupPage.tsx | 22 +++++++
client/src/gql/client.tsx | 5 +-
client/src/gql/queries/profile.tsx | 2 +-
9 files changed, 62 insertions(+), 67 deletions(-)
delete mode 100644 client/src/components/Loader.tsx
create mode 100644 client/src/components/WorkgroupPage/WorkgroupPage.tsx
diff --git a/client/src/components/App.tsx b/client/src/components/App.tsx
index af9e243..89e3dca 100644
--- a/client/src/components/App.tsx
+++ b/client/src/components/App.tsx
@@ -2,6 +2,7 @@ import React from 'react';
import { BrowserRouter, Route, Redirect, Switch } from "react-router-dom";
import { HomePage } from './HomePage/HomePage';
import { ProfilePage } from './ProfilePage/ProfilePage';
+import { WorkgroupPage } from './WorkgroupPage/WorkgroupPage';
export class App extends React.Component {
render() {
@@ -10,6 +11,7 @@ export class App extends React.Component {
+
} />
diff --git a/client/src/components/HomePage/HomePage.tsx b/client/src/components/HomePage/HomePage.tsx
index bd01c65..a09d5f7 100644
--- a/client/src/components/HomePage/HomePage.tsx
+++ b/client/src/components/HomePage/HomePage.tsx
@@ -2,23 +2,18 @@ import React from 'react';
import { Page } from '../Page';
import { Dashboard } from './Dashboard';
import { useUserProfileQuery } from '../../gql/queries/profile';
-import { Loader } from '../Loader';
+import { WithLoader } from '../WithLoader';
export function HomePage() {
const { data, loading } = useUserProfileQuery();
- if (loading) {
- return (
-
- );
- }
-
const { userProfile } = (data || {});
return (
+
{
userProfile ?
:
@@ -30,6 +25,7 @@ export function HomePage() {
}
+
diff --git a/client/src/components/HomePage/WorkgroupsPanel.tsx b/client/src/components/HomePage/WorkgroupsPanel.tsx
index 6648bc0..d98ef75 100644
--- a/client/src/components/HomePage/WorkgroupsPanel.tsx
+++ b/client/src/components/HomePage/WorkgroupsPanel.tsx
@@ -4,7 +4,7 @@ import { User } from '../../types/user';
import { Link } from 'react-router-dom';
import { useWorkgroupsQuery } from '../../gql/queries/workgroups';
import { useUserProfileQuery } from '../../gql/queries/profile';
-import { Loader } from '../Loader';
+import { WithLoader } from '../WithLoader';
export function WorkgroupsPanel() {
const workgroupsQuery = useWorkgroupsQuery();
@@ -12,18 +12,14 @@ export function WorkgroupsPanel() {
const [ state, setState ] = useState({ selectedTab: 0 });
const isLoading = userProfileQuery.loading || workgroupsQuery.loading;
- if (isLoading) {
- return ;
- }
-
- let { data: { userProfile }} = userProfileQuery;
- let { data: { workgroups }} = workgroupsQuery;
+ const { userProfile } = (userProfileQuery.data || {});
+ const { workgroups } = (workgroupsQuery.data || {});
const filterTabs = [
{
label: "Mes groupes",
filter: workgroups => workgroups.filter((wg: Workgroup) => {
- return wg.members.some((u: User) => u.id === userProfile.id);
+ return wg.members.some((u: User) => u.id === (userProfile ? userProfile.id : ''));
})
},
{
@@ -43,7 +39,7 @@ export function WorkgroupsPanel() {
let workgroupsItems = [];
- workgroupsItems = filterTabs[state.selectedTab].filter(workgroups).map((wg: Workgroup) => {
+ workgroupsItems = filterTabs[state.selectedTab].filter(workgroups || []).map((wg: Workgroup) => {
return (
@@ -63,9 +59,9 @@ export function WorkgroupsPanel() {
-
+
+
+
{/*
@@ -76,26 +72,28 @@ export function WorkgroupsPanel() {
*/}
-
+
+
+ {
+ filterTabs.map((tab, i) => {
+ return (
+
+ {tab.label}
+
+ )
+ })
+ }
+
{
- filterTabs.map((tab, i) => {
- return (
-
- {tab.label}
-
- )
- })
+ workgroupsItems.length > 0 ?
+ workgroupsItems :
+
+ Aucun groupe dans cet catégorie pour l'instant.
+
}
-
- {
- workgroupsItems.length > 0 ?
- workgroupsItems :
-
- Aucun groupe dans cet catégorie pour l'instant.
-
- }
+
)
}
\ No newline at end of file
diff --git a/client/src/components/Loader.tsx b/client/src/components/Loader.tsx
deleted file mode 100644
index 5632248..0000000
--- a/client/src/components/Loader.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import React from 'react';
-
-export class Loader extends React.Component {
- render() {
- return (
-
- )
- }
-}
\ No newline at end of file
diff --git a/client/src/components/ProfilePage/ProfilePage.tsx b/client/src/components/ProfilePage/ProfilePage.tsx
index 536711e..4e53325 100644
--- a/client/src/components/ProfilePage/ProfilePage.tsx
+++ b/client/src/components/ProfilePage/ProfilePage.tsx
@@ -1,7 +1,6 @@
-import React, { useEffect } from 'react';
+import React from 'react';
import { Page } from '../Page';
import { UserForm } from '../UserForm';
-import { Loader } from '../Loader';
import { User } from '../../types/user';
import { useUserProfileQuery } from '../../gql/queries/profile';
import { useUpdateUserProfileMutation } from '../../gql/mutations/profile';
@@ -27,11 +26,9 @@ export function ProfilePage() {
Mon profil
-
+
{
- userProfile ?
- :
-
+
}
diff --git a/client/src/components/WithLoader.tsx b/client/src/components/WithLoader.tsx
index 33f5441..1a5abf3 100644
--- a/client/src/components/WithLoader.tsx
+++ b/client/src/components/WithLoader.tsx
@@ -9,12 +9,7 @@ export const WithLoader: FunctionComponent
= ({ loading, childr
{
loading ?
- :
+ Chargement
:
children
}
diff --git a/client/src/components/WorkgroupPage/WorkgroupPage.tsx b/client/src/components/WorkgroupPage/WorkgroupPage.tsx
new file mode 100644
index 0000000..14a0011
--- /dev/null
+++ b/client/src/components/WorkgroupPage/WorkgroupPage.tsx
@@ -0,0 +1,22 @@
+import React, { useEffect } from 'react';
+import { Page } from '../Page';
+import { WithLoader } from '../WithLoader';
+
+export function WorkgroupPage() {
+ return (
+
+
+
+
+
+
Groupe de travail
+
+
+
+
+
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/client/src/gql/client.tsx b/client/src/gql/client.tsx
index bbe3c37..3aff245 100644
--- a/client/src/gql/client.tsx
+++ b/client/src/gql/client.tsx
@@ -4,12 +4,11 @@ import { WebSocketLink } from "@apollo/client/link/ws";
import { RetryLink } from "@apollo/client/link/retry";
import { SubscriptionClient } from "subscriptions-transport-ws";
-
const subscriptionClient = new SubscriptionClient(Config.subscriptionEndpoint, {
- reconnect: true
+ reconnect: true,
});
-const link = new RetryLink().split(
+const link = new RetryLink({attempts: {max: 2}}).split(
(operation) => operation.operationName === 'subscription',
new WebSocketLink(subscriptionClient),
new HttpLink({ uri: Config.graphQLEndpoint, credentials: 'include' })
diff --git a/client/src/gql/queries/profile.tsx b/client/src/gql/queries/profile.tsx
index 128c394..573fc04 100644
--- a/client/src/gql/queries/profile.tsx
+++ b/client/src/gql/queries/profile.tsx
@@ -12,5 +12,5 @@ query userProfile {
}`;
export function useUserProfileQuery() {
- return useQuery(QUERY_USER_PROFILE, { fetchPolicy: "network-only" });
+ return useQuery(QUERY_USER_PROFILE);
}
\ No newline at end of file