Hook it up

This commit is contained in:
Eric Bailey
2024-10-22 21:22:59 -05:00
parent ae026bb699
commit c02c919252
2 changed files with 49 additions and 11 deletions
+42 -7
View File
@@ -1,33 +1,66 @@
import React from 'react' import React from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {AtUri} from '@atproto/api'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {useNavigation} from '@react-navigation/native'
import {NavigationProp} from '#/lib/routes/types'
import {useCreateFeedMutation} from '#/state/queries/feed'
import {useProfileQuery} from '#/state/queries/profile' import {useProfileQuery} from '#/state/queries/profile'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
import {UserSelectButton} from '#/screens/Feeds/Creator/UserSelectButton' import {UserSelectButton} from '#/screens/Feeds/Creator/UserSelectButton'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Admonition} from '#/components/Admonition' import {Admonition} from '#/components/Admonition'
import {Button, ButtonIcon,ButtonText} from '#/components/Button' import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import {OutlineTags} from '#/components/Composer/OutlineTags' import {OutlineTags} from '#/components/Composer/OutlineTags'
import * as TextField from '#/components/forms/TextField' import * as TextField from '#/components/forms/TextField'
import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus'
import * as Layout from '#/components/Layout' import * as Layout from '#/components/Layout'
import {Loader} from '#/components/Loader'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
export function Creator() { export function Creator() {
const t = useTheme() const t = useTheme()
const {_} = useLingui() const {_} = useLingui()
const {currentAccount} = useSession() const {currentAccount} = useSession()
const {data: currentProfile} = useProfileQuery({ const navigation = useNavigation<NavigationProp>()
const {data: currentProfile, isPending} = useProfileQuery({
did: currentAccount?.did, did: currentAccount?.did,
staleTime: 300, staleTime: 300,
}) })
const onSuccessCreate = (data: {uri: string; cid: string}) => {
const rkey = new AtUri(data.uri).rkey
navigation.replace('ProfileFeed', {
name: currentAccount!.handle,
rkey,
})
}
const {mutateAsync: createFeed} = useCreateFeedMutation({
onSuccess: onSuccessCreate,
onError: e => {
console.error(e)
},
})
const [name, setName] = React.useState('') const [name, setName] = React.useState('')
const [description, setDescription] = React.useState('') const [description, setDescription] = React.useState('')
const [_tags, setTags] = React.useState<string[]>([]) const [tags, setTags] = React.useState<string[]>([])
const [dids, setDids] = React.useState<string[]>([]) const [actors, setActors] = React.useState<string[]>([])
const onSubmit = React.useCallback(async () => {
try {
await createFeed({
name,
description,
actors,
tags,
handleSuffixes: [],
})
} catch (e) {
console.error(e)
}
}, [name, description, actors, tags, createFeed])
return ( return (
<Layout.Screen> <Layout.Screen>
@@ -115,7 +148,7 @@ export function Creator() {
</Trans> </Trans>
</Text> </Text>
<UserSelectButton dids={dids} onChangeDids={setDids} /> <UserSelectButton dids={actors} onChangeDids={setActors} />
</View> </View>
<View style={[a.gap_md]}> <View style={[a.gap_md]}>
@@ -156,11 +189,13 @@ export function Creator() {
label={_(msg`Save feed`)} label={_(msg`Save feed`)}
size="large" size="large"
variant="solid" variant="solid"
color="primary"> color="primary"
onPress={onSubmit}
disabled={isPending}>
<ButtonText> <ButtonText>
<Trans>Create feed</Trans> <Trans>Create feed</Trans>
</ButtonText> </ButtonText>
<ButtonIcon icon={Plus} position="right" /> <ButtonIcon icon={isPending ? Loader : Plus} position="right" />
</Button> </Button>
<View style={{height: 500}} /> <View style={{height: 500}} />
+7 -4
View File
@@ -651,6 +651,9 @@ export function precacheFeedFromGeneratorView(
interface UseCreateFeedMutationParams { interface UseCreateFeedMutationParams {
name: string name: string
description?: string description?: string
actors: string[]
tags: string[]
handleSuffixes: string[]
} }
export function useCreateFeedMutation({ export function useCreateFeedMutation({
@@ -667,7 +670,7 @@ export function useCreateFeedMutation({
Error, Error,
UseCreateFeedMutationParams UseCreateFeedMutationParams
>({ >({
mutationFn: async ({name, description}) => { mutationFn: async ({name, description, actors, tags, handleSuffixes}) => {
let descriptionFacets: AppBskyRichtextFacet.Main[] | undefined let descriptionFacets: AppBskyRichtextFacet.Main[] | undefined
if (description) { if (description) {
const rt = new RichText({text: description}) const rt = new RichText({text: description})
@@ -691,9 +694,9 @@ export function useCreateFeedMutation({
}, },
'$club.feeed.generator': { '$club.feeed.generator': {
$type: 'club.feeed.generator', $type: 'club.feeed.generator',
actors: [], actors,
handleSuffixes: [], handleSuffixes,
tags: [], tags,
}, },
}, },
}) })