More prefill

This commit is contained in:
Dan Abramov
2024-10-23 19:37:19 +01:00
parent a02f4fc75c
commit 4c9e2b014e
3 changed files with 54 additions and 32 deletions
+1
View File
@@ -42,6 +42,7 @@ export interface ComposerOpts {
text?: string text?: string
imageUris?: {uri: string; width: number; height: number; altText?: string}[] imageUris?: {uri: string; width: number; height: number; altText?: string}[]
videoUri?: {uri: string; width: number; height: number} videoUri?: {uri: string; width: number; height: number}
initFeeds: string[] | undefined
} }
type StateContext = ComposerOpts | undefined type StateContext = ComposerOpts | undefined
+10 -23
View File
@@ -51,11 +51,10 @@ import {Text} from '#/view/com/util/text/Text'
import * as Toast from '#/view/com/util/Toast' import * as Toast from '#/view/com/util/Toast'
import {CenteredView} from '#/view/com/util/Views' import {CenteredView} from '#/view/com/util/Views'
import {atoms as a, useTheme} from '#/alf' 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 {useRichText} from '#/components/hooks/useRichText'
import {ArrowOutOfBox_Stroke2_Corner0_Rounded as Share} from '#/components/icons/ArrowOutOfBox' import {ArrowOutOfBox_Stroke2_Corner0_Rounded as Share} from '#/components/icons/ArrowOutOfBox'
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
import {EditBig_Stroke2_Corner0_Rounded as EditBig} from '#/components/icons/EditBig'
import { import {
Heart2_Filled_Stroke2_Corner0_Rounded as HeartFilled, Heart2_Filled_Stroke2_Corner0_Rounded as HeartFilled,
Heart2_Stroke2_Corner0_Rounded as HeartOutline, Heart2_Stroke2_Corner0_Rounded as HeartOutline,
@@ -267,9 +266,6 @@ export function ProfileFeedScreenInner({
}, },
[feedSectionRef], [feedSectionRef],
) )
const isFeedSubmittable =
feedInfo.creatorDid === currentAccount?.did &&
feedInfo.did === 'did:web:feeed.club'
const renderHeader = useCallback(() => { const renderHeader = useCallback(() => {
return ( return (
@@ -287,21 +283,6 @@ export function ProfileFeedScreenInner({
} }
avatarType="algo"> avatarType="algo">
<View style={[a.flex_row, a.align_center, a.gap_sm]}> <View style={[a.flex_row, a.align_center, a.gap_sm]}>
{isFeedSubmittable && (
<NewButton
size="small"
variant="solid"
color="primary"
shape="round"
label={_(msg`Add post to feed`)}
onPress={() =>
openComposer({
initFeeds: [feedInfo.uri],
})
}>
<ButtonIcon icon={EditBig} />
</NewButton>
)}
{feedInfo && hasSession && ( {feedInfo && hasSession && (
<NewButton <NewButton
testID={isPinned ? 'unpinBtn' : 'pinBtn'} testID={isPinned ? 'unpinBtn' : 'pinBtn'}
@@ -410,8 +391,6 @@ export function ProfileFeedScreenInner({
onPressShare, onPressShare,
t, t,
isPending, isPending,
isFeedSubmittable,
openComposer,
]) ])
return ( return (
@@ -442,7 +421,15 @@ export function ProfileFeedScreenInner({
{hasSession && ( {hasSession && (
<FAB <FAB
testID="composeFAB" testID="composeFAB"
onPress={() => openComposer({})} onPress={() => {
let initFeeds
if (feedInfo.creatorDid === currentAccount?.did) {
initFeeds = [feedInfo.uri]
}
openComposer({
initFeeds,
})
}}
icon={ icon={
<ComposeIcon2 <ComposeIcon2
strokeWidth={1.5} strokeWidth={1.5}
+43 -9
View File
@@ -23,6 +23,7 @@ import {useFetchHandle} from '#/state/queries/handle'
import {useUnreadMessageCount} from '#/state/queries/messages/list-converations' import {useUnreadMessageCount} from '#/state/queries/messages/list-converations'
import {useUnreadNotifications} from '#/state/queries/notifications/unread' import {useUnreadNotifications} from '#/state/queries/notifications/unread'
import {useProfileQuery} from '#/state/queries/profile' import {useProfileQuery} from '#/state/queries/profile'
import {useAgent} from '#/state/session'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
import {useComposerControls} from '#/state/shell/composer' import {useComposerControls} from '#/state/shell/composer'
import {Link} from '#/view/com/util/Link' import {Link} from '#/view/com/util/Link'
@@ -261,12 +262,16 @@ function ComposeBtn() {
const {isTablet} = useWebMediaQueries() const {isTablet} = useWebMediaQueries()
const [isFetchingHandle, setIsFetchingHandle] = React.useState(false) const [isFetchingHandle, setIsFetchingHandle] = React.useState(false)
const fetchHandle = useFetchHandle() const fetchHandle = useFetchHandle()
const agent = useAgent()
const getProfileHandle = async () => { const getProfileHandle = async () => {
const routes = getState()?.routes const routes = getState()?.routes
const currentRoute = routes?.[routes?.length - 1] const currentRoute = routes?.[routes?.length - 1]
if (currentRoute?.name === 'Profile') { if (
currentRoute?.name === 'Profile' ||
currentRoute?.name === 'ProfileFeed'
) {
let handle: string | undefined = ( let handle: string | undefined = (
currentRoute.params as CommonNavigatorParams['Profile'] currentRoute.params as CommonNavigatorParams['Profile']
).name ).name
@@ -282,12 +287,7 @@ function ComposeBtn() {
} }
} }
if ( if (!handle || isInvalidHandle(handle)) return undefined
!handle ||
handle === currentAccount?.handle ||
isInvalidHandle(handle)
)
return undefined
return handle return handle
} }
@@ -295,8 +295,42 @@ function ComposeBtn() {
return undefined return undefined
} }
const onPressCompose = async () => const getFeedUris = async (handle: string | undefined) => {
openComposer({mention: await getProfileHandle()}) 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) { if (isTablet) {
return null return null