Implement profile-update api
parent
bf39791f01
commit
0aaa406b17
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
// import {ReactNativeStore} from './auth'
|
// import {ReactNativeStore} from './auth'
|
||||||
import AdxApi from '../../third-party/api'
|
import AdxApi from '../../third-party/api'
|
||||||
import {ServiceClient} from '../../third-party/api/src/index'
|
import * as Profile from '../../third-party/api/src/types/todo/social/profile'
|
||||||
import {AdxUri} from '../../third-party/uri'
|
import {AdxUri} from '../../third-party/uri'
|
||||||
import {RootStoreModel} from '../models/root-store'
|
import {RootStoreModel} from '../models/root-store'
|
||||||
import {extractEntities} from '../../view/lib/strings'
|
import {extractEntities} from '../../view/lib/strings'
|
||||||
|
@ -100,11 +100,29 @@ export async function unfollow(store: RootStoreModel, followUri: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateProfile(
|
export async function updateProfile(
|
||||||
adx: ServiceClient,
|
store: RootStoreModel,
|
||||||
user: string,
|
modifyFn: (existing?: Profile.Record) => Profile.Record,
|
||||||
profile: bsky.Profile.Record,
|
|
||||||
) {
|
) {
|
||||||
throw new Error('TODO')
|
const res = await store.api.todo.social.profile.list({
|
||||||
|
nameOrDid: store.me.did || '',
|
||||||
|
})
|
||||||
|
const existing = res.records[0]
|
||||||
|
if (existing) {
|
||||||
|
await store.api.todo.social.profile.put(
|
||||||
|
{
|
||||||
|
did: store.me.did || '',
|
||||||
|
tid: new AdxUri(existing.uri).recordKey,
|
||||||
|
},
|
||||||
|
modifyFn(existing.value),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
await store.api.todo.social.profile.create(
|
||||||
|
{
|
||||||
|
did: store.me.did || '',
|
||||||
|
},
|
||||||
|
modifyFn(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FetchHandlerResponse {
|
interface FetchHandlerResponse {
|
||||||
|
|
|
@ -88,11 +88,11 @@ export class ProfileViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateProfile(profile: Profile.Record) {
|
async updateProfile(fn: (existing?: Profile.Record) => Profile.Record) {
|
||||||
if (this.did !== this.rootStore.me.did) {
|
if (this.did !== this.rootStore.me.did) {
|
||||||
throw new Error('Not your profile!')
|
throw new Error('Not your profile!')
|
||||||
}
|
}
|
||||||
await apilib.updateProfile(this.rootStore.api, this.did, profile)
|
await apilib.updateProfile(this.rootStore, fn)
|
||||||
await this.refresh()
|
await this.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {ErrorMessage} from '../util/ErrorMessage'
|
||||||
import {useStores} from '../../../state'
|
import {useStores} from '../../../state'
|
||||||
import {ProfileViewModel} from '../../../state/models/profile-view'
|
import {ProfileViewModel} from '../../../state/models/profile-view'
|
||||||
import {s, colors, gradients} from '../../lib/styles'
|
import {s, colors, gradients} from '../../lib/styles'
|
||||||
|
import * as Profile from '../../../third-party/api/src/types/todo/social/profile'
|
||||||
|
|
||||||
export const snapPoints = ['80%']
|
export const snapPoints = ['80%']
|
||||||
|
|
||||||
|
@ -23,10 +24,19 @@ export function Component({profileView}: {profileView: ProfileViewModel}) {
|
||||||
setError('')
|
setError('')
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await profileView.updateProfile({
|
await profileView.updateProfile(
|
||||||
|
(existing?: Profile.Record): Profile.Record => {
|
||||||
|
if (existing) {
|
||||||
|
existing.displayName = displayName
|
||||||
|
existing.description = description
|
||||||
|
return existing
|
||||||
|
}
|
||||||
|
return {
|
||||||
displayName,
|
displayName,
|
||||||
description,
|
description,
|
||||||
})
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
Toast.show('Profile updated', {
|
Toast.show('Profile updated', {
|
||||||
position: Toast.positions.TOP,
|
position: Toast.positions.TOP,
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,10 +11,6 @@ Paul's todo list
|
||||||
- Firehose
|
- Firehose
|
||||||
- Composer
|
- Composer
|
||||||
- Update the view after creating a post
|
- Update the view after creating a post
|
||||||
- Profile
|
|
||||||
- Implement update/edit
|
|
||||||
- Disable editing avi or banner
|
|
||||||
- More button
|
|
||||||
- Linking
|
- Linking
|
||||||
- Web linking
|
- Web linking
|
||||||
- App linking
|
- App linking
|
||||||
|
|
Loading…
Reference in New Issue