repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
Projectflow
stars
latest
clone command
git clone gitlawb://did:key:z6Mkfh4Y...QBEi/projectflowgit clone gitlawb://did:key:z6Mkfh4Y.../projectflowb3cded1async from playground1d ago| #1 | import { StateCreator } from "zustand"; |
| #2 | import type { Comment } from "../../../domain/entities"; |
| #3 | import { comments as mockComments } from "../../../infrastructure/mock-data/comments"; |
| #4 | import { generateId } from "../../../infrastructure/helpers"; |
| #5 | import type { StoreState } from "../store.types"; |
| #6 | |
| #7 | export interface CommentSlice { |
| #8 | comments: Comment[]; |
| #9 | addComment: (issueId: string, content: string) => void; |
| #10 | updateComment: (id: string, content: string) => void; |
| #11 | deleteComment: (id: string) => void; |
| #12 | } |
| #13 | |
| #14 | export const createCommentSlice: StateCreator< |
| #15 | StoreState, |
| #16 | [], |
| #17 | [], |
| #18 | CommentSlice |
| #19 | > = (set, get) => ({ |
| #20 | comments: mockComments, |
| #21 | addComment: (issueId, content) => { |
| #22 | const newComment: Comment = { |
| #23 | id: generateId(), |
| #24 | issueId, |
| #25 | userId: get().currentUser?.id || "u1", |
| #26 | content, |
| #27 | createdAt: new Date().toISOString(), |
| #28 | updatedAt: new Date().toISOString(), |
| #29 | }; |
| #30 | set((s) => ({ comments: [...s.comments, newComment] })); |
| #31 | }, |
| #32 | updateComment: (id, content) => { |
| #33 | set((s) => ({ |
| #34 | comments: s.comments.map((c) => |
| #35 | c.id === id |
| #36 | ? { ...c, content, updatedAt: new Date().toISOString() } |
| #37 | : c |
| #38 | ), |
| #39 | })); |
| #40 | }, |
| #41 | deleteComment: (id) => { |
| #42 | set((s) => ({ |
| #43 | comments: s.comments.filter((c) => c.id !== id), |
| #44 | })); |
| #45 | }, |
| #46 | }); |
| #47 |