Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move sorting out of filter area #32

Merged
merged 1 commit into from
Jan 27, 2025
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
13 changes: 5 additions & 8 deletions src/components/Entities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Alert, AlertDescription } from '@/components/ui/alert';
import { useLocalStorage } from '../hooks/useLocalStorage';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
import SortControls from './SortControls';
import { EntityFilterContext } from '../context/EntityFilterContext';
import { EntityFilters } from '../types/filters';
import { ActiveEntityFilters as ActiveFilters } from './ActiveEntityFilters';
Expand Down Expand Up @@ -126,6 +125,11 @@ export default function Entities() {
totalItems={data.total}
itemsPerPage={itemsPerPage}
onItemsPerPageChange={handleItemsPerPageChange}
sort={sort}
setSort={setSort}
direction={direction}
setDirection={setDirection}
sortOptions={sortOptions}
/>
);
};
Expand Down Expand Up @@ -198,13 +202,6 @@ export default function Entities() {
<Card className="border-gray-100 shadow-sm">
<CardContent className="p-6 space-y-4">
<EntityFilter filters={filters} onFilterChange={setFilters} />
<SortControls
sort={sort}
setSort={setSort}
direction={direction}
setDirection={setDirection}
sortOptions={sortOptions}
/>
</CardContent>
</Card>
)}
Expand Down
14 changes: 6 additions & 8 deletions src/components/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Alert, AlertDescription } from '@/components/ui/alert';
import { useLocalStorage } from '../hooks/useLocalStorage';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
import SortControls from './SortControls';
import { EventFilterContext } from '../context/EventFilterContext';
import { EventFilters } from '../types/filters';
import { ActiveEventFilters as ActiveFilters } from './ActiveEventFilters';
Expand Down Expand Up @@ -136,6 +135,11 @@ export default function Events() {
totalItems={data.total}
itemsPerPage={itemsPerPage}
onItemsPerPageChange={handleItemsPerPageChange}
sort={sort}
setSort={setSort}
direction={direction}
setDirection={setDirection}
sortOptions={sortOptions}
/>
);
};
Expand Down Expand Up @@ -208,13 +212,7 @@ export default function Events() {
<Card className="shadow-sm">
<CardContent className="p-6 space-y-4">
<EventFilter filters={filters} onFilterChange={setFilters} />
<SortControls
sort={sort}
setSort={setSort}
direction={direction}
setDirection={setDirection}
sortOptions={sortOptions}
/>

</CardContent>
</Card>
)}
Expand Down
23 changes: 22 additions & 1 deletion src/components/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button } from "@/components/ui/button";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { ChevronLeft, ChevronRight } from "lucide-react";
import SortControls from './SortControls';

interface PaginationProps {
currentPage: number;
Expand All @@ -10,6 +11,11 @@ interface PaginationProps {
totalItems: number;
itemsPerPage: number;
onItemsPerPageChange: (count: number) => void;
sort: string;
setSort: (value: string) => void;
direction: 'asc' | 'desc';
setDirection: (value: 'asc' | 'desc') => void;
sortOptions: { value: string; label: string }[];
}

const itemsPerPageOptions = [
Expand All @@ -26,12 +32,19 @@ export function Pagination({
totalItems,
itemsPerPage,
onItemsPerPageChange,
sort,
setSort,
direction,
setDirection,
sortOptions
}: PaginationProps) {

return (
<div className="flex flex-col gap-4 md:gap-0 border-t py-3 md:px-6">
<div className="flex flex-col md:flex-row md:items-center md:justify-between">
<div className="flex items-center justify-between md:justify-start gap-4">
<p className="text-sm text-gray-700">

<p className="text-sm text-gray-700 hidden md:block">
Showing{' '}
<span className="font-medium">{((currentPage - 1) * itemsPerPage) + 1}</span>{' '}
to{' '}
Expand All @@ -58,6 +71,14 @@ export function Pagination({
))}
</SelectContent>
</Select>

<SortControls
sort={sort}
setSort={setSort}
direction={direction}
setDirection={setDirection}
sortOptions={sortOptions}
/>
</div>

<div className="flex items-center justify-between md:justify-end gap-6 mt-4 md:mt-0">
Expand Down
54 changes: 27 additions & 27 deletions src/components/SortControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ interface SortControlsProps {

const SortControls: React.FC<SortControlsProps> = ({ sort, setSort, direction, setDirection, sortOptions }) => {
return (
<div className="flex items-center justify-between pt-4 border-t">
<div className="flex items-center gap-2">
<span className="text-sm text-gray-500">Sort by:</span>
<Select
value={sort}
onValueChange={(value) => setSort(value)}
>
<SelectTrigger className="w-[180px]">
<SelectValue />
</SelectTrigger>
<SelectContent>
{sortOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
<Button
variant="ghost"
size="sm"
onClick={() => setDirection(direction === 'asc' ? 'desc' : 'asc')}
className="text-gray-500"
>
{direction === 'asc' ? '↑' : '↓'}
</Button>
</div>

<div className="flex items-center gap-2">
<span className="text-sm text-gray-500">Sort by:</span>
<Select
value={sort}
onValueChange={(value) => setSort(value)}
>
<SelectTrigger className="w-[180px]">
<SelectValue />
</SelectTrigger>
<SelectContent>
{sortOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
<Button
variant="ghost"
size="sm"
onClick={() => setDirection(direction === 'asc' ? 'desc' : 'asc')}
className="text-gray-500"
>
{direction === 'asc' ? '↑' : '↓'}
</Button>
</div>

);
};

Expand Down