Few list tweaks on web (#3062)

* share button only on native

* update gttablet to be 1300px

* improve web layout

* change re-layout to mobile breakpoint

* adjustable not found reason

* don't show the borders on mobile web

* slight padding for the spinner
zio/stable
Hailey 2024-03-01 15:47:59 -08:00 committed by GitHub
parent e11bd4385d
commit 82655f2ee3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 20 deletions

View File

@ -17,7 +17,7 @@ const breakpoints: {
[key: string]: number [key: string]: number
} = { } = {
gtMobile: 800, gtMobile: 800,
gtTablet: 1200, gtTablet: 1300,
} }
function getActiveBreakpoints({width}: {width: number}) { function getActiveBreakpoints({width}: {width: number}) {
const active: (keyof typeof breakpoints)[] = Object.keys(breakpoints).filter( const active: (keyof typeof breakpoints)[] = Object.keys(breakpoints).filter(

View File

@ -9,6 +9,7 @@ import {Text} from '#/components/Typography'
import {StackActions} from '@react-navigation/native' import {StackActions} from '@react-navigation/native'
import {useNavigation} from '@react-navigation/core' import {useNavigation} from '@react-navigation/core'
import {NavigationProp} from 'lib/routes/types' import {NavigationProp} from 'lib/routes/types'
import {router} from '#/routes'
export function ListFooter({ export function ListFooter({
isFetching, isFetching,
@ -30,6 +31,7 @@ export function ListFooter({
a.align_center, a.align_center,
a.justify_center, a.justify_center,
a.border_t, a.border_t,
a.pb_lg,
t.atoms.border_contrast_low, t.atoms.border_contrast_low,
{height: 100}, {height: 100},
]}> ]}>
@ -128,6 +130,7 @@ export function ListMaybePlaceholder({
isError, isError,
empty, empty,
error, error,
notFoundType = 'page',
onRetry, onRetry,
}: { }: {
isLoading: boolean isLoading: boolean
@ -135,10 +138,12 @@ export function ListMaybePlaceholder({
isError: boolean isError: boolean
empty?: string empty?: string
error?: string error?: string
notFoundType?: 'page' | 'results'
onRetry?: () => Promise<unknown> onRetry?: () => Promise<unknown>
}) { }) {
const navigation = useNavigation<NavigationProp>() const navigation = useNavigation<NavigationProp>()
const t = useTheme() const t = useTheme()
const {gtMobile} = useBreakpoints()
const canGoBack = navigation.canGoBack() const canGoBack = navigation.canGoBack()
const onGoBack = React.useCallback(() => { const onGoBack = React.useCallback(() => {
@ -146,7 +151,14 @@ export function ListMaybePlaceholder({
navigation.goBack() navigation.goBack()
} else { } else {
navigation.navigate('HomeTab') navigation.navigate('HomeTab')
navigation.dispatch(StackActions.popToTop())
// Checking the state for routes ensures that web doesn't encounter errors while going back
if (navigation.getState()?.routes) {
navigation.dispatch(StackActions.push(...router.matchPath('/')))
} else {
navigation.navigate('HomeTab')
navigation.dispatch(StackActions.popToTop())
}
} }
}, [navigation, canGoBack]) }, [navigation, canGoBack])
@ -157,8 +169,7 @@ export function ListMaybePlaceholder({
style={[ style={[
a.flex_1, a.flex_1,
a.align_center, a.align_center,
a.border_t, !gtMobile ? [a.justify_between, a.border_t] : a.gap_5xl,
a.justify_between,
t.atoms.border_contrast_low, t.atoms.border_contrast_low,
{paddingTop: 175, paddingBottom: 110}, {paddingTop: 175, paddingBottom: 110},
]}> ]}>
@ -173,7 +184,13 @@ export function ListMaybePlaceholder({
{isError ? ( {isError ? (
<Trans>Oops!</Trans> <Trans>Oops!</Trans>
) : isEmpty ? ( ) : isEmpty ? (
<Trans>Page not found</Trans> <>
{notFoundType === 'results' ? (
<Trans>No results found</Trans>
) : (
<Trans>Page not found</Trans>
)}
</>
) : undefined} ) : undefined}
</Text> </Text>
@ -195,7 +212,8 @@ export function ListMaybePlaceholder({
</Text> </Text>
) : undefined} ) : undefined}
</View> </View>
<View style={[a.w_full, a.px_lg, a.gap_md]}> <View
style={[a.gap_md, !gtMobile ? [a.w_full, a.px_lg] : {width: 350}]}>
{isError && onRetry && ( {isError && onRetry && (
<Button <Button
variant="solid" variant="solid"

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import {ListRenderItemInfo, Pressable} from 'react-native' import {ListRenderItemInfo, Pressable} from 'react-native'
import {atoms as a} from '#/alf' import {atoms as a, useBreakpoints} from '#/alf'
import {useFocusEffect} from '@react-navigation/native' import {useFocusEffect} from '@react-navigation/native'
import {useSetMinimalShellMode} from 'state/shell' import {useSetMinimalShellMode} from 'state/shell'
import {ViewHeader} from 'view/com/util/ViewHeader' import {ViewHeader} from 'view/com/util/ViewHeader'
@ -23,6 +23,7 @@ import {CenteredView} from 'view/com/util/Views'
import {ArrowOutOfBox_Stroke2_Corner0_Rounded} from '#/components/icons/ArrowOutOfBox' import {ArrowOutOfBox_Stroke2_Corner0_Rounded} from '#/components/icons/ArrowOutOfBox'
import {shareUrl} from 'lib/sharing' import {shareUrl} from 'lib/sharing'
import {HITSLOP_10} from 'lib/constants' import {HITSLOP_10} from 'lib/constants'
import {isNative} from 'platform/detection'
const renderItem = ({item}: ListRenderItemInfo<PostView>) => { const renderItem = ({item}: ListRenderItemInfo<PostView>) => {
return <Post post={item} /> return <Post post={item} />
@ -37,6 +38,7 @@ export default function HashtagScreen({
}: NativeStackScreenProps<CommonNavigatorParams, 'Hashtag'>) { }: NativeStackScreenProps<CommonNavigatorParams, 'Hashtag'>) {
const {tag, author} = route.params const {tag, author} = route.params
const setMinimalShellMode = useSetMinimalShellMode() const setMinimalShellMode = useSetMinimalShellMode()
const {gtMobile} = useBreakpoints()
const {_} = useLingui() const {_} = useLingui()
const [isPTR, setIsPTR] = React.useState(false) const [isPTR, setIsPTR] = React.useState(false)
@ -101,28 +103,33 @@ export default function HashtagScreen({
}, [isFetching, hasNextPage, error, fetchNextPage]) }, [isFetching, hasNextPage, error, fetchNextPage])
return ( return (
<CenteredView style={a.flex_1}> <CenteredView style={a.flex_1} sideBorders={gtMobile}>
<ViewHeader <ViewHeader
title={headerTitle} title={headerTitle}
subtitle={author ? _(msg`From @${sanitizedAuthor}`) : undefined} subtitle={author ? _(msg`From @${sanitizedAuthor}`) : undefined}
canGoBack={true} canGoBack
renderButton={() => ( renderButton={
<Pressable isNative
accessibilityRole="button" ? () => (
onPress={onShare} <Pressable
hitSlop={HITSLOP_10}> accessibilityRole="button"
<ArrowOutOfBox_Stroke2_Corner0_Rounded onPress={onShare}
size="lg" hitSlop={HITSLOP_10}>
onPress={onShare} <ArrowOutOfBox_Stroke2_Corner0_Rounded
/> size="lg"
</Pressable> onPress={onShare}
)} />
</Pressable>
)
: undefined
}
/> />
<ListMaybePlaceholder <ListMaybePlaceholder
isLoading={isLoading || isRefetching} isLoading={isLoading || isRefetching}
isError={isError} isError={isError}
isEmpty={posts.length < 1} isEmpty={posts.length < 1}
onRetry={refetch} onRetry={refetch}
notFoundType="results"
empty={_(msg`We couldn't find any results for that hashtag.`)} empty={_(msg`We couldn't find any results for that hashtag.`)}
/> />
{!isLoading && posts.length > 0 && ( {!isLoading && posts.length > 0 && (