Compare commits

..

No commits in common. "d2d358bff273967f262814439788f11ee0010207" and "74a05e4678a1dda841072b9837f2feecc3620a58" have entirely different histories.

2 changed files with 15 additions and 10 deletions

View file

@ -1,7 +1,7 @@
{
"name": "femto-webapp",
"private": true,
"version": "1.26.1",
"version": "1.26.0",
"type": "module",
"scripts": {
"dev": "vite --host 0.0.0.0",

View file

@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'
import { Post } from '../posts/posts.ts'
import { PostsService } from '../posts/postsService.ts'
import SingleColumnLayout from '../../../layouts/SingleColumnLayout.tsx'
@ -13,6 +13,7 @@ interface PostPageProps {
export default function PostPage({ postsService }: PostPageProps) {
const { postId } = useParams<{ postId: string }>()
const navigate = useNavigate()
const [post, setPost] = useState<Post | null>(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
@ -28,7 +29,7 @@ export default function PostPage({ postsService }: PostPageProps) {
try {
// Load posts and find the one with matching ID
const { posts } = await postsService.loadPublicFeed(null, 100)
const foundPost = posts.find((p) => p.postId === postId)
const foundPost = posts.find(p => p.postId === postId)
if (foundPost) {
setPost(foundPost)
@ -50,11 +51,11 @@ export default function PostPage({ postsService }: PostPageProps) {
await postsService.addReaction(post.postId, emoji)
setPost((prevPost) => {
setPost(prevPost => {
if (!prevPost) return null
const updatedReactions = [...prevPost.reactions]
const theReaction = updatedReactions.find((r) => r.emoji === emoji)
const theReaction = updatedReactions.find(r => r.emoji === emoji)
if (theReaction) {
theReaction.count++
@ -65,7 +66,7 @@ export default function PostPage({ postsService }: PostPageProps) {
return {
...prevPost,
reactions: updatedReactions,
reactions: updatedReactions
}
})
}
@ -75,11 +76,11 @@ export default function PostPage({ postsService }: PostPageProps) {
await postsService.removeReaction(post.postId, emoji)
setPost((prevPost) => {
setPost(prevPost => {
if (!prevPost) return null
const updatedReactions = [...prevPost.reactions]
const theReaction = updatedReactions.find((r) => r.emoji === emoji)
const theReaction = updatedReactions.find(r => r.emoji === emoji)
if (theReaction) {
theReaction.count = Math.max(theReaction.count - 1, 0)
@ -88,7 +89,7 @@ export default function PostPage({ postsService }: PostPageProps) {
return {
...prevPost,
reactions: updatedReactions,
reactions: updatedReactions
}
})
}
@ -104,7 +105,11 @@ export default function PostPage({ postsService }: PostPageProps) {
<main className="w-full max-w-3xl mx-auto">
{loading && <div className="text-center py-8">Loading...</div>}
{error && <div className="text-center py-8 text-red-500">Error: {error}</div>}
{error && (
<div className="text-center py-8 text-red-500">
Error: {error}
</div>
)}
{post && (
<div className="w-full">