added toasts popups + improved login/signup page + many more changes and improvements
This commit is contained in:
+7
-4
@@ -1,10 +1,15 @@
|
||||
import { create } from "zustand";
|
||||
import { AccountSettings } from "@/types/global";
|
||||
|
||||
type ResponseObject = {
|
||||
ok: boolean;
|
||||
data: object | string;
|
||||
};
|
||||
|
||||
type AccountStore = {
|
||||
account: AccountSettings;
|
||||
setAccount: (email: string) => void;
|
||||
updateAccount: (user: AccountSettings) => Promise<boolean>;
|
||||
updateAccount: (user: AccountSettings) => Promise<ResponseObject>;
|
||||
};
|
||||
|
||||
const useAccountStore = create<AccountStore>()((set) => ({
|
||||
@@ -29,11 +34,9 @@ const useAccountStore = create<AccountStore>()((set) => ({
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (response.ok) set({ account: { ...data.response } });
|
||||
|
||||
return response.ok;
|
||||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
+11
-10
@@ -2,16 +2,21 @@ import { create } from "zustand";
|
||||
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||
import useTagStore from "./tags";
|
||||
|
||||
type ResponseObject = {
|
||||
ok: boolean;
|
||||
data: object | string;
|
||||
};
|
||||
|
||||
type CollectionStore = {
|
||||
collections: CollectionIncludingMembersAndLinkCount[];
|
||||
setCollections: () => void;
|
||||
addCollection: (
|
||||
body: CollectionIncludingMembersAndLinkCount
|
||||
) => Promise<boolean>;
|
||||
) => Promise<ResponseObject>;
|
||||
updateCollection: (
|
||||
collection: CollectionIncludingMembersAndLinkCount
|
||||
) => Promise<boolean>;
|
||||
removeCollection: (collectionId: number) => Promise<boolean>;
|
||||
) => Promise<ResponseObject>;
|
||||
removeCollection: (collectionId: number) => Promise<ResponseObject>;
|
||||
};
|
||||
|
||||
const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||
@@ -39,7 +44,7 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||
collections: [...state.collections, data.response],
|
||||
}));
|
||||
|
||||
return response.ok;
|
||||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
updateCollection: async (collection) => {
|
||||
const response = await fetch("/api/routes/collections", {
|
||||
@@ -52,8 +57,6 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (response.ok)
|
||||
set((state) => ({
|
||||
collections: state.collections.map((e) =>
|
||||
@@ -61,7 +64,7 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||
),
|
||||
}));
|
||||
|
||||
return response.ok;
|
||||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
removeCollection: async (id) => {
|
||||
const response = await fetch("/api/routes/collections", {
|
||||
@@ -74,8 +77,6 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (response.ok) {
|
||||
set((state) => ({
|
||||
collections: state.collections.filter((e) => e.id !== id),
|
||||
@@ -83,7 +84,7 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||
useTagStore.getState().setTags();
|
||||
}
|
||||
|
||||
return response.ok;
|
||||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
+13
-12
@@ -3,19 +3,26 @@ import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||
import useTagStore from "./tags";
|
||||
import useCollectionStore from "./collections";
|
||||
|
||||
type ResponseObject = {
|
||||
ok: boolean;
|
||||
data: object | string;
|
||||
};
|
||||
|
||||
type LinkStore = {
|
||||
links: LinkIncludingShortenedCollectionAndTags[];
|
||||
setLinks: (
|
||||
data: LinkIncludingShortenedCollectionAndTags[],
|
||||
isInitialCall: boolean
|
||||
) => void;
|
||||
addLink: (body: LinkIncludingShortenedCollectionAndTags) => Promise<boolean>;
|
||||
addLink: (
|
||||
body: LinkIncludingShortenedCollectionAndTags
|
||||
) => Promise<ResponseObject>;
|
||||
updateLink: (
|
||||
link: LinkIncludingShortenedCollectionAndTags
|
||||
) => Promise<boolean>;
|
||||
) => Promise<ResponseObject>;
|
||||
removeLink: (
|
||||
link: LinkIncludingShortenedCollectionAndTags
|
||||
) => Promise<boolean>;
|
||||
) => Promise<ResponseObject>;
|
||||
resetLinks: () => void;
|
||||
};
|
||||
|
||||
@@ -41,8 +48,6 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (response.ok) {
|
||||
set((state) => ({
|
||||
links: [data.response, ...state.links],
|
||||
@@ -51,7 +56,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||
useCollectionStore.getState().setCollections();
|
||||
}
|
||||
|
||||
return response.ok;
|
||||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
updateLink: async (link) => {
|
||||
const response = await fetch("/api/routes/links", {
|
||||
@@ -64,8 +69,6 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (response.ok) {
|
||||
set((state) => ({
|
||||
links: state.links.map((e) =>
|
||||
@@ -76,7 +79,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||
useCollectionStore.getState().setCollections();
|
||||
}
|
||||
|
||||
return response.ok;
|
||||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
removeLink: async (link) => {
|
||||
const response = await fetch("/api/routes/links", {
|
||||
@@ -89,8 +92,6 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (response.ok) {
|
||||
set((state) => ({
|
||||
links: state.links.filter((e) => e.id !== link.id),
|
||||
@@ -98,7 +99,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||
useTagStore.getState().setTags();
|
||||
}
|
||||
|
||||
return response.ok;
|
||||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
resetLinks: () => set({ links: [] }),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user