From ec508d80b039f84686ad334f7f2bad8448d63480 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 7 Sep 2023 19:10:42 +0800 Subject: [PATCH 1/3] Use loading instead of validating to avoid flicker --- .../web/components/templates/homeFeed/LibraryFilterMenu.tsx | 4 ++-- packages/web/lib/networking/queries/useGetLabelsQuery.tsx | 3 +++ .../web/lib/networking/queries/useGetSubscriptionsQuery.tsx | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/web/components/templates/homeFeed/LibraryFilterMenu.tsx b/packages/web/components/templates/homeFeed/LibraryFilterMenu.tsx index 79d7a28ff..6ab19f3eb 100644 --- a/packages/web/components/templates/homeFeed/LibraryFilterMenu.tsx +++ b/packages/web/components/templates/homeFeed/LibraryFilterMenu.tsx @@ -32,9 +32,9 @@ type LibraryFilterMenuProps = { } export function LibraryFilterMenu(props: LibraryFilterMenuProps): JSX.Element { - const { labels, isValidating: labelsLoading } = useGetLabelsQuery() + const { labels, isLoading: labelsLoading } = useGetLabelsQuery() const { savedSearches, isLoading: searchesLoading } = useGetSavedSearchQuery() - const { subscriptions, isValidating: subscriptionsLoading } = + const { subscriptions, isLoading: subscriptionsLoading } = useGetSubscriptionsQuery() return ( diff --git a/packages/web/lib/networking/queries/useGetLabelsQuery.tsx b/packages/web/lib/networking/queries/useGetLabelsQuery.tsx index a4af02c2c..1c8995990 100644 --- a/packages/web/lib/networking/queries/useGetLabelsQuery.tsx +++ b/packages/web/lib/networking/queries/useGetLabelsQuery.tsx @@ -4,6 +4,7 @@ import { Label, labelFragment } from '../fragments/labelFragment' import { publicGqlFetcher } from '../networkHelpers' type LabelsQueryResponse = { + isLoading: boolean isValidating: boolean labels: Label[] revalidate: () => void @@ -41,6 +42,7 @@ export function useGetLabelsQuery(): LabelsQueryResponse { const result = data as LabelsResponseData const labels = result.labels?.labels as Label[] return { + isLoading: !error && !data, isValidating, labels, revalidate: () => { @@ -52,6 +54,7 @@ export function useGetLabelsQuery(): LabelsQueryResponse { console.log('error', error) } return { + isLoading: !error && !data, isValidating: false, labels: [], // eslint-disable-next-line @typescript-eslint/no-empty-function diff --git a/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx b/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx index 89bfccf99..4e5b26910 100644 --- a/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx +++ b/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx @@ -25,6 +25,7 @@ export type Subscription = { } type SubscriptionsQueryResponse = { + isLoading: boolean isValidating: boolean subscriptions: Subscription[] revalidate: () => void @@ -84,6 +85,7 @@ export function useGetSubscriptionsQuery( const result = data as SubscriptionsResponseData const subscriptions = result.subscriptions.subscriptions as Subscription[] return { + isLoading: !error && !data, isValidating, subscriptions, revalidate: () => { @@ -95,6 +97,7 @@ export function useGetSubscriptionsQuery( console.log('error', error) } return { + isLoading: !error && !data, isValidating: true, subscriptions: [], // eslint-disable-next-line @typescript-eslint/no-empty-function From e3d1a69c65a64b7ad1cc57e9a4d77d2a7084e9c4 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 7 Sep 2023 19:15:18 +0800 Subject: [PATCH 2/3] Fix SWR call --- packages/web/lib/networking/queries/useGetLabelsQuery.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web/lib/networking/queries/useGetLabelsQuery.tsx b/packages/web/lib/networking/queries/useGetLabelsQuery.tsx index 1c8995990..d6fefad8e 100644 --- a/packages/web/lib/networking/queries/useGetLabelsQuery.tsx +++ b/packages/web/lib/networking/queries/useGetLabelsQuery.tsx @@ -35,7 +35,7 @@ export function useGetLabelsQuery(): LabelsQueryResponse { ${labelFragment} ` - const { data, mutate, isValidating } = useSWR(query, publicGqlFetcher) + const { data, error, mutate, isValidating } = useSWR(query, publicGqlFetcher) try { if (data) { From 791f00067774a7c00fcf039a5c8c8af46cdee01e Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 7 Sep 2023 19:16:02 +0800 Subject: [PATCH 3/3] Fix SWR call --- .../web/lib/networking/queries/useGetSubscriptionsQuery.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx b/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx index 4e5b26910..4c0a26d17 100644 --- a/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx +++ b/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx @@ -75,7 +75,7 @@ export function useGetSubscriptionsQuery( by: sortBy, }, } - const { data, mutate, isValidating } = useSWR( + const { data, error, mutate, isValidating } = useSWR( [query, variables], makeGqlFetcher(variables) )