feat(post): persist new posts and wire like interactions

This commit is contained in:
zetaloop
2026-02-22 08:29:59 +08:00
parent 237cf90f5e
commit 43a0cf7a73
6 changed files with 136 additions and 28 deletions
+48
View File
@@ -0,0 +1,48 @@
import { create } from "zustand"
import { generateId } from "@/lib/id"
import { mockPosts } from "@/lib/mock"
import type { Post, User, UserRole } from "@/lib/types"
interface CreatePostInput {
author: User
authorRole: UserRole
title: string
content: string
images: string[]
tags: string[]
linkedOrderId?: string
quotedPostId?: string
}
interface PostState {
posts: Post[]
createPost: (input: CreatePostInput) => Post
}
export const usePostStore = create<PostState>((set) => ({
posts: mockPosts,
createPost: (input) => {
const post: Post = {
id: generateId("post"),
author: input.author,
authorRole: input.authorRole,
title: input.title.trim(),
content: input.content.trim(),
images: input.images,
tags: input.tags,
linkedOrderId: input.linkedOrderId,
quotedPostId: input.quotedPostId,
likeCount: 0,
commentCount: 0,
liked: false,
pinned: false,
createdAt: new Date().toISOString(),
}
set((state) => ({
posts: [post, ...state.posts],
}))
return post
},
}))