Skip to content

Commit 55edfb2

Browse files
authored
remove spinner from delete button when executing deletion from multi selection bar (#943)
1 parent 0bc2ef5 commit 55edfb2

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

apps/web/app/(org)/dashboard/caps/Caps.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ import { toast } from "sonner";
1313
import { useEffectMutation } from "@/lib/EffectRuntime";
1414
import { Rpc, withRpc } from "@/lib/Rpcs";
1515
import { useDashboardContext } from "../Contexts";
16+
import {
17+
NewFolderDialog,
18+
SelectedCapsBar,
19+
UploadCapButton,
20+
UploadPlaceholderCard,
21+
} from "./components";
1622
import { CapCard } from "./components/CapCard/CapCard";
1723
import { CapPagination } from "./components/CapPagination";
1824
import { EmptyCapState } from "./components/EmptyCapState";
1925
import type { FolderDataType } from "./components/Folder";
2026
import Folder from "./components/Folder";
21-
import { NewFolderDialog } from "./components/NewFolderDialog";
22-
import { SelectedCapsBar } from "./components/SelectedCapsBar";
23-
import { UploadCapButton } from "./components/UploadCapButton";
24-
import { UploadPlaceholderCard } from "./components/UploadPlaceholderCard";
2527
import { useUploadingContext } from "./UploadingContext";
2628

2729
export type VideoData = {
@@ -149,7 +151,7 @@ export const Caps = ({
149151
document.activeElement?.tagName || "",
150152
)
151153
) {
152-
deleteCaps.mutate(selectedCaps);
154+
deleteCaps(selectedCaps);
153155
}
154156
}
155157

@@ -197,7 +199,7 @@ export const Caps = ({
197199
});
198200
};
199201

200-
const deleteCaps = useEffectMutation({
202+
const { mutate: deleteCaps, isPending: isDeletingCaps } = useEffectMutation({
201203
mutationFn: Effect.fn(function* (ids: Video.VideoId[]) {
202204
if (ids.length === 0) return;
203205

@@ -252,7 +254,7 @@ export const Caps = ({
252254
},
253255
});
254256

255-
const deleteCap = useEffectMutation({
257+
const { mutate: deleteCap, isPending: isDeletingCap } = useEffectMutation({
256258
mutationFn: (id: Video.VideoId) => withRpc((r) => r.VideoDelete(id)),
257259
onSuccess: () => {
258260
toast.success("Cap deleted successfully");
@@ -324,11 +326,11 @@ export const Caps = ({
324326
key={cap.id}
325327
cap={cap}
326328
analytics={analytics[cap.id] || 0}
327-
onDelete={async () => {
329+
onDelete={() => {
328330
if (selectedCaps.length > 0) {
329-
await deleteCaps.mutateAsync(selectedCaps);
331+
deleteCaps(selectedCaps);
330332
} else {
331-
deleteCap.mutateAsync(cap.id);
333+
deleteCap(cap.id);
332334
}
333335
}}
334336
userId={user?.id}
@@ -351,8 +353,8 @@ export const Caps = ({
351353
<SelectedCapsBar
352354
selectedCaps={selectedCaps}
353355
setSelectedCaps={setSelectedCaps}
354-
deleteSelectedCaps={() => deleteCaps.mutate(selectedCaps)}
355-
isDeleting={deleteCaps.isPending}
356+
deleteSelectedCaps={() => deleteCaps(selectedCaps)}
357+
isDeleting={isDeletingCaps || isDeletingCap}
356358
/>
357359
{isDraggingCap && (
358360
<div className="fixed inset-0 z-50 pointer-events-none">

apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface CapCardProps extends PropsWithChildren {
6363
};
6464
analytics: number;
6565
isLoadingAnalytics: boolean;
66-
onDelete?: () => Promise<any>;
66+
onDelete?: () => void;
6767
userId?: string;
6868
sharedCapCard?: boolean;
6969
isSelected?: boolean;

apps/web/app/(org)/dashboard/caps/components/SelectedCapsBar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export const SelectedCapsBar = ({
2525
}: SelectedCapsBarProps) => {
2626
const [confirmOpen, setConfirmOpen] = useState(false);
2727

28-
const handleConfirmDelete = async () => {
29-
await deleteSelectedCaps();
28+
const handleConfirmDelete = () => {
29+
deleteSelectedCaps();
3030
setConfirmOpen(false);
3131
};
3232

@@ -70,7 +70,6 @@ export const SelectedCapsBar = ({
7070
onClick={() => setConfirmOpen(true)}
7171
disabled={isDeleting}
7272
className="size-[40px] min-w-[unset] p-0"
73-
spinner={isDeleting}
7473
size="sm"
7574
>
7675
<FontAwesomeIcon className="w-3.5 text-white" icon={faTrash} />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export * from "./CapPagination";
2+
export * from "./EmptyCapState";
3+
export * from "./Folder";
4+
export * from "./NewFolderDialog";
5+
export * from "./SelectedCapsBar";
6+
export * from "./UploadCapButton";
7+
export * from "./UploadPlaceholderCard";

0 commit comments

Comments
 (0)