From d3b5078030a4acf2d952929fdf4cfee0d03b7cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 25 Oct 2024 20:41:14 +0200 Subject: [PATCH] pl-fe: Disable some queries when unauthenticated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- packages/pl-fe/src/api/hooks/accounts/useRelationship.ts | 4 +++- packages/pl-fe/src/components/media-gallery.tsx | 1 + packages/pl-fe/src/queries/trends.ts | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/pl-fe/src/api/hooks/accounts/useRelationship.ts b/packages/pl-fe/src/api/hooks/accounts/useRelationship.ts index 1d009d87f..e2bce4815 100644 --- a/packages/pl-fe/src/api/hooks/accounts/useRelationship.ts +++ b/packages/pl-fe/src/api/hooks/accounts/useRelationship.ts @@ -3,6 +3,7 @@ import * as v from 'valibot'; import { Entities } from 'pl-fe/entity-store/entities'; import { useEntity } from 'pl-fe/entity-store/hooks/useEntity'; import { useClient } from 'pl-fe/hooks/useClient'; +import { useLoggedIn } from 'pl-fe/hooks/useLoggedIn'; import type { Relationship } from 'pl-api'; @@ -12,13 +13,14 @@ interface UseRelationshipOpts { const useRelationship = (accountId: string | undefined, opts: UseRelationshipOpts = {}) => { const client = useClient(); + const { isLoggedIn } = useLoggedIn(); const { enabled = false } = opts; const { entity: relationship, ...result } = useEntity( [Entities.RELATIONSHIPS, accountId!], () => client.accounts.getRelationships([accountId!]), { - enabled: enabled && !!accountId, + enabled: enabled && isLoggedIn && !!accountId, schema: v.pipe(v.any(), v.transform(arr => arr[0])), }, ); diff --git a/packages/pl-fe/src/components/media-gallery.tsx b/packages/pl-fe/src/components/media-gallery.tsx index 9a5d2d81d..af99025bb 100644 --- a/packages/pl-fe/src/components/media-gallery.tsx +++ b/packages/pl-fe/src/components/media-gallery.tsx @@ -289,6 +289,7 @@ const MediaGallery: React.FC = (props) => { height, visible, } = props; + const [width, setWidth] = useState(defaultWidth); const node = useRef(null); diff --git a/packages/pl-fe/src/queries/trends.ts b/packages/pl-fe/src/queries/trends.ts index 812af9689..29f3b3b9d 100644 --- a/packages/pl-fe/src/queries/trends.ts +++ b/packages/pl-fe/src/queries/trends.ts @@ -3,12 +3,14 @@ import { useQuery } from '@tanstack/react-query'; import { fetchTrendsSuccess } from 'pl-fe/actions/trends'; import { useAppDispatch } from 'pl-fe/hooks/useAppDispatch'; import { useClient } from 'pl-fe/hooks/useClient'; +import { useLoggedIn } from 'pl-fe/hooks/useLoggedIn'; import type { Tag } from 'pl-api'; const useTrends = () => { const dispatch = useAppDispatch(); const client = useClient(); + const { isLoggedIn } = useLoggedIn(); const getTrends = async() => { const data = await client.trends.getTrendingTags(); @@ -23,6 +25,7 @@ const useTrends = () => { queryFn: getTrends, placeholderData: [], staleTime: 600000, // 10 minutes + enabled: isLoggedIn, }); return result;