mirror of
https://github.com/tooot-app/app
synced 2025-02-28 17:48:12 +01:00
Fix #614
This commit is contained in:
parent
3594500b3e
commit
64b367a247
@ -2,6 +2,7 @@ import Icon from '@components/Icon'
|
|||||||
import openLink from '@components/openLink'
|
import openLink from '@components/openLink'
|
||||||
import ParseEmojis from '@components/Parse/Emojis'
|
import ParseEmojis from '@components/Parse/Emojis'
|
||||||
import CustomText from '@components/Text'
|
import CustomText from '@components/Text'
|
||||||
|
import { getHost } from '@helpers/urlMatcher'
|
||||||
import { useNavigation, useRoute } from '@react-navigation/native'
|
import { useNavigation, useRoute } from '@react-navigation/native'
|
||||||
import { StackNavigationProp } from '@react-navigation/stack'
|
import { StackNavigationProp } from '@react-navigation/stack'
|
||||||
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
||||||
@ -13,7 +14,7 @@ import { useTheme } from '@utils/styles/ThemeManager'
|
|||||||
import { isEqual } from 'lodash'
|
import { isEqual } from 'lodash'
|
||||||
import React, { useCallback, useState } from 'react'
|
import React, { useCallback, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { Platform, Pressable, TextStyleIOS, View } from 'react-native'
|
import { Pressable, TextStyleIOS, View } from 'react-native'
|
||||||
import HTMLView from 'react-native-htmlview'
|
import HTMLView from 'react-native-htmlview'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ const renderNode = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const domain = href?.split(new RegExp(/:\/\/(.[^\/]+\/.{3})/))
|
const host = getHost(href)
|
||||||
// Need example here
|
// Need example here
|
||||||
const content = node.children && node.children[0] && node.children[0].data
|
const content = node.children && node.children[0] && node.children[0].data
|
||||||
const shouldBeTag = tags && tags.filter(tag => `#${tag.name}` === content).length > 0
|
const shouldBeTag = tags && tags.filter(tag => `#${tag.name}` === content).length > 0
|
||||||
@ -127,8 +128,8 @@ const renderNode = ({
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{content && content !== href ? content : showFullLink ? href : domain?.[1]}
|
{content && content !== href ? content : showFullLink ? href : host}
|
||||||
{!shouldBeTag ? '...' : null}
|
{!shouldBeTag ? '/...' : null}
|
||||||
</CustomText>
|
</CustomText>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
import { store } from '@root/store'
|
import { store } from '@root/store'
|
||||||
import { getInstanceUrl } from '@utils/slices/instancesSlice'
|
import { getInstanceUrl } from '@utils/slices/instancesSlice'
|
||||||
|
|
||||||
|
const getHost = (url: unknown): string | void => {
|
||||||
|
if (typeof url !== 'string') return undefined
|
||||||
|
|
||||||
|
const matches = url.match(/^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/i)
|
||||||
|
return matches?.[1]
|
||||||
|
}
|
||||||
|
|
||||||
const matchStatus = (
|
const matchStatus = (
|
||||||
url: string
|
url: string
|
||||||
): { id: string; style: 'default' | 'pretty'; sameInstance: boolean } | null => {
|
): { id: string; style: 'default' | 'pretty'; sameInstance: boolean } | null => {
|
||||||
@ -53,4 +60,4 @@ const matchAccount = (
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export { matchStatus, matchAccount }
|
export { getHost, matchStatus, matchAccount }
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
import apiGeneral from '@api/general'
|
import apiGeneral from '@api/general'
|
||||||
import { PagedResponse } from '@api/helpers'
|
import { PagedResponse } from '@api/helpers'
|
||||||
|
import { getHost } from '@helpers/urlMatcher'
|
||||||
|
|
||||||
export type QueryKeyUsers = ['Users', TabSharedStackParamList['Tab-Shared-Users']]
|
export type QueryKeyUsers = ['Users', TabSharedStackParamList['Tab-Shared-Users']]
|
||||||
|
|
||||||
@ -38,9 +39,7 @@ const queryFunction = async ({
|
|||||||
let res: PagedResponse<Mastodon.Account[]>
|
let res: PagedResponse<Mastodon.Account[]>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const domain = page.account.url.match(
|
const domain = getHost(page.account.url)
|
||||||
/^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/i
|
|
||||||
)?.[1]
|
|
||||||
if (!domain?.length) {
|
if (!domain?.length) {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user