Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 48 additions & 28 deletions src/routes/demos/demoDir/BottomBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Text } from "@mantine/core";
import { IconTag, IconTrash, IconX } from "@tabler/icons-react";
import { IconChecks, IconTag, IconTrash, IconX } from "@tabler/icons-react";

import { formatFileSize } from "@/util";

Expand All @@ -11,6 +11,8 @@ export type Props = {
selectedDemoCount: number;
selectedFileSize: number;
selectionMode: boolean;
allVisibleSelected: boolean;
handleSelectAll(): void;
handleDeselectAll(): void;
handleDeleteSelected(): void;
handleTagSelected(): void;
Expand All @@ -22,6 +24,8 @@ export default function BottomBar({
selectedDemoCount,
selectedFileSize,
selectionMode,
allVisibleSelected,
handleSelectAll,
handleDeselectAll,
handleDeleteSelected,
handleTagSelected,
Expand All @@ -31,42 +35,58 @@ export default function BottomBar({
<Text inline ml="sm">
{totalDemoCount} Demos ({formatFileSize(totalFileSize)})
</Text>
{selectionMode && (
{(selectionMode || totalDemoCount > 0) && (
<>
<Text inline ml="sm">
{selectedDemoCount} Selected ({formatFileSize(selectedFileSize)})
</Text>
{selectionMode && (
<Text inline ml="sm">
{selectedDemoCount} Selected ({formatFileSize(selectedFileSize)})
</Text>
)}
<div style={{ flexGrow: 1 }} />
<Button
variant="subtle"
radius={0}
color="inherit"
size="md"
leftSection={<IconTag />}
onClick={handleTagSelected}
leftSection={<IconChecks />}
onClick={allVisibleSelected ? handleDeselectAll : handleSelectAll}
>
Tags
</Button>
<Button
variant="subtle"
radius={0}
color="inherit"
size="md"
leftSection={<IconTrash />}
onClick={handleDeleteSelected}
>
Delete selected
</Button>
<Button
variant="subtle"
radius={0}
color="inherit"
size="md"
leftSection={<IconX />}
onClick={handleDeselectAll}
>
Cancel
{allVisibleSelected ? "Deselect all" : "Select all"}
</Button>
{selectionMode && (
<>
<Button
variant="subtle"
radius={0}
color="inherit"
size="md"
leftSection={<IconTag />}
onClick={handleTagSelected}
>
Tags
</Button>
<Button
variant="subtle"
radius={0}
color="inherit"
size="md"
leftSection={<IconTrash />}
onClick={handleDeleteSelected}
>
Delete selected
</Button>
<Button
variant="subtle"
radius={0}
color="inherit"
size="md"
leftSection={<IconX />}
onClick={handleDeselectAll}
>
Cancel
</Button>
</>
)}
</>
)}
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/routes/demos/demoDir/DemoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export default function DemoList({ demos, onDemosChanged }: DemoListProps) {
setSelectedRows(Array(demos.length).fill(false));
};

const handleSelectAll = () => {
setSelectedRows(Array(demos.length).fill(true));
};

const handleDeleteSelected = () => {
const demosToDelete = selectedRows
.map((selected, index) => [selected, index] as const)
Expand Down Expand Up @@ -126,6 +130,11 @@ export default function DemoList({ demos, onDemosChanged }: DemoListProps) {
[selectedRows]
);

const allVisibleSelected = useMemo(
() => demos.length > 0 && selectedDemoCount === demos.length,
[demos.length, selectedDemoCount]
);

return (
<div
style={{
Expand Down Expand Up @@ -153,6 +162,8 @@ export default function DemoList({ demos, onDemosChanged }: DemoListProps) {
selectedDemoCount={selectedDemoCount}
selectedFileSize={selectedFileSize}
selectionMode={selectionMode}
allVisibleSelected={allVisibleSelected}
handleSelectAll={handleSelectAll}
handleDeselectAll={handleDeselectAll}
handleDeleteSelected={handleDeleteSelected}
handleTagSelected={handleTagSelected}
Expand Down
Loading