From 4269c1d9d1688edeadf4357a39d1ac0a6e692179 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Sat, 25 Feb 2023 16:52:38 +0100 Subject: [PATCH] Refine adding remote instance --- src/i18n/en/screens/tabs.json | 6 +++- src/screens/Tabs/Public/Root.tsx | 36 ++++++++++++++++++++--- src/screens/Tabs/Shared/Account/index.tsx | 1 + 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/i18n/en/screens/tabs.json b/src/i18n/en/screens/tabs.json index 615c4db5..f80ea938 100644 --- a/src/i18n/en/screens/tabs.json +++ b/src/i18n/en/screens/tabs.json @@ -17,7 +17,11 @@ "heading": "Exploring", "trending": "Trending", "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": { diff --git a/src/screens/Tabs/Public/Root.tsx b/src/screens/Tabs/Public/Root.tsx index 5fb2e296..407d5bfb 100644 --- a/src/screens/Tabs/Public/Root.tsx +++ b/src/screens/Tabs/Public/Root.tsx @@ -1,6 +1,8 @@ import Button from '@components/Button' +import haptics from '@components/haptics' import { HeaderLeft, HeaderRight } from '@components/Header' import Icon from '@components/Icon' +import { displayMessage } from '@components/Message' import CustomText from '@components/Text' import Timeline from '@components/Timeline' 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 { colors, mode } = useTheme() + const [loading, setLoading] = useState(false) const [addingRemote, setAddingRemote] = useState(false) const [domain, setDomain] = useState('') const [domainValid, setDomainValid] = useState() @@ -38,7 +41,14 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => { retry: false, keepPreviousData: false, 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({ method: 'get', domain: domain, @@ -46,17 +56,31 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => { params: { local: 'true', limit: 1 } }) .then(({ body }) => { + setLoading(false) if (Array.isArray(body)) { setDomainValid(true) } else { + displayMessage({ + type: 'danger', + message: t('screenTabs:tabs.public.exploring.errors.notAvailable') + }) setDomainValid(false) } }) - .catch(() => setDomainValid(false)) + .catch(() => { + displayMessage({ + type: 'danger', + message: t('screenTabs:tabs.public.exploring.errors.notAvailable') + }) + setLoading(false) + setDomainValid(false) + }) + } } }) const debounceFetch = useCallback( debounce(() => { + setLoading(true) instanceQuery.refetch() }, 1000), [] @@ -124,6 +148,8 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => { disableRefresh={!remoteActive} refreshAutoRefetch={false} customProps={{ + keyboardDismissMode: 'on-drag', + keyboardShouldPersistTaps: 'always', stickyHeaderIndices: [0], stickyHeaderHiddenOnScroll: true, ListHeaderComponent: ( @@ -229,15 +255,16 @@ const Explore = ({ route: { key: page } }: { route: { key: 'Explore' } }) => {