From 4c9e2b014ef99423081177db6d0250de675a20ae Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 23 Oct 2024 19:37:19 +0100 Subject: [PATCH] More prefill --- src/state/shell/composer/index.tsx | 1 + src/view/screens/ProfileFeed.tsx | 33 ++++++------------- src/view/shell/desktop/LeftNav.tsx | 52 ++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/state/shell/composer/index.tsx b/src/state/shell/composer/index.tsx index 0969485064..fa8769813f 100644 --- a/src/state/shell/composer/index.tsx +++ b/src/state/shell/composer/index.tsx @@ -42,6 +42,7 @@ export interface ComposerOpts { text?: string imageUris?: {uri: string; width: number; height: number; altText?: string}[] videoUri?: {uri: string; width: number; height: number} + initFeeds: string[] | undefined } type StateContext = ComposerOpts | undefined diff --git a/src/view/screens/ProfileFeed.tsx b/src/view/screens/ProfileFeed.tsx index 80e55df70c..323a8d506d 100644 --- a/src/view/screens/ProfileFeed.tsx +++ b/src/view/screens/ProfileFeed.tsx @@ -51,11 +51,10 @@ import {Text} from '#/view/com/util/text/Text' import * as Toast from '#/view/com/util/Toast' import {CenteredView} from '#/view/com/util/Views' import {atoms as a, useTheme} from '#/alf' -import {Button as NewButton, ButtonIcon, ButtonText} from '#/components/Button' +import {Button as NewButton, ButtonText} from '#/components/Button' import {useRichText} from '#/components/hooks/useRichText' import {ArrowOutOfBox_Stroke2_Corner0_Rounded as Share} from '#/components/icons/ArrowOutOfBox' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' -import {EditBig_Stroke2_Corner0_Rounded as EditBig} from '#/components/icons/EditBig' import { Heart2_Filled_Stroke2_Corner0_Rounded as HeartFilled, Heart2_Stroke2_Corner0_Rounded as HeartOutline, @@ -267,9 +266,6 @@ export function ProfileFeedScreenInner({ }, [feedSectionRef], ) - const isFeedSubmittable = - feedInfo.creatorDid === currentAccount?.did && - feedInfo.did === 'did:web:feeed.club' const renderHeader = useCallback(() => { return ( @@ -287,21 +283,6 @@ export function ProfileFeedScreenInner({ } avatarType="algo"> - {isFeedSubmittable && ( - - openComposer({ - initFeeds: [feedInfo.uri], - }) - }> - - - )} {feedInfo && hasSession && ( openComposer({})} + onPress={() => { + let initFeeds + if (feedInfo.creatorDid === currentAccount?.did) { + initFeeds = [feedInfo.uri] + } + openComposer({ + initFeeds, + }) + }} icon={ { const routes = getState()?.routes const currentRoute = routes?.[routes?.length - 1] - if (currentRoute?.name === 'Profile') { + if ( + currentRoute?.name === 'Profile' || + currentRoute?.name === 'ProfileFeed' + ) { let handle: string | undefined = ( currentRoute.params as CommonNavigatorParams['Profile'] ).name @@ -282,12 +287,7 @@ function ComposeBtn() { } } - if ( - !handle || - handle === currentAccount?.handle || - isInvalidHandle(handle) - ) - return undefined + if (!handle || isInvalidHandle(handle)) return undefined return handle } @@ -295,8 +295,42 @@ function ComposeBtn() { return undefined } - const onPressCompose = async () => - openComposer({mention: await getProfileHandle()}) + const getFeedUris = async (handle: string | undefined) => { + if (!handle) return undefined + + const did = (await agent.resolveHandle({handle: handle})).data.did + + const routes = getState()?.routes + const currentRoute = routes?.[routes?.length - 1] + + if (currentRoute?.name === 'ProfileFeed') { + let rkey: string | undefined = ( + currentRoute.params as CommonNavigatorParams['ProfileFeed'] + ).rkey + + return [`at://${did}/app.bsky.feed.generator/${rkey}`] + } + + return undefined + } + + const onPressCompose = async () => { + const handle = await getProfileHandle() + const routes = getState()?.routes + const currentRoute = routes?.[routes?.length - 1] + let mention = + handle !== currentAccount?.handle && currentRoute?.name === 'Profile' + ? handle + : undefined + let initFeeds = + handle === currentAccount?.handle && currentRoute?.name === 'ProfileFeed' + ? await getFeedUris(handle) + : undefined + openComposer({ + mention, + initFeeds, + }) + } if (isTablet) { return null