diff --git a/src/lib/api/mutations/party.mutations.ts b/src/lib/api/mutations/party.mutations.ts
index abbeebf3..1ec21c5e 100644
--- a/src/lib/api/mutations/party.mutations.ts
+++ b/src/lib/api/mutations/party.mutations.ts
@@ -15,6 +15,7 @@ import {
} from '$lib/api/adapters/party.adapter'
import { partyKeys } from '$lib/api/queries/party.queries'
import { userKeys } from '$lib/api/queries/user.queries'
+import { crewKeys } from '$lib/api/queries/crew.queries'
import type { Party } from '$lib/types/api/party'
/**
@@ -312,3 +313,69 @@ export function useRegeneratePreview() {
}
}))
}
+
+/**
+ * Share party with crew mutation
+ *
+ * Shares a party with the current user's crew.
+ *
+ * @example
+ * ```svelte
+ *
+ * ```
+ */
+export function useSharePartyWithCrew() {
+ const queryClient = useQueryClient()
+
+ return createMutation(() => ({
+ mutationFn: ({ partyId }: { partyId: string; shortcode: string }) =>
+ partyAdapter.shareWithCrew(partyId),
+ onSuccess: (_share, { shortcode }) => {
+ // Invalidate the party to refresh its shares
+ queryClient.invalidateQueries({ queryKey: partyKeys.detail(shortcode) })
+ // Invalidate crew's shared parties list
+ queryClient.invalidateQueries({ queryKey: crewKeys.sharedParties() })
+ }
+ }))
+}
+
+/**
+ * Remove party share mutation
+ *
+ * Removes a share from a party.
+ *
+ * @example
+ * ```svelte
+ *
+ * ```
+ */
+export function useRemovePartyShare() {
+ const queryClient = useQueryClient()
+
+ return createMutation(() => ({
+ mutationFn: ({ partyId, shareId }: { partyId: string; shareId: string; shortcode: string }) =>
+ partyAdapter.removeShare(partyId, shareId),
+ onSuccess: (_data, { shortcode }) => {
+ // Invalidate the party to refresh its shares
+ queryClient.invalidateQueries({ queryKey: partyKeys.detail(shortcode) })
+ // Invalidate crew's shared parties list
+ queryClient.invalidateQueries({ queryKey: crewKeys.sharedParties() })
+ }
+ }))
+}
diff --git a/src/lib/api/queries/crew.queries.ts b/src/lib/api/queries/crew.queries.ts
index c768226f..778e667d 100644
--- a/src/lib/api/queries/crew.queries.ts
+++ b/src/lib/api/queries/crew.queries.ts
@@ -7,7 +7,7 @@
* @module api/queries/crew
*/
-import { queryOptions } from '@tanstack/svelte-query'
+import { queryOptions, infiniteQueryOptions } from '@tanstack/svelte-query'
import { crewAdapter } from '$lib/api/adapters/crew.adapter'
import type { MemberFilter } from '$lib/types/api/crew'
@@ -96,6 +96,30 @@ export const crewQueries = {
queryFn: () => crewAdapter.getPendingPhantomClaims(),
staleTime: 1000 * 60 * 2, // 2 minutes
gcTime: 1000 * 60 * 15 // 15 minutes
+ }),
+
+ /**
+ * Parties shared with the crew query options
+ * Uses infinite query for pagination
+ */
+ sharedParties: () =>
+ infiniteQueryOptions({
+ queryKey: ['crew', 'shared_parties'] as const,
+ queryFn: async ({ pageParam }) => {
+ const response = await crewAdapter.getSharedParties(pageParam)
+ return {
+ parties: response.parties,
+ page: response.meta.page,
+ totalPages: response.meta.totalPages,
+ total: response.meta.count,
+ perPage: response.meta.perPage
+ }
+ },
+ initialPageParam: 1,
+ getNextPageParam: (lastPage) =>
+ lastPage.page < lastPage.totalPages ? lastPage.page + 1 : undefined,
+ staleTime: 1000 * 60 * 2, // 2 minutes
+ gcTime: 1000 * 60 * 15 // 15 minutes
})
}
@@ -122,6 +146,7 @@ export const crewKeys = {
membersAll: () => [...crewKeys.all, 'members'] as const,
members: (filter: MemberFilter) => [...crewKeys.all, 'members', filter] as const,
crewInvitations: (crewId: string) => [...crewKeys.all, crewId, 'invitations'] as const,
+ sharedParties: () => [...crewKeys.all, 'shared_parties'] as const,
invitations: {
all: ['invitations'] as const,
pending: () => ['invitations', 'pending'] as const