mirror of
https://github.com/tooot-app/app
synced 2025-04-18 04:07:33 +02:00
parent
e7ca5ba63d
commit
e5744aba06
@ -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':
|
||||
|
@ -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(() => {
|
||||
|
@ -13,7 +13,7 @@ export type Params = {
|
||||
}
|
||||
headers?: { [key: string]: string }
|
||||
body?: FormData
|
||||
extras?: Omit<AxiosRequestConfig, 'method' | 'url' | 'params' | 'headers' | 'data'>
|
||||
extras?: Omit<AxiosRequestConfig, 'method' | 'baseURL' | 'url' | 'params' | 'headers' | 'data'>
|
||||
}
|
||||
|
||||
const apiInstance = async <T = unknown>({
|
||||
|
@ -18,8 +18,8 @@ export type SearchResult = {
|
||||
statuses: Mastodon.Status[]
|
||||
}
|
||||
|
||||
const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeySearch>) => {
|
||||
const { type, term, limit = 20 } = queryKey[1]
|
||||
const queryFunction = async ({ queryKey, meta }: QueryFunctionContext<QueryKeySearch>) => {
|
||||
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<QueryKeySearch>)
|
||||
...(type && { type }),
|
||||
limit,
|
||||
resolve: true
|
||||
}
|
||||
},
|
||||
...(meta && { extras: meta })
|
||||
})
|
||||
return res.body
|
||||
}
|
||||
@ -50,7 +51,12 @@ const useSearchQuery = <T = SearchResult>({
|
||||
export const searchLocalStatus = async (uri: Mastodon.Status['uri']): Promise<Mastodon.Status> => {
|
||||
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<Mastodon.Account> => {
|
||||
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()))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user