diff --git a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx index c02c652aa..395f3225d 100644 --- a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx +++ b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx @@ -627,8 +627,13 @@ export function HomeFeedContainer(): JSX.Element { multiSelectMode === 'search' ? queryInputs.searchQuery || 'in:inbox' : `includes:${checkedItems.join(',')}` + const expectedCount = + multiSelectMode === 'search' + ? itemsPages?.[0].search.pageInfo.totalCount || 0 + : checkedItems.length + try { - const res = await bulkActionMutation(action, query) + const res = await bulkActionMutation(action, query, expectedCount) if (res) { switch (action) { case BulkAction.ARCHIVE: @@ -648,7 +653,7 @@ export function HomeFeedContainer(): JSX.Element { })() setMultiSelectMode('off') }, - [multiSelectMode, checkedItems] + [itemsPages, multiSelectMode, checkedItems] ) return ( diff --git a/packages/web/lib/networking/mutations/bulkActionMutation.ts b/packages/web/lib/networking/mutations/bulkActionMutation.ts index eb0b207ed..07ea621e2 100644 --- a/packages/web/lib/networking/mutations/bulkActionMutation.ts +++ b/packages/web/lib/networking/mutations/bulkActionMutation.ts @@ -17,10 +17,15 @@ type BulkActionResponse = { export async function bulkActionMutation( action: BulkAction, - query: string + query: string, + expectedCount: number ): Promise { const mutation = gql` - mutation BulkAction($action: BulkActionType!, $query: String!) { + mutation BulkAction( + $action: BulkActionType! + $query: String! + $expectedCount: Int + ) { bulkAction(query: $query, action: $action) { ... on BulkActionSuccess { success @@ -35,7 +40,11 @@ export async function bulkActionMutation( console.log('bulkActionbulkActionMutation', mutation) try { - const response = await gqlFetcher(mutation, { action, query }) + const response = await gqlFetcher(mutation, { + action, + query, + expectedCount, + }) console.log('response', response) const data = response as BulkActionResponse | undefined return data?.bulkAction?.success ?? false diff --git a/packages/web/pages/tools/bulk.tsx b/packages/web/pages/tools/bulk.tsx deleted file mode 100644 index a0889fbf4..000000000 --- a/packages/web/pages/tools/bulk.tsx +++ /dev/null @@ -1,172 +0,0 @@ -import { useCallback, useState } from 'react' -import { applyStoredTheme } from '../../lib/themeUpdater' - -import { VStack } from '../../components/elements/LayoutPrimitives' - -import { StyledText } from '../../components/elements/StyledText' -import { ProfileLayout } from '../../components/templates/ProfileLayout' -import { - BulkAction, - bulkActionMutation, -} from '../../lib/networking/mutations/bulkActionMutation' -import { Button } from '../../components/elements/Button' -import { theme } from '../../components/tokens/stitches.config' -import { ConfirmationModal } from '../../components/patterns/ConfirmationModal' -import { showErrorToast, showSuccessToast } from '../../lib/toastHelpers' -import { useRouter } from 'next/router' - -type RunningState = 'none' | 'confirming' | 'running' | 'completed' - -export default function BulkPerformer(): JSX.Element { - const router = useRouter() - - applyStoredTheme(false) - - const [action, setAction] = useState() - const [errorMessage, setErrorMessage] = useState() - const [runningState, setRunningState] = useState('none') - - const performAction = useCallback(() => { - ;(async () => { - console.log('performing action: ', action) - if (!action) { - showErrorToast('Unable to run action, no action set.') - return - } - try { - const success = await bulkActionMutation(action, 'in:all') - if (!success) { - throw 'Success not returned' - } - showSuccessToast('Bulk action is being performed.') - setRunningState('completed') - } catch (err) { - showErrorToast('Error performing bulk action.') - } - })() - }, [action]) - - return ( - - - - Perform a Bulk Action - - - Use this tool to perform a bulk operation on all the items in your - library.

- More info -
- - Note: This operation can not be undone. - - - {runningState == 'completed' ? ( - - Your bulk action has started. Please note that it can take some - time for these actions to complete. During this time, we recommend - not modifying your library as new items could be updated by the - action. - - ) : ( - <> - - - - - - - )} - - {runningState == 'confirming' && ( - setRunningState('none')} - /> - )} - {runningState == 'completed' && ( - - - - )} - - {errorMessage && ( - {errorMessage} - )} - -
-
- ) -}