pl-fe: Disable some queries when unauthenticated
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
e546d787f0
commit
d3b5078030
3 changed files with 7 additions and 1 deletions
|
@ -3,6 +3,7 @@ import * as v from 'valibot';
|
||||||
import { Entities } from 'pl-fe/entity-store/entities';
|
import { Entities } from 'pl-fe/entity-store/entities';
|
||||||
import { useEntity } from 'pl-fe/entity-store/hooks/useEntity';
|
import { useEntity } from 'pl-fe/entity-store/hooks/useEntity';
|
||||||
import { useClient } from 'pl-fe/hooks/useClient';
|
import { useClient } from 'pl-fe/hooks/useClient';
|
||||||
|
import { useLoggedIn } from 'pl-fe/hooks/useLoggedIn';
|
||||||
|
|
||||||
import type { Relationship } from 'pl-api';
|
import type { Relationship } from 'pl-api';
|
||||||
|
|
||||||
|
@ -12,13 +13,14 @@ interface UseRelationshipOpts {
|
||||||
|
|
||||||
const useRelationship = (accountId: string | undefined, opts: UseRelationshipOpts = {}) => {
|
const useRelationship = (accountId: string | undefined, opts: UseRelationshipOpts = {}) => {
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
|
const { isLoggedIn } = useLoggedIn();
|
||||||
const { enabled = false } = opts;
|
const { enabled = false } = opts;
|
||||||
|
|
||||||
const { entity: relationship, ...result } = useEntity<Relationship>(
|
const { entity: relationship, ...result } = useEntity<Relationship>(
|
||||||
[Entities.RELATIONSHIPS, accountId!],
|
[Entities.RELATIONSHIPS, accountId!],
|
||||||
() => client.accounts.getRelationships([accountId!]),
|
() => client.accounts.getRelationships([accountId!]),
|
||||||
{
|
{
|
||||||
enabled: enabled && !!accountId,
|
enabled: enabled && isLoggedIn && !!accountId,
|
||||||
schema: v.pipe(v.any(), v.transform(arr => arr[0])),
|
schema: v.pipe(v.any(), v.transform(arr => arr[0])),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -289,6 +289,7 @@ const MediaGallery: React.FC<IMediaGallery> = (props) => {
|
||||||
height,
|
height,
|
||||||
visible,
|
visible,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [width, setWidth] = useState<number>(defaultWidth);
|
const [width, setWidth] = useState<number>(defaultWidth);
|
||||||
|
|
||||||
const node = useRef<HTMLDivElement>(null);
|
const node = useRef<HTMLDivElement>(null);
|
||||||
|
|
|
@ -3,12 +3,14 @@ import { useQuery } from '@tanstack/react-query';
|
||||||
import { fetchTrendsSuccess } from 'pl-fe/actions/trends';
|
import { fetchTrendsSuccess } from 'pl-fe/actions/trends';
|
||||||
import { useAppDispatch } from 'pl-fe/hooks/useAppDispatch';
|
import { useAppDispatch } from 'pl-fe/hooks/useAppDispatch';
|
||||||
import { useClient } from 'pl-fe/hooks/useClient';
|
import { useClient } from 'pl-fe/hooks/useClient';
|
||||||
|
import { useLoggedIn } from 'pl-fe/hooks/useLoggedIn';
|
||||||
|
|
||||||
import type { Tag } from 'pl-api';
|
import type { Tag } from 'pl-api';
|
||||||
|
|
||||||
const useTrends = () => {
|
const useTrends = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
|
const { isLoggedIn } = useLoggedIn();
|
||||||
|
|
||||||
const getTrends = async() => {
|
const getTrends = async() => {
|
||||||
const data = await client.trends.getTrendingTags();
|
const data = await client.trends.getTrendingTags();
|
||||||
|
@ -23,6 +25,7 @@ const useTrends = () => {
|
||||||
queryFn: getTrends,
|
queryFn: getTrends,
|
||||||
placeholderData: [],
|
placeholderData: [],
|
||||||
staleTime: 600000, // 10 minutes
|
staleTime: 600000, // 10 minutes
|
||||||
|
enabled: isLoggedIn,
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue