void
- isSubmitting?: boolean
-}
-
-export default function NewCommentWidget({
- onSubmit,
- isSubmitting = false,
-}: NewCommentWidgetProps) {
- const { t } = useTranslations()
- const [content, setContent] = useState('')
-
- const onContentInput = (value: string) => {
- setContent(value)
- }
-
- const handleSubmit = () => {
- if (!content.trim()) {
- return
- }
-
- onSubmit(content)
-
- setContent('')
- }
-
- const onInputKeyDown = (e: TextInputKeyDownEvent) => {
- if (e.key === 'Enter' && e.ctrlKey) {
- e.preventDefault()
- handleSubmit()
- }
- }
-
- return (
-
-
-
-
-
-
-
- )
-}
diff --git a/src/app/feed/components/PostItem.tsx b/src/app/feed/components/PostItem.tsx
index db766f6..a0a541c 100644
--- a/src/app/feed/components/PostItem.tsx
+++ b/src/app/feed/components/PostItem.tsx
@@ -1,24 +1,13 @@
-import { PostMedia, PostReaction } from '../posts/posts.ts'
+import { Post, PostMedia } from '../posts/posts.ts'
import { useEffect, useState } from 'react'
-import { Link } from 'react-router-dom'
-import { PostInfo } from '../posts/usePostViewModel.ts'
-import { useUserStore } from '../../user/user.ts'
interface PostItemProps {
- post: PostInfo
- reactions: PostReaction[]
+ post: Post
addReaction: (emoji: string) => void
clearReaction: (emoji: string) => void
- hideViewButton?: boolean
}
-export default function PostItem({
- post,
- reactions,
- addReaction,
- clearReaction,
- hideViewButton = false,
-}: PostItemProps) {
+export default function PostItem({ post, addReaction, clearReaction }: PostItemProps) {
const formattedDate = post.createdAt.toLocaleString('en-US', {
year: 'numeric',
month: 'short',
@@ -42,14 +31,6 @@ export default function PostItem({
@{post.authorName}• {formattedDate}
- {!hideViewButton && (
- <>
- {' • '}
-
- View
-
- >
- )}
{post.content}
@@ -62,30 +43,26 @@ export default function PostItem({
)
}
interface PostReactionsProps {
- post: PostInfo
- reactions: PostReaction[]
+ post: Post
addReaction: (emoji: string) => void
clearReaction: (emoji: string) => void
}
-function PostReactions({ post, reactions, addReaction, clearReaction }: PostReactionsProps) {
- const username = useUserStore((state) => state.user?.username)
+function PostReactions({ post, addReaction, clearReaction }: PostReactionsProps) {
+ const reactionMap = new Map(post.reactions.map((r) => [r.emoji, r]))
+
return (
{post.possibleReactions.map((emoji) => {
- const count = reactions.filter((r) => r.emoji === emoji).length
- const didReact = reactions.some((r) => r.emoji == emoji && r.authorName == username)
+ const reaction = reactionMap.get(emoji)
+ const count = reaction?.count ?? 0
+ const didReact = reaction?.didReact ?? false
const onClick = () => {
if (didReact) {
clearReaction(emoji)
@@ -122,7 +99,7 @@ function PostReactionButton({ emoji, didReact, onClick, count }: PostReactionBut