ligun and sogup

This commit is contained in:
john 2025-05-06 16:31:55 +02:00
parent b6633d6f25
commit 4573048a47
24 changed files with 482 additions and 226 deletions

View file

@ -1,11 +1,11 @@
import { useCallback, useState } from 'react'
import FeedView from '../feed/FeedView.tsx'
import { PostsService } from '../model/posts/postsService.ts'
import { PostsService } from '../feed/models/posts/postsService.ts'
import { useUserStore } from '../store/userStore.ts'
import { MediaService } from '../model/mediaService.ts'
import { MediaService } from '../model/media/mediaService.ts'
import NewPostWidget from '../components/NewPostWidget.tsx'
import { useFeedViewModel } from '../feed/FeedView.ts'
import { Post } from '../model/posts/posts.ts'
import { Post } from '../feed/models/posts/posts.ts'
import { Temporal } from '@js-temporal/polyfill'
import SingleColumnLayout from '../layouts/SingleColumnLayout.tsx'
import NavBar from '../components/NavBar.tsx'
@ -30,15 +30,25 @@ export default function HomePage({ postsService, mediaService }: HomePageProps)
const { pages, setPages, loadNextPage } = useFeedViewModel(fetchPosts)
const onCreatePost = useCallback(
async (content: string, files: File[]) => {
if (!onCreatePost) return
async (content: string, files: { file: File; width: number; height: number }[]) => {
setIsSubmitting(true)
if (user == null) throw new Error('Not logged in')
try {
if (user == null) throw new Error('Not logged in')
const urls = await Promise.all(files.map((file) => mediaService.uploadFile(file)))
const postId = await postsService.createNew(user.userId, content, urls)
const post = new Post(postId, content, urls, Temporal.Now.instant(), user.username)
const media = await Promise.all(
files.map(async ({ file, width, height }) => {
console.debug('do mediaService.uploadFile', file, 'width', width, 'height', height)
const { mediaId, url } = await mediaService.uploadFile(file)
return {
mediaId,
url,
width,
height,
}
}),
)
const postId = await postsService.createNew(user.userId, content, media)
const post = new Post(postId, content, media, Temporal.Now.instant(), user.username)
setPages((pages) => [[post], ...pages])
} catch (error) {
console.error('Failed to create post:', error)