mirror of
https://github.com/tooot-app/app
synced 2025-04-25 15:38:42 +02:00
parent
e7ca5ba63d
commit
e5744aba06
@ -9,13 +9,7 @@ import { getGlobalStorage } from '@utils/storage/actions'
|
|||||||
import * as Linking from 'expo-linking'
|
import * as Linking from 'expo-linking'
|
||||||
import * as WebBrowser from 'expo-web-browser'
|
import * as WebBrowser from 'expo-web-browser'
|
||||||
|
|
||||||
export let loadingLink = false
|
|
||||||
|
|
||||||
const openLink = async (url: string, navigation?: any) => {
|
const openLink = async (url: string, navigation?: any) => {
|
||||||
if (loadingLink) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleNavigation = (page: 'Tab-Shared-Toot' | 'Tab-Shared-Account', options: any) => {
|
const handleNavigation = (page: 'Tab-Shared-Toot' | 'Tab-Shared-Account', options: any) => {
|
||||||
if (navigation) {
|
if (navigation) {
|
||||||
navigation.push(page, options)
|
navigation.push(page, options)
|
||||||
@ -28,7 +22,6 @@ const openLink = async (url: string, navigation?: any) => {
|
|||||||
const match = urlMatcher(url)
|
const match = urlMatcher(url)
|
||||||
// If a tooot can be found
|
// If a tooot can be found
|
||||||
if (match?.status?.id) {
|
if (match?.status?.id) {
|
||||||
loadingLink = true
|
|
||||||
let response: Mastodon.Status | undefined = undefined
|
let response: Mastodon.Status | undefined = undefined
|
||||||
|
|
||||||
const queryKey: QueryKeyStatus = [
|
const queryKey: QueryKeyStatus = [
|
||||||
@ -39,7 +32,6 @@ const openLink = async (url: string, navigation?: any) => {
|
|||||||
|
|
||||||
if (cache) {
|
if (cache) {
|
||||||
handleNavigation('Tab-Shared-Toot', { toot: cache })
|
handleNavigation('Tab-Shared-Toot', { toot: cache })
|
||||||
loadingLink = false
|
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@ -47,7 +39,6 @@ const openLink = async (url: string, navigation?: any) => {
|
|||||||
} catch {}
|
} catch {}
|
||||||
if (response) {
|
if (response) {
|
||||||
handleNavigation('Tab-Shared-Toot', { toot: response })
|
handleNavigation('Tab-Shared-Toot', { toot: response })
|
||||||
loadingLink = false
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,7 +51,6 @@ const openLink = async (url: string, navigation?: any) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
loadingLink = true
|
|
||||||
let response: Mastodon.Account | undefined = undefined
|
let response: Mastodon.Account | undefined = undefined
|
||||||
|
|
||||||
const queryKey: QueryKeyAccount = [
|
const queryKey: QueryKeyAccount = [
|
||||||
@ -71,7 +61,6 @@ const openLink = async (url: string, navigation?: any) => {
|
|||||||
|
|
||||||
if (cache) {
|
if (cache) {
|
||||||
handleNavigation('Tab-Shared-Account', { account: cache })
|
handleNavigation('Tab-Shared-Account', { account: cache })
|
||||||
loadingLink = false
|
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@ -79,13 +68,11 @@ const openLink = async (url: string, navigation?: any) => {
|
|||||||
} catch {}
|
} catch {}
|
||||||
if (response) {
|
if (response) {
|
||||||
handleNavigation('Tab-Shared-Account', { account: response })
|
handleNavigation('Tab-Shared-Account', { account: response })
|
||||||
loadingLink = false
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadingLink = false
|
|
||||||
switch (getGlobalStorage.string('app.browser')) {
|
switch (getGlobalStorage.string('app.browser')) {
|
||||||
// Some links might end with an empty space at the end that triggers an error
|
// Some links might end with an empty space at the end that triggers an error
|
||||||
case 'internal':
|
case 'internal':
|
||||||
|
@ -38,7 +38,6 @@ const ComposeRootSuggestions: React.FC = () => {
|
|||||||
const { isFetching, data, refetch } = useSearchQuery({
|
const { isFetching, data, refetch } = useSearchQuery({
|
||||||
type: mapSchemaToType(),
|
type: mapSchemaToType(),
|
||||||
term: composeState.tag?.raw.substring(1),
|
term: composeState.tag?.raw.substring(1),
|
||||||
limit: 10,
|
|
||||||
options: { enabled: false }
|
options: { enabled: false }
|
||||||
})
|
})
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -13,7 +13,7 @@ export type Params = {
|
|||||||
}
|
}
|
||||||
headers?: { [key: string]: string }
|
headers?: { [key: string]: string }
|
||||||
body?: FormData
|
body?: FormData
|
||||||
extras?: Omit<AxiosRequestConfig, 'method' | 'url' | 'params' | 'headers' | 'data'>
|
extras?: Omit<AxiosRequestConfig, 'method' | 'baseURL' | 'url' | 'params' | 'headers' | 'data'>
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiInstance = async <T = unknown>({
|
const apiInstance = async <T = unknown>({
|
||||||
|
@ -18,8 +18,8 @@ export type SearchResult = {
|
|||||||
statuses: Mastodon.Status[]
|
statuses: Mastodon.Status[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeySearch>) => {
|
const queryFunction = async ({ queryKey, meta }: QueryFunctionContext<QueryKeySearch>) => {
|
||||||
const { type, term, limit = 20 } = queryKey[1]
|
const { type, term, limit = 10 } = queryKey[1]
|
||||||
if (!term?.length) {
|
if (!term?.length) {
|
||||||
return Promise.reject('Empty search term')
|
return Promise.reject('Empty search term')
|
||||||
}
|
}
|
||||||
@ -32,7 +32,8 @@ const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeySearch>)
|
|||||||
...(type && { type }),
|
...(type && { type }),
|
||||||
limit,
|
limit,
|
||||||
resolve: true
|
resolve: true
|
||||||
}
|
},
|
||||||
|
...(meta && { extras: meta })
|
||||||
})
|
})
|
||||||
return res.body
|
return res.body
|
||||||
}
|
}
|
||||||
@ -50,7 +51,12 @@ const useSearchQuery = <T = SearchResult>({
|
|||||||
export const searchLocalStatus = async (uri: Mastodon.Status['uri']): Promise<Mastodon.Status> => {
|
export const searchLocalStatus = async (uri: Mastodon.Status['uri']): Promise<Mastodon.Status> => {
|
||||||
const queryKey: QueryKeySearch = ['Search', { type: 'statuses', term: uri, limit: 1 }]
|
const queryKey: QueryKeySearch = ['Search', { type: 'statuses', term: uri, limit: 1 }]
|
||||||
return await queryClient
|
return await queryClient
|
||||||
.fetchQuery(queryKey, queryFunction, { staleTime: 3600, cacheTime: 3600 })
|
.fetchQuery(queryKey, queryFunction, {
|
||||||
|
staleTime: 3600,
|
||||||
|
cacheTime: 3600,
|
||||||
|
retry: false,
|
||||||
|
meta: { timeout: 1000 }
|
||||||
|
})
|
||||||
.then(res =>
|
.then(res =>
|
||||||
res.statuses[0]?.uri === uri || res.statuses[0]?.url === uri
|
res.statuses[0]?.uri === uri || res.statuses[0]?.url === uri
|
||||||
? res.statuses[0]
|
? res.statuses[0]
|
||||||
@ -63,7 +69,12 @@ export const searchLocalAccount = async (
|
|||||||
): Promise<Mastodon.Account> => {
|
): Promise<Mastodon.Account> => {
|
||||||
const queryKey: QueryKeySearch = ['Search', { type: 'accounts', term: url, limit: 1 }]
|
const queryKey: QueryKeySearch = ['Search', { type: 'accounts', term: url, limit: 1 }]
|
||||||
return await queryClient
|
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()))
|
.then(res => (res.accounts[0].url === url ? res.accounts[0] : Promise.reject()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user