-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathposts-store.ts
More file actions
51 lines (46 loc) · 1.46 KB
/
posts-store.ts
File metadata and controls
51 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { create } from "zustand/react"
import { Post } from "./types.ts"
interface PostsState {
posts: Post[]
total: number
skip: number
limit: number
searchQuery: string
sortBy: string
sortOrder: "asc" | "desc"
selectedTag: string
selectedPost: Post | null
newPost: { title: string; body: string; userId: number }
setPosts: (posts: Post[]) => void
setTotal: (total: number) => void
setSkip: (skip: number) => void
setLimit: (limit: number) => void
setSearchQuery: (query: string) => void
setSortBy: (sortBy: string) => void
setSortOrder: (sortOrder: "asc" | "desc") => void
setSelectedTag: (tag: string) => void
setSelectedPost: (post: Post | null) => void
setNewPost: (post: { title: string; body: string; userId: number }) => void
}
export const usePostsStore = create<PostsState>((set) => ({
posts: [],
total: 0,
skip: 0,
limit: 10,
searchQuery: "",
sortBy: "",
sortOrder: "asc",
selectedTag: "",
selectedPost: null,
newPost: { title: "", body: "", userId: 1 },
setPosts: (posts) => set({ posts }),
setTotal: (total) => set({ total }),
setSkip: (skip) => set({ skip }),
setLimit: (limit) => set({ limit }),
setSearchQuery: (searchQuery) => set({ searchQuery }),
setSortBy: (sortBy) => set({ sortBy }),
setSortOrder: (sortOrder) => set({ sortOrder }),
setSelectedTag: (selectedTag) => set({ selectedTag }),
setSelectedPost: (selectedPost) => set({ selectedPost }),
setNewPost: (newPost) => set({ newPost }),
}))