feat(post): persist new posts and wire like interactions
This commit is contained in:
@@ -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
|
||||
},
|
||||
}))
|
||||
Reference in New Issue
Block a user