fix TS error

This commit is contained in:
john 2025-08-10 13:47:36 +01:00
parent 74a05e4678
commit 0afe5eac04

View file

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