MCPcopy
hub / github.com/linkwarden/linkwarden / useCollections

Function useCollections

packages/router/collections.tsx:76–106  ·  view source on GitHub ↗
(auth?: MobileAuth)

Source from the content-addressed store, hash-verified

74};
75
76const useCollections = (auth?: MobileAuth) => {
77 let status: "loading" | "authenticated" | "unauthenticated";
78
79 if (!auth) {
80 const session = useSession();
81 status = session.status;
82 } else {
83 status = auth?.status;
84 }
85
86 return useQuery({
87 queryKey: ["collections"],
88 queryFn: async (): Promise<CollectionIncludingMembersAndLinkCount[]> => {
89 const response = await fetch(
90 (auth?.instance ? auth?.instance : "") + "/api/v1/collections",
91 auth?.session
92 ? {
93 headers: {
94 Authorization: `Bearer ${auth.session}`,
95 },
96 }
97 : undefined
98 );
99 const data = await response.json();
100
101 if (Array.isArray(data.response)) return data.response;
102 else return [];
103 },
104 enabled: status === "authenticated",
105 });
106};
107
108const useCreateCollection = (auth?: MobileAuth) => {
109 const queryClient = useQueryClient();

Callers 15

DashboardLayoutDropdownFunction · 0.90
CardFunction · 0.90
CollectionListingFunction · 0.90
SidebarFunction · 0.90
CollectionSelectionFunction · 0.90
LinksFunction · 0.90
PreservationNavbarFunction · 0.90
UploadFileModalFunction · 0.90
NewLinkModalFunction · 0.90
PageFunction · 0.90
PageFunction · 0.90
PageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected