feat: add collection functionality
This commit is contained in:
@@ -5,11 +5,12 @@
|
||||
|
||||
import { create } from "zustand";
|
||||
import { Collection } from "@prisma/client";
|
||||
import { NewCollection } from "@/types/global";
|
||||
|
||||
type CollectionStore = {
|
||||
collections: Collection[];
|
||||
setCollections: () => void;
|
||||
addCollection: (collectionName: string) => void;
|
||||
addCollection: (body: NewCollection) => Promise<boolean>;
|
||||
updateCollection: (collection: Collection) => void;
|
||||
removeCollection: (collectionId: number) => void;
|
||||
};
|
||||
@@ -23,9 +24,9 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||
|
||||
if (response.ok) set({ collections: data.response });
|
||||
},
|
||||
addCollection: async (collectionName) => {
|
||||
addCollection: async (body) => {
|
||||
const response = await fetch("/api/routes/collections", {
|
||||
body: JSON.stringify({ collectionName }),
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
@@ -38,6 +39,8 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||
set((state) => ({
|
||||
collections: [...state.collections, data.response],
|
||||
}));
|
||||
|
||||
return response.ok;
|
||||
},
|
||||
updateCollection: (collection) =>
|
||||
set((state) => ({
|
||||
|
||||
+4
-4
@@ -4,14 +4,14 @@
|
||||
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import { create } from "zustand";
|
||||
import { ExtendedLink } from "@/types/global";
|
||||
import { ExtendedLink, NewLink } from "@/types/global";
|
||||
import useTagStore from "./tags";
|
||||
import useCollectionStore from "./collections";
|
||||
|
||||
type LinkStore = {
|
||||
links: ExtendedLink[];
|
||||
setLinks: () => void;
|
||||
addLink: (linkName: ExtendedLink) => Promise<boolean>;
|
||||
addLink: (body: NewLink) => Promise<boolean>;
|
||||
updateLink: (link: ExtendedLink) => void;
|
||||
removeLink: (link: ExtendedLink) => void;
|
||||
};
|
||||
@@ -25,9 +25,9 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||
|
||||
if (response.ok) set({ links: data.response });
|
||||
},
|
||||
addLink: async (newLink) => {
|
||||
addLink: async (body) => {
|
||||
const response = await fetch("/api/routes/links", {
|
||||
body: JSON.stringify(newLink),
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user