added new api route + fixed dropdown
This commit is contained in:
@@ -17,6 +17,7 @@ type LinkStore = {
|
||||
addLink: (
|
||||
body: LinkIncludingShortenedCollectionAndTags
|
||||
) => Promise<ResponseObject>;
|
||||
getLink: (linkId: number) => Promise<ResponseObject>;
|
||||
updateLink: (
|
||||
link: LinkIncludingShortenedCollectionAndTags
|
||||
) => Promise<ResponseObject>;
|
||||
@@ -65,6 +66,21 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||
|
||||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
getLink: async (linkId) => {
|
||||
const response = await fetch(`/api/v1/links/${linkId}`);
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
set((state) => ({
|
||||
links: state.links.map((e) =>
|
||||
e.id === data.response.id ? data.response : e
|
||||
),
|
||||
}));
|
||||
}
|
||||
|
||||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
updateLink: async (link) => {
|
||||
const response = await fetch(`/api/v1/links/${link.id}`, {
|
||||
body: JSON.stringify(link),
|
||||
|
||||
Reference in New Issue
Block a user