Reworked access to tags as public viewer

This commit is contained in:
Oliver Schwamb
2024-07-10 10:22:58 +02:00
parent e8d0cce58a
commit abb73f80bd
7 changed files with 52 additions and 29 deletions
-4
View File
@@ -11,13 +11,11 @@ type ResponseObject = {
type LinkStore = {
links: LinkIncludingShortenedCollectionAndTags[];
selectedLinks: LinkIncludingShortenedCollectionAndTags[];
allLinksOfCollection: LinkIncludingShortenedCollectionAndTags[];
setLinks: (
data: LinkIncludingShortenedCollectionAndTags[],
isInitialCall: boolean
) => void;
setSelectedLinks: (links: LinkIncludingShortenedCollectionAndTags[]) => void;
setAllLinksOfCollection: (links: LinkIncludingShortenedCollectionAndTags[]) => void;
addLink: (
body: LinkIncludingShortenedCollectionAndTags
) => Promise<ResponseObject>;
@@ -41,7 +39,6 @@ type LinkStore = {
const useLinkStore = create<LinkStore>()((set) => ({
links: [],
selectedLinks: [],
allLinksOfCollection: [],
setLinks: async (data, isInitialCall) => {
isInitialCall &&
set(() => ({
@@ -61,7 +58,6 @@ const useLinkStore = create<LinkStore>()((set) => ({
}));
},
setSelectedLinks: (links) => set({ selectedLinks: links }),
setAllLinksOfCollection: (links) => set({allLinksOfCollection: links}),
addLink: async (body) => {
const response = await fetch("/api/v1/links", {
body: JSON.stringify(body),
+7 -3
View File
@@ -8,15 +8,19 @@ type ResponseObject = {
type TagStore = {
tags: TagIncludingLinkCount[];
setTags: () => void;
setTags: (collectionId?: number) => void;
updateTag: (tag: TagIncludingLinkCount) => Promise<ResponseObject>;
removeTag: (tagId: number) => Promise<ResponseObject>;
};
const useTagStore = create<TagStore>()((set) => ({
tags: [],
setTags: async () => {
const response = await fetch("/api/v1/tags");
setTags: async (collectionId?: number) => {
let path = "/api/v1/tags";
if (collectionId) {
path = "/api/v1/public/collections/tags?collectionId=" + encodeURIComponent(collectionId);
}
const response = await fetch(path);
const data = await response.json();