about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2023-11-21 17:35:53 -0600
committerGitHub <noreply@github.com>2023-11-21 17:35:53 -0600
commit8da10a5edc11c916c250fc9694dab70837ca2b9b (patch)
treea505392485c91d81e8aac86c7d9fa8a2e9af0203 /src
parent47d2d3cbf289ebb2e893e07b5265aad8fcd64cb1 (diff)
downloadvoidsky-8da10a5edc11c916c250fc9694dab70837ca2b9b.tar.zst
Search page (#1969)
Diffstat (limited to 'src')
-rw-r--r--src/view/screens/Search/Search.tsx57
1 files changed, 51 insertions, 6 deletions
diff --git a/src/view/screens/Search/Search.tsx b/src/view/screens/Search/Search.tsx
index 9cd7ee370..5a25ce755 100644
--- a/src/view/screens/Search/Search.tsx
+++ b/src/view/screens/Search/Search.tsx
@@ -6,6 +6,7 @@ import {
   RefreshControl,
   TextInput,
   Pressable,
+  Platform,
 } from 'react-native'
 import {FlatList, ScrollView, CenteredView} from '#/view/com/util/Views'
 import {AppBskyActorDefs, AppBskyFeedDefs, moderateProfile} from '@atproto/api'
@@ -284,10 +285,17 @@ function SearchScreenUserResults({query}: {query: string}) {
 
   React.useEffect(() => {
     async function getResults() {
-      const searchResults = await search({query, limit: 30})
-
-      if (searchResults) {
-        setResults(results)
+      try {
+        const searchResults = await search({query, limit: 30})
+
+        if (searchResults) {
+          setResults(searchResults)
+        }
+      } catch (e: any) {
+        logger.error(`SearchScreenUserResults: failed to get results`, {
+          error: e.toString(),
+        })
+      } finally {
         setIsFetched(true)
       }
     }
@@ -298,7 +306,7 @@ function SearchScreenUserResults({query}: {query: string}) {
       setResults([])
       setIsFetched(false)
     }
-  }, [query, search, results])
+  }, [query, search, setResults])
 
   return isFetched ? (
     <>
@@ -327,6 +335,8 @@ export function SearchScreenInner({query}: {query?: string}) {
   const pal = usePalette('default')
   const setMinimalShellMode = useSetMinimalShellMode()
   const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled()
+  const {hasSession} = useSession()
+  const {isDesktop} = useWebMediaQueries()
 
   const onPageSelected = React.useCallback(
     (index: number) => {
@@ -353,7 +363,7 @@ export function SearchScreenInner({query}: {query?: string}) {
         <SearchScreenUserResults query={query} />
       </View>
     </Pager>
-  ) : (
+  ) : hasSession ? (
     <View>
       <CenteredView sideBorders style={pal.border}>
         <Text
@@ -371,8 +381,43 @@ export function SearchScreenInner({query}: {query?: string}) {
           <Trans>Suggested Follows</Trans>
         </Text>
       </CenteredView>
+
       <SearchScreenSuggestedFollows />
     </View>
+  ) : (
+    <CenteredView sideBorders style={pal.border}>
+      <View
+        // @ts-ignore web only -esb
+        style={{
+          height: Platform.select({web: '100vh'}),
+        }}>
+        {isDesktop && (
+          <Text
+            type="title"
+            style={[
+              pal.text,
+              pal.border,
+              {
+                display: 'flex',
+                paddingVertical: 12,
+                paddingHorizontal: 18,
+                fontWeight: 'bold',
+                borderBottomWidth: 1,
+              },
+            ]}>
+            <Trans>Search</Trans>
+          </Text>
+        )}
+
+        <Text
+          style={[
+            pal.textLight,
+            {textAlign: 'center', paddingVertical: 12, paddingHorizontal: 18},
+          ]}>
+          <Trans>Search for posts and users.</Trans>
+        </Text>
+      </View>
+    </CenteredView>
   )
 }