[PWI] Shell (#1967)

* Sidebars

* Bottom bar

* Drawer

* Translate

* Spacing fix

* Fix responsive regression

* Fix nit
zio/stable
Eric Bailey 2023-11-21 16:58:13 -06:00 committed by GitHub
parent 4c4ba553bd
commit 47d2d3cbf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 416 additions and 289 deletions

View File

@ -43,7 +43,13 @@ interface PreviewableUserAvatarProps extends BaseUserAvatarProps {
const BLUR_AMOUNT = isWeb ? 5 : 100 const BLUR_AMOUNT = isWeb ? 5 : 100
function DefaultAvatar({type, size}: {type: UserAvatarType; size: number}) { export function DefaultAvatar({
type,
size,
}: {
type: UserAvatarType
size: number
}) {
if (type === 'algo') { if (type === 'algo') {
// Font Awesome Pro 6.4.0 by @fontawesome -https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. // Font Awesome Pro 6.4.0 by @fontawesome -https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc.
return ( return (

View File

@ -52,6 +52,7 @@ import {useUnreadNotifications} from '#/state/queries/notifications/unread'
import {emitSoftReset} from '#/state/events' import {emitSoftReset} from '#/state/events'
import {useInviteCodesQuery} from '#/state/queries/invites' import {useInviteCodesQuery} from '#/state/queries/invites'
import {RQKEY as NOTIFS_RQKEY} from '#/state/queries/notifications/feed' import {RQKEY as NOTIFS_RQKEY} from '#/state/queries/notifications/feed'
import {NavSignupCard} from '#/view/shell/NavSignupCard'
export function DrawerProfileCard({ export function DrawerProfileCard({
account, account,
@ -112,7 +113,7 @@ export function DrawerContent() {
const {track} = useAnalytics() const {track} = useAnalytics()
const {isAtHome, isAtSearch, isAtFeeds, isAtNotifications, isAtMyProfile} = const {isAtHome, isAtSearch, isAtFeeds, isAtNotifications, isAtMyProfile} =
useNavigationTabState() useNavigationTabState()
const {currentAccount} = useSession() const {hasSession, currentAccount} = useSession()
const numUnreadNotifications = useUnreadNotifications() const numUnreadNotifications = useUnreadNotifications()
// events // events
@ -218,18 +219,20 @@ export function DrawerContent() {
]}> ]}>
<SafeAreaView style={s.flex1}> <SafeAreaView style={s.flex1}>
<ScrollView style={styles.main}> <ScrollView style={styles.main}>
{hasSession && currentAccount ? (
<View style={{}}> <View style={{}}>
{currentAccount && (
<DrawerProfileCard <DrawerProfileCard
account={currentAccount} account={currentAccount}
onPressProfile={onPressProfile} onPressProfile={onPressProfile}
/> />
)}
</View> </View>
) : (
<NavSignupCard />
)}
<InviteCodes style={{paddingLeft: 0}} /> {hasSession && <InviteCodes style={{paddingLeft: 0}} />}
<View style={{height: 10}} /> {hasSession && <View style={{height: 10}} />}
<MenuItem <MenuItem
icon={ icon={
@ -275,6 +278,8 @@ export function DrawerContent() {
bold={isAtHome} bold={isAtHome}
onPress={onPressHome} onPress={onPressHome}
/> />
{hasSession && (
<MenuItem <MenuItem
icon={ icon={
isAtNotifications ? ( isAtNotifications ? (
@ -302,6 +307,8 @@ export function DrawerContent() {
bold={isAtNotifications} bold={isAtNotifications}
onPress={onPressNotifications} onPress={onPressNotifications}
/> />
)}
<MenuItem <MenuItem
icon={ icon={
isAtFeeds ? ( isAtFeeds ? (
@ -324,6 +331,9 @@ export function DrawerContent() {
bold={isAtFeeds} bold={isAtFeeds}
onPress={onPressMyFeeds} onPress={onPressMyFeeds}
/> />
{hasSession && (
<>
<MenuItem <MenuItem
icon={<ListIcon strokeWidth={2} style={pal.text} size={26} />} icon={<ListIcon strokeWidth={2} style={pal.text} size={26} />}
label={_(msg`Lists`)} label={_(msg`Lists`)}
@ -372,10 +382,13 @@ export function DrawerContent() {
accessibilityHint="" accessibilityHint=""
onPress={onPressSettings} onPress={onPressSettings}
/> />
</>
)}
<View style={styles.smallSpacer} /> <View style={styles.smallSpacer} />
<View style={styles.smallSpacer} /> <View style={styles.smallSpacer} />
</ScrollView> </ScrollView>
<View style={styles.footer}> <View style={styles.footer}>
<TouchableOpacity <TouchableOpacity
accessibilityRole="link" accessibilityRole="link"

View File

@ -0,0 +1,61 @@
import React from 'react'
import {View} from 'react-native'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {s} from 'lib/styles'
import {usePalette} from 'lib/hooks/usePalette'
import {DefaultAvatar} from '#/view/com/util/UserAvatar'
import {Text} from '#/view/com/util/text/Text'
import {Button} from '#/view/com/util/forms/Button'
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
import {useCloseAllActiveElements} from '#/state/util'
export function NavSignupCard() {
const {_} = useLingui()
const pal = usePalette('default')
const {setShowLoggedOut} = useLoggedOutViewControls()
const closeAllActiveElements = useCloseAllActiveElements()
const showLoggedOut = React.useCallback(() => {
closeAllActiveElements()
setShowLoggedOut(true)
}, [setShowLoggedOut, closeAllActiveElements])
return (
<View
style={{
alignItems: 'flex-start',
paddingTop: 6,
marginBottom: 24,
}}>
<DefaultAvatar type="user" size={48} />
<View style={{paddingTop: 12}}>
<Text type="md" style={[pal.text, s.bold]}>
<Trans>Sign up or sign in to join the conversation</Trans>
</Text>
</View>
<View style={{flexDirection: 'row', paddingTop: 12, gap: 8}}>
<Button
onPress={showLoggedOut}
accessibilityHint={_(msg`Sign up`)}
accessibilityLabel={_(msg`Sign up`)}>
<Text type="md" style={[{color: 'white'}, s.bold]}>
<Trans>Sign up</Trans>
</Text>
</Button>
<Button
type="default"
onPress={showLoggedOut}
accessibilityHint={_(msg`Sign in`)}
accessibilityLabel={_(msg`Sign in`)}>
<Text type="md" style={[pal.text, s.bold]}>
Sign in
</Text>
</Button>
</View>
</View>
)
}

View File

@ -37,7 +37,7 @@ type TabOptions = 'Home' | 'Search' | 'Notifications' | 'MyProfile' | 'Feeds'
export function BottomBar({navigation}: BottomTabBarProps) { export function BottomBar({navigation}: BottomTabBarProps) {
const {openModal} = useModalControls() const {openModal} = useModalControls()
const {currentAccount} = useSession() const {hasSession, currentAccount} = useSession()
const pal = usePalette('default') const pal = usePalette('default')
const {_} = useLingui() const {_} = useLingui()
const queryClient = useQueryClient() const queryClient = useQueryClient()
@ -169,6 +169,9 @@ export function BottomBar({navigation}: BottomTabBarProps) {
accessibilityLabel={_(msg`Feeds`)} accessibilityLabel={_(msg`Feeds`)}
accessibilityHint="" accessibilityHint=""
/> />
{hasSession && (
<>
<Btn <Btn
testID="bottomBarNotificationsBtn" testID="bottomBarNotificationsBtn"
icon={ icon={
@ -235,6 +238,8 @@ export function BottomBar({navigation}: BottomTabBarProps) {
accessibilityLabel={_(msg`Profile`)} accessibilityLabel={_(msg`Profile`)}
accessibilityHint="" accessibilityHint=""
/> />
</>
)}
</Animated.View> </Animated.View>
) )
} }

View File

@ -24,7 +24,7 @@ import {CommonNavigatorParams} from 'lib/routes/types'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
export function BottomBarWeb() { export function BottomBarWeb() {
const {currentAccount} = useSession() const {hasSession, currentAccount} = useSession()
const pal = usePalette('default') const pal = usePalette('default')
const safeAreaInsets = useSafeAreaInsets() const safeAreaInsets = useSafeAreaInsets()
const {footerMinimalShellTransform} = useMinimalShellMode() const {footerMinimalShellTransform} = useMinimalShellMode()
@ -75,6 +75,9 @@ export function BottomBarWeb() {
) )
}} }}
</NavItem> </NavItem>
{hasSession && (
<>
<NavItem routeName="Notifications" href="/notifications"> <NavItem routeName="Notifications" href="/notifications">
{({isActive}) => { {({isActive}) => {
const Icon = isActive ? BellIconSolid : BellIcon const Icon = isActive ? BellIconSolid : BellIcon
@ -108,6 +111,8 @@ export function BottomBarWeb() {
) )
}} }}
</NavItem> </NavItem>
</>
)}
</Animated.View> </Animated.View>
) )
} }

View File

@ -47,6 +47,7 @@ import {useFetchHandle} from '#/state/queries/handle'
import {emitSoftReset} from '#/state/events' import {emitSoftReset} from '#/state/events'
import {useQueryClient} from '@tanstack/react-query' import {useQueryClient} from '@tanstack/react-query'
import {RQKEY as NOTIFS_RQKEY} from '#/state/queries/notifications/feed' import {RQKEY as NOTIFS_RQKEY} from '#/state/queries/notifications/feed'
import {NavSignupCard} from '#/view/shell/NavSignupCard'
function ProfileCard() { function ProfileCard() {
const {currentAccount} = useSession() const {currentAccount} = useSession()
@ -268,7 +269,7 @@ function ComposeBtn() {
} }
export function DesktopLeftNav() { export function DesktopLeftNav() {
const {currentAccount} = useSession() const {hasSession, currentAccount} = useSession()
const pal = usePalette('default') const pal = usePalette('default')
const {_} = useLingui() const {_} = useLingui()
const {isDesktop, isTablet} = useWebMediaQueries() const {isDesktop, isTablet} = useWebMediaQueries()
@ -282,8 +283,16 @@ export function DesktopLeftNav() {
pal.view, pal.view,
pal.border, pal.border,
]}> ]}>
{hasSession ? (
<ProfileCard /> <ProfileCard />
) : isDesktop ? (
<View style={{paddingHorizontal: 12}}>
<NavSignupCard />
</View>
) : null}
<BackBtn /> <BackBtn />
<NavItem <NavItem
href="/" href="/"
icon={<HomeIcon size={isDesktop ? 24 : 28} style={pal.text} />} icon={<HomeIcon size={isDesktop ? 24 : 28} style={pal.text} />}
@ -332,6 +341,9 @@ export function DesktopLeftNav() {
} }
label={_(msg`Feeds`)} label={_(msg`Feeds`)}
/> />
{hasSession && (
<>
<NavItem <NavItem
href="/notifications" href="/notifications"
count={numUnread} count={numUnread}
@ -423,7 +435,10 @@ export function DesktopLeftNav() {
} }
label={_(msg`Settings`)} label={_(msg`Settings`)}
/> />
<ComposeBtn /> <ComposeBtn />
</>
)}
</View> </View>
) )
} }

View File

@ -30,9 +30,21 @@ export function DesktopRightNav() {
return ( return (
<View style={[styles.rightNav, pal.view]}> <View style={[styles.rightNav, pal.view]}>
{hasSession && <DesktopSearch />} <DesktopSearch />
{hasSession && <DesktopFeeds />}
<View style={styles.message}> {hasSession && (
<View style={{paddingTop: 18, marginBottom: 18}}>
<DesktopFeeds />
</View>
)}
<View
style={[
styles.message,
{
paddingTop: hasSession ? 0 : 18,
},
]}>
{isSandbox ? ( {isSandbox ? (
<View style={[palError.view, styles.messageLine, s.p10]}> <View style={[palError.view, styles.messageLine, s.p10]}>
<Text type="md" style={[palError.text, s.bold]}> <Text type="md" style={[palError.text, s.bold]}>
@ -41,6 +53,8 @@ export function DesktopRightNav() {
</View> </View>
) : undefined} ) : undefined}
<View style={[s.flexRow]}> <View style={[s.flexRow]}>
{hasSession && (
<>
<TextLink <TextLink
type="md" type="md"
style={pal.link} style={pal.link}
@ -53,6 +67,8 @@ export function DesktopRightNav() {
<Text type="md" style={pal.textLight}> <Text type="md" style={pal.textLight}>
&nbsp;&middot;&nbsp; &nbsp;&middot;&nbsp;
</Text> </Text>
</>
)}
<TextLink <TextLink
type="md" type="md"
style={pal.link} style={pal.link}
@ -79,7 +95,8 @@ export function DesktopRightNav() {
/> />
</View> </View>
</View> </View>
<InviteCodes />
{hasSession && <InviteCodes />}
</View> </View>
) )
} }

View File

@ -222,7 +222,6 @@ const styles = StyleSheet.create({
container: { container: {
position: 'relative', position: 'relative',
width: 300, width: 300,
paddingBottom: 18,
}, },
search: { search: {
paddingHorizontal: 16, paddingHorizontal: 16,

View File

@ -21,8 +21,8 @@ import {
useSetDrawerOpen, useSetDrawerOpen,
useOnboardingState, useOnboardingState,
} from '#/state/shell' } from '#/state/shell'
import {useSession} from '#/state/session'
import {useCloseAllActiveElements} from '#/state/util' import {useCloseAllActiveElements} from '#/state/util'
import {useLoggedOutView} from '#/state/shell/logged-out'
function ShellInner() { function ShellInner() {
const isDrawerOpen = useIsDrawerOpen() const isDrawerOpen = useIsDrawerOpen()
@ -30,8 +30,8 @@ function ShellInner() {
const onboardingState = useOnboardingState() const onboardingState = useOnboardingState()
const {isDesktop, isMobile} = useWebMediaQueries() const {isDesktop, isMobile} = useWebMediaQueries()
const navigator = useNavigation<NavigationProp>() const navigator = useNavigation<NavigationProp>()
const {hasSession} = useSession()
const closeAllActiveElements = useCloseAllActiveElements() const closeAllActiveElements = useCloseAllActiveElements()
const {showLoggedOut} = useLoggedOutView()
useAuxClick() useAuxClick()
@ -42,7 +42,7 @@ function ShellInner() {
}, [navigator, closeAllActiveElements]) }, [navigator, closeAllActiveElements])
const showBottomBar = isMobile && !onboardingState.isActive const showBottomBar = isMobile && !onboardingState.isActive
const showSideNavs = !isMobile && hasSession && !onboardingState.isActive const showSideNavs = !isMobile && !onboardingState.isActive && !showLoggedOut
return ( return (
<View style={[s.hContentRegion, {overflow: 'hidden'}]}> <View style={[s.hContentRegion, {overflow: 'hidden'}]}>
<View style={s.hContentRegion}> <View style={s.hContentRegion}>
@ -50,16 +50,22 @@ function ShellInner() {
<FlatNavigator /> <FlatNavigator />
</ErrorBoundary> </ErrorBoundary>
</View> </View>
{showSideNavs && ( {showSideNavs && (
<> <>
<DesktopLeftNav /> <DesktopLeftNav />
<DesktopRightNav /> <DesktopRightNav />
</> </>
)} )}
<Composer winHeight={0} /> <Composer winHeight={0} />
{showBottomBar && <BottomBarWeb />} {showBottomBar && <BottomBarWeb />}
<ModalsContainer /> <ModalsContainer />
<Lightbox /> <Lightbox />
{!isDesktop && isDrawerOpen && ( {!isDesktop && isDrawerOpen && (
<TouchableOpacity <TouchableOpacity
onPress={() => setDrawerOpen(false)} onPress={() => setDrawerOpen(false)}