From bcad2486a9d50e7e56e69055cc3ac9c0ea189276 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sun, 26 Nov 2023 12:16:28 -0600 Subject: [PATCH] Split out home feed, wip --- src/view/screens/Home.tsx | 27 +--- src/view/screens/HomePublic.tsx | 213 ++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+), 25 deletions(-) create mode 100644 src/view/screens/HomePublic.tsx diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx index 015c436f41..30c5afecf9 100644 --- a/src/view/screens/Home.tsx +++ b/src/view/screens/Home.tsx @@ -14,6 +14,7 @@ import {usePreferencesQuery} from '#/state/queries/preferences' import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types' import {emitSoftReset} from '#/state/events' import {useSession} from '#/state/session' +import {HomePublic} from '#/view/screens/HomePublic' type Props = NativeStackScreenProps export function HomeScreen(props: Props) { @@ -21,7 +22,7 @@ export function HomeScreen(props: Props) { const {data: preferences} = usePreferencesQuery() if (!hasSession) { - return + return } if (preferences) { @@ -35,30 +36,6 @@ export function HomeScreen(props: Props) { } } -function HomeScreenPublic() { - const setMinimalShellMode = useSetMinimalShellMode() - const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled() - - const renderCustomFeedEmptyState = React.useCallback(() => { - return - }, []) - - useFocusEffect( - React.useCallback(() => { - setMinimalShellMode(false) - setDrawerSwipeDisabled(false) - }, [setDrawerSwipeDisabled, setMinimalShellMode]), - ) - - return ( - - ) -} - function HomeScreenReady({ preferences, }: Props & { diff --git a/src/view/screens/HomePublic.tsx b/src/view/screens/HomePublic.tsx new file mode 100644 index 0000000000..1d550013f2 --- /dev/null +++ b/src/view/screens/HomePublic.tsx @@ -0,0 +1,213 @@ +import React from 'react' +import {View, StyleSheet, FlatList, TouchableOpacity} from 'react-native' +import Animated from 'react-native-reanimated' +import {useFocusEffect} from '@react-navigation/native' +import {CustomFeedEmptyState} from 'view/com/posts/CustomFeedEmptyState' +import {useSetMinimalShellMode, useSetDrawerSwipeDisabled} from '#/state/shell' +import {listenSoftReset, emitSoftReset} from '#/state/events' +import {useSession} from '#/state/session' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' +import {useIsFocused} from '@react-navigation/native' +import {useAnalytics} from '@segment/analytics-react-native' +import {useQueryClient} from '@tanstack/react-query' +import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed' +import {useOnMainScroll} from 'lib/hooks/useOnMainScroll' +import {usePalette} from 'lib/hooks/usePalette' +import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' +import {colors, s} from 'lib/styles' +import {Feed} from '#/view/com/posts/Feed' +import {TextLink} from '#/view/com/util/Link' +import {LoadLatestBtn} from '#/view/com/util/load-latest/LoadLatestBtn' +import {msg} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {useSetDrawerOpen} from '#/state/shell/drawer-open' +import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle' +import {useShellLayout} from '#/state/shell/shell-layout' +import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode' +import {HITSLOP_10} from 'lib/constants' +import {Text} from '#/view/com/util/text/Text' + +const DISCOVER_FEED = `feedgen|at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot` +const POLL_FREQ = 30e3 // 30sec + +function Header({hasNew}: {hasNew: boolean}) { + const pal = usePalette('default') + const {isSandbox} = useSession() + const {_} = useLingui() + const setDrawerOpen = useSetDrawerOpen() + const brandBlue = useColorSchemeStyle(s.brandBlue, s.blue3) + const {headerHeight} = useShellLayout() + const {headerMinimalShellTransform} = useMinimalShellMode() + const {isTablet, isDesktop} = useWebMediaQueries() + + const onPressAvi = React.useCallback(() => { + setDrawerOpen(true) + }, [setDrawerOpen]) + + return isTablet || isDesktop ? ( + + + {isSandbox ? 'SANDBOX' : 'Bluesky'}{' '} + {hasNew && ( + + )} + + } + onPress={emitSoftReset} + /> + + ) : ( + { + headerHeight.value = e.nativeEvent.layout.height + }}> + + + + + + + + {isSandbox ? 'SANDBOX' : 'Bluesky'} + + + + + ) +} + +const styles = StyleSheet.create({ + tabBar: { + // position: 'absolute', + zIndex: 1, + left: 0, + right: 0, + top: 0, + flexDirection: 'column', + borderBottomWidth: 1, + }, + topBar: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + paddingHorizontal: 18, + paddingTop: 8, + paddingBottom: 8, + width: '100%', + }, + title: { + fontSize: 21, + }, +}) + +export function HomePublic() { + const {_} = useLingui() + const setMinimalShellMode = useSetMinimalShellMode() + const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled() + const queryClient = useQueryClient() + const [onMainScroll, isScrolledDown, resetMainScroll] = useOnMainScroll() + const {screen} = useAnalytics() + const scrollElRef = React.useRef(null) + const isScreenFocused = useIsFocused() + const [hasNew, setHasNew] = React.useState(false) + + const scrollToTop = React.useCallback(() => { + scrollElRef.current?.scrollToOffset({offset: 0}) + resetMainScroll() + }, [resetMainScroll]) + + const onSoftReset = React.useCallback(() => { + scrollToTop() + queryClient.invalidateQueries({queryKey: FEED_RQKEY(DISCOVER_FEED)}) + setHasNew(false) + }, [scrollToTop, queryClient, setHasNew]) + + // fires when page within screen is activated/deactivated + React.useEffect(() => { + if (isScreenFocused) { + return + } + screen('Feed') + return listenSoftReset(onSoftReset) + }, [onSoftReset, screen, isScreenFocused]) + + const onPressLoadLatest = React.useCallback(() => { + scrollToTop() + queryClient.invalidateQueries({queryKey: FEED_RQKEY(DISCOVER_FEED)}) + setHasNew(false) + }, [scrollToTop, queryClient, setHasNew]) + + const renderCustomFeedEmptyState = React.useCallback(() => { + return + }, []) + + useFocusEffect( + React.useCallback(() => { + setMinimalShellMode(false) + setDrawerSwipeDisabled(false) + }, [setDrawerSwipeDisabled, setMinimalShellMode]), + ) + + const ListHeaderComponent = React.useCallback(() => { + return
+ }, [hasNew]) + + return ( + + + + {(isScrolledDown || hasNew) && ( + + )} + + ) +}