handle returned post from create post endpoint
This commit is contained in:
parent
83835d374b
commit
dab626f227
2 changed files with 3 additions and 6 deletions
|
@ -5,8 +5,6 @@ import { useUser } from '../../user/user.ts'
|
||||||
import { MediaService } from '../../media/mediaService.ts'
|
import { MediaService } from '../../media/mediaService.ts'
|
||||||
import NewPostWidget from '../../../components/NewPostWidget.tsx'
|
import NewPostWidget from '../../../components/NewPostWidget.tsx'
|
||||||
import { useFeedViewModel } from '../components/FeedView.ts'
|
import { useFeedViewModel } from '../components/FeedView.ts'
|
||||||
import { Post } from '../posts/posts.ts'
|
|
||||||
import { Temporal } from '@js-temporal/polyfill'
|
|
||||||
import SingleColumnLayout from '../../../layouts/SingleColumnLayout.tsx'
|
import SingleColumnLayout from '../../../layouts/SingleColumnLayout.tsx'
|
||||||
import NavBar from '../../../components/NavBar.tsx'
|
import NavBar from '../../../components/NavBar.tsx'
|
||||||
import AuthNavButtons from '../../auth/components/AuthNavButtons.tsx'
|
import AuthNavButtons from '../../auth/components/AuthNavButtons.tsx'
|
||||||
|
@ -52,8 +50,7 @@ export default function HomePage({ postsService, mediaService }: HomePageProps)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
const postId = await postsService.createNew(user.id, content, media, isPublic)
|
const post = await postsService.createNew(user.id, content, media, isPublic)
|
||||||
const post = new Post(postId, content, media, Temporal.Now.instant(), user.username)
|
|
||||||
setPages((pages) => [[post], ...pages])
|
setPages((pages) => [[post], ...pages])
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to create post:', error)
|
console.error('Failed to create post:', error)
|
||||||
|
|
|
@ -9,7 +9,7 @@ export class PostsService {
|
||||||
content: string,
|
content: string,
|
||||||
media: CreatePostMedia[],
|
media: CreatePostMedia[],
|
||||||
isPublic: boolean,
|
isPublic: boolean,
|
||||||
): Promise<string> {
|
): Promise<Post> {
|
||||||
const response = await this.client.POST('/posts', {
|
const response = await this.client.POST('/posts', {
|
||||||
body: {
|
body: {
|
||||||
authorId,
|
authorId,
|
||||||
|
@ -26,7 +26,7 @@ export class PostsService {
|
||||||
throw new Error('Failed to create post')
|
throw new Error('Failed to create post')
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.data.postId
|
return Post.fromDto(response.data.post)
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadPublicFeed(cursor: string | null, amount: number | null): Promise<Post[]> {
|
async loadPublicFeed(cursor: string | null, amount: number | null): Promise<Post[]> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue