diff --git a/src/components/openLink.ts b/src/components/openLink.ts index e096e313..3cda22bf 100644 --- a/src/components/openLink.ts +++ b/src/components/openLink.ts @@ -9,13 +9,7 @@ import { getGlobalStorage } from '@utils/storage/actions' import * as Linking from 'expo-linking' import * as WebBrowser from 'expo-web-browser' -export let loadingLink = false - const openLink = async (url: string, navigation?: any) => { - if (loadingLink) { - return - } - const handleNavigation = (page: 'Tab-Shared-Toot' | 'Tab-Shared-Account', options: any) => { if (navigation) { navigation.push(page, options) @@ -28,7 +22,6 @@ const openLink = async (url: string, navigation?: any) => { const match = urlMatcher(url) // If a tooot can be found if (match?.status?.id) { - loadingLink = true let response: Mastodon.Status | undefined = undefined const queryKey: QueryKeyStatus = [ @@ -39,7 +32,6 @@ const openLink = async (url: string, navigation?: any) => { if (cache) { handleNavigation('Tab-Shared-Toot', { toot: cache }) - loadingLink = false return } else { try { @@ -47,7 +39,6 @@ const openLink = async (url: string, navigation?: any) => { } catch {} if (response) { handleNavigation('Tab-Shared-Toot', { toot: response }) - loadingLink = false return } } @@ -60,7 +51,6 @@ const openLink = async (url: string, navigation?: any) => { return } - loadingLink = true let response: Mastodon.Account | undefined = undefined const queryKey: QueryKeyAccount = [ @@ -71,7 +61,6 @@ const openLink = async (url: string, navigation?: any) => { if (cache) { handleNavigation('Tab-Shared-Account', { account: cache }) - loadingLink = false return } else { try { @@ -79,13 +68,11 @@ const openLink = async (url: string, navigation?: any) => { } catch {} if (response) { handleNavigation('Tab-Shared-Account', { account: response }) - loadingLink = false return } } } - loadingLink = false switch (getGlobalStorage.string('app.browser')) { // Some links might end with an empty space at the end that triggers an error case 'internal': diff --git a/src/screens/Compose/Root/Suggestions.tsx b/src/screens/Compose/Root/Suggestions.tsx index b1ae64e9..89439541 100644 --- a/src/screens/Compose/Root/Suggestions.tsx +++ b/src/screens/Compose/Root/Suggestions.tsx @@ -38,7 +38,6 @@ const ComposeRootSuggestions: React.FC = () => { const { isFetching, data, refetch } = useSearchQuery({ type: mapSchemaToType(), term: composeState.tag?.raw.substring(1), - limit: 10, options: { enabled: false } }) useEffect(() => { diff --git a/src/utils/api/instance.ts b/src/utils/api/instance.ts index 9c71dadd..64f5b318 100644 --- a/src/utils/api/instance.ts +++ b/src/utils/api/instance.ts @@ -13,7 +13,7 @@ export type Params = { } headers?: { [key: string]: string } body?: FormData - extras?: Omit + extras?: Omit } const apiInstance = async ({ diff --git a/src/utils/queryHooks/search.ts b/src/utils/queryHooks/search.ts index 0f75cdc9..aafceff8 100644 --- a/src/utils/queryHooks/search.ts +++ b/src/utils/queryHooks/search.ts @@ -18,8 +18,8 @@ export type SearchResult = { statuses: Mastodon.Status[] } -const queryFunction = async ({ queryKey }: QueryFunctionContext) => { - const { type, term, limit = 20 } = queryKey[1] +const queryFunction = async ({ queryKey, meta }: QueryFunctionContext) => { + const { type, term, limit = 10 } = queryKey[1] if (!term?.length) { return Promise.reject('Empty search term') } @@ -32,7 +32,8 @@ const queryFunction = async ({ queryKey }: QueryFunctionContext) ...(type && { type }), limit, resolve: true - } + }, + ...(meta && { extras: meta }) }) return res.body } @@ -50,7 +51,12 @@ const useSearchQuery = ({ export const searchLocalStatus = async (uri: Mastodon.Status['uri']): Promise => { const queryKey: QueryKeySearch = ['Search', { type: 'statuses', term: uri, limit: 1 }] return await queryClient - .fetchQuery(queryKey, queryFunction, { staleTime: 3600, cacheTime: 3600 }) + .fetchQuery(queryKey, queryFunction, { + staleTime: 3600, + cacheTime: 3600, + retry: false, + meta: { timeout: 1000 } + }) .then(res => res.statuses[0]?.uri === uri || res.statuses[0]?.url === uri ? res.statuses[0] @@ -63,7 +69,12 @@ export const searchLocalAccount = async ( ): Promise => { const queryKey: QueryKeySearch = ['Search', { type: 'accounts', term: url, limit: 1 }] return await queryClient - .fetchQuery(queryKey, queryFunction, { staleTime: 3600, cacheTime: 3600 }) + .fetchQuery(queryKey, queryFunction, { + staleTime: 3600, + cacheTime: 3600, + retry: false, + meta: { timeout: 1000 } + }) .then(res => (res.accounts[0].url === url ? res.accounts[0] : Promise.reject())) }