(auth?: MobileAuth)
| 74 | }; |
| 75 | |
| 76 | const 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 | |
| 108 | const useCreateCollection = (auth?: MobileAuth) => { |
| 109 | const queryClient = useQueryClient(); |
no outgoing calls
no test coverage detected