1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Refine adding remote instance

This commit is contained in:
xmflsct
2023-02-25 16:52:38 +01:00
parent 35eb7ba765
commit 4269c1d9d1
3 changed files with 38 additions and 5 deletions

View File

@ -17,7 +17,11 @@
"heading": "Exploring", "heading": "Exploring",
"trending": "Trending", "trending": "Trending",
"followRemote": "Follow remote instance", "followRemote": "Follow remote instance",
"noTitle": "No Title" "noTitle": "No Title",
"errors": {
"existed": "You are already following this remote instance.",
"notAvailable": "This instance's timeline is not public accessible. Please try another instance."
}
} }
}, },
"notifications": { "notifications": {

View File

@ -1,6 +1,8 @@
import Button from '@components/Button' import Button from '@components/Button'
import haptics from '@components/haptics'
import { HeaderLeft, HeaderRight } from '@components/Header' import { HeaderLeft, HeaderRight } from '@components/Header'
import Icon from '@components/Icon' import Icon from '@components/Icon'
import { displayMessage } from '@components/Message'
import CustomText from '@components/Text' import CustomText from '@components/Text'
import Timeline from '@components/Timeline' import Timeline from '@components/Timeline'
import SegmentedControl from '@react-native-segmented-control/segmented-control' import SegmentedControl from '@react-native-segmented-control/segmented-control'
@ -28,6 +30,7 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => {
const { t } = useTranslation(['common', 'componentInstance', 'screenTabs']) const { t } = useTranslation(['common', 'componentInstance', 'screenTabs'])
const { colors, mode } = useTheme() const { colors, mode } = useTheme()
const [loading, setLoading] = useState(false)
const [addingRemote, setAddingRemote] = useState(false) const [addingRemote, setAddingRemote] = useState(false)
const [domain, setDomain] = useState<string>('') const [domain, setDomain] = useState<string>('')
const [domainValid, setDomainValid] = useState<boolean>() const [domainValid, setDomainValid] = useState<boolean>()
@ -38,7 +41,14 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => {
retry: false, retry: false,
keepPreviousData: false, keepPreviousData: false,
cacheTime: 1000 * 30, cacheTime: 1000 * 30,
onSuccess: () => onError: () => setLoading(false),
onSuccess: () => {
if (!!remotes?.find(r => r.domain === domain)) {
displayMessage({
type: 'warning',
message: t('screenTabs:tabs.public.exploring.errors.existed')
})
}
apiGeneral<Mastodon.Status[]>({ apiGeneral<Mastodon.Status[]>({
method: 'get', method: 'get',
domain: domain, domain: domain,
@ -46,17 +56,31 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => {
params: { local: 'true', limit: 1 } params: { local: 'true', limit: 1 }
}) })
.then(({ body }) => { .then(({ body }) => {
setLoading(false)
if (Array.isArray(body)) { if (Array.isArray(body)) {
setDomainValid(true) setDomainValid(true)
} else { } else {
displayMessage({
type: 'danger',
message: t('screenTabs:tabs.public.exploring.errors.notAvailable')
})
setDomainValid(false) setDomainValid(false)
} }
}) })
.catch(() => setDomainValid(false)) .catch(() => {
displayMessage({
type: 'danger',
message: t('screenTabs:tabs.public.exploring.errors.notAvailable')
})
setLoading(false)
setDomainValid(false)
})
}
} }
}) })
const debounceFetch = useCallback( const debounceFetch = useCallback(
debounce(() => { debounce(() => {
setLoading(true)
instanceQuery.refetch() instanceQuery.refetch()
}, 1000), }, 1000),
[] []
@ -124,6 +148,8 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => {
disableRefresh={!remoteActive} disableRefresh={!remoteActive}
refreshAutoRefetch={false} refreshAutoRefetch={false}
customProps={{ customProps={{
keyboardDismissMode: 'on-drag',
keyboardShouldPersistTaps: 'always',
stickyHeaderIndices: [0], stickyHeaderIndices: [0],
stickyHeaderHiddenOnScroll: true, stickyHeaderHiddenOnScroll: true,
ListHeaderComponent: ( ListHeaderComponent: (
@ -229,15 +255,16 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => {
<Button <Button
type='text' type='text'
content={t('common:buttons.add')} content={t('common:buttons.add')}
loading={instanceQuery.isFetching} loading={loading}
disabled={ disabled={
!!domain.length !!domain.length
? domainValid === false || ? !domainValid ||
accountActive === domain || accountActive === domain ||
!!remotes?.find(r => r.domain === domain) !!remotes?.find(r => r.domain === domain)
: true : true
} }
onPress={() => { onPress={() => {
haptics('Success')
setRemotes([ setRemotes([
...(remotes || []), ...(remotes || []),
{ {
@ -338,6 +365,7 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => {
setRemoteActive(item.domain) setRemoteActive(item.domain)
} else if (next === 'off') { } else if (next === 'off') {
const nextRemotes = remotes?.filter(r => r.domain !== item.domain) const nextRemotes = remotes?.filter(r => r.domain !== item.domain)
haptics('Light')
setRemotes(nextRemotes) setRemotes(nextRemotes)
setRemoteActive(nextRemotes.at(-1)?.domain) setRemoteActive(nextRemotes.at(-1)?.domain)
} }

View File

@ -258,6 +258,7 @@ const TabSharedAccount: React.FC<TabSharedStackScreenProps<'Tab-Shared-Account'>
disableRefresh disableRefresh
queryOptions={{ enabled: account._remote ? !!data?.id : true }} queryOptions={{ enabled: account._remote ? !!data?.id : true }}
customProps={{ customProps={{
keyboardShouldPersistTaps: 'always',
renderItem: ({ item }) => <TimelineDefault item={item} queryKey={queryKey} />, renderItem: ({ item }) => <TimelineDefault item={item} queryKey={queryKey} />,
onScroll: ({ nativeEvent }) => (scrollY.value = nativeEvent.contentOffset.y), onScroll: ({ nativeEvent }) => (scrollY.value = nativeEvent.contentOffset.y),
ListHeaderComponent, ListHeaderComponent,