style(lists): refresh pagination and loading states

This commit is contained in:
2026-04-29 02:05:39 +03:30
parent e4b1dcf3c0
commit 5082dab99e
5 changed files with 240 additions and 89 deletions

View File

@@ -0,0 +1,85 @@
import { useMemo } from "react";
import { useTranslation } from "../hooks/useTranslation";
type ListPageSkeletonVariant = "list" | "standard-grid" | "dense-grid";
type ListPageSkeletonProps = {
variant?: ListPageSkeletonVariant;
};
export function ListPageSkeleton({
variant = "standard-grid",
}: ListPageSkeletonProps) {
const { t } = useTranslation();
const cardCount = variant === "list" ? 5 : variant === "dense-grid" ? 8 : 6;
const items = useMemo(
() => Array.from({ length: cardCount }, (_, index) => index),
[cardCount],
);
const gridClassName =
variant === "dense-grid"
? "grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4"
: "grid grid-cols-1 gap-4 md:grid-cols-2 2xl:grid-cols-3";
return (
<div className="flex flex-1 flex-col rounded-3xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-6">
{variant === "list" ? (
<div className="flex flex-1 flex-col gap-4 animate-pulse">
{items.map((item) => (
<div
key={item}
className="rounded-2xl border border-slate-200/80 bg-slate-50/70 p-5 dark:border-slate-800 dark:bg-slate-950/40"
>
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<div className="flex min-w-0 items-center gap-3">
<div className="h-10 w-10 shrink-0 rounded-xl bg-slate-200 dark:bg-slate-800" />
<div className="min-w-0 space-y-2">
<div className="h-4 w-40 max-w-[60vw] rounded-full bg-slate-200 dark:bg-slate-800" />
<div className="h-3 w-64 max-w-[70vw] rounded-full bg-slate-200 dark:bg-slate-800" />
</div>
</div>
<div className="flex items-center gap-2 self-end sm:self-auto">
<div className="h-8 w-8 rounded-xl bg-slate-200 dark:bg-slate-800" />
<div className="h-8 w-8 rounded-xl bg-slate-200 dark:bg-slate-800" />
<div className="h-8 w-8 rounded-xl bg-slate-200 dark:bg-slate-800" />
</div>
</div>
</div>
))}
</div>
) : (
<div className={`${gridClassName} animate-pulse`}>
{items.map((item) => (
<div
key={item}
className="rounded-2xl border border-slate-200/80 bg-slate-50/70 p-5 dark:border-slate-800 dark:bg-slate-950/40"
>
<div className="flex items-start justify-between gap-3">
<div className="flex min-w-0 items-center gap-3">
<div className="h-10 w-10 shrink-0 rounded-xl bg-slate-200 dark:bg-slate-800" />
<div className="min-w-0 space-y-2">
<div className="h-4 w-32 max-w-[40vw] rounded-full bg-slate-200 dark:bg-slate-800" />
<div className="h-3 w-24 rounded-full bg-slate-200 dark:bg-slate-800" />
</div>
</div>
<div className="flex items-center gap-2">
<div className="h-8 w-8 rounded-xl bg-slate-200 dark:bg-slate-800" />
<div className="h-8 w-8 rounded-xl bg-slate-200 dark:bg-slate-800" />
</div>
</div>
<div className="mt-5 space-y-2">
<div className="h-3 w-full rounded-full bg-slate-200 dark:bg-slate-800" />
<div className="h-3 w-[82%] rounded-full bg-slate-200 dark:bg-slate-800" />
<div className="h-3 w-[64%] rounded-full bg-slate-200 dark:bg-slate-800" />
</div>
<div className="mt-5 h-3 w-28 rounded-full bg-slate-200 dark:bg-slate-800" />
</div>
))}
</div>
)}
</div>
);
}

View File

@@ -1,5 +1,7 @@
import React from 'react';
import React, { useMemo } from 'react';
import { ChevronLeft, ChevronRight, MoreHorizontal } from 'lucide-react';
import { useTranslation } from '../hooks/useTranslation';
import { cn } from '../lib/utils';
import { Select } from './ui/Select';
import { Button } from './ui/button';
@@ -35,50 +37,115 @@ export const Pagination: React.FC<PaginationProps> = ({
const startItem = ((currentPage - 1) * limit) + 1;
const endItem = Math.min(currentPage * limit, totalCount);
const pageItems = useMemo(() => {
if (totalPages <= 7) {
return Array.from({ length: totalPages }, (_, index) => index + 1);
}
const pages: Array<number | "ellipsis-left" | "ellipsis-right"> = [1];
const start = Math.max(2, currentPage - 1);
const end = Math.min(totalPages - 1, currentPage + 1);
if (start > 2) {
pages.push("ellipsis-left");
}
for (let page = start; page <= end; page += 1) {
pages.push(page);
}
if (end < totalPages - 1) {
pages.push("ellipsis-right");
}
pages.push(totalPages);
return pages;
}, [currentPage, totalPages]);
return (
<div className="mt-auto sticky bottom-0 bg-slate-50/60 dark:bg-slate-900/60 backdrop-blur-md left-0 right-0 z-10 flex items-center justify-between py-4 px-4 -mx-4 sm:px-0 sm:mx-0">
<div className="flex items-center gap-4">
<Select
value={String(limit)}
onChange={(val) => {
onLimitChange(Number(val));
onPageChange(1);
}}
options={pageSizeOptions.map((option) => ({
value: String(option),
label: String(toPersianNum(option)),
}))}
className="w-20 shrink-0"
buttonClassName=""
/>
<span className="text-sm text-slate-500 dark:text-slate-400 hidden sm:inline-block">
{t.pagination?.showing || 'Showing'} <strong className="text-slate-700 dark:text-slate-300">{toPersianNum(startItem)}</strong> {t.pagination?.to || '-'} <strong className="text-slate-700 dark:text-slate-300">{toPersianNum(endItem)}</strong> {t.pagination?.of || 'of'} <strong className="text-slate-700 dark:text-slate-300">{toPersianNum(totalCount)}</strong>
</span>
</div>
<div className="sticky bottom-0 left-0 right-0 z-10 mt-auto -mx-4 border-t border-slate-200/80 bg-white/90 px-4 py-4 backdrop-blur-xl dark:border-slate-800/80 dark:bg-slate-950/90 sm:mx-0 sm:rounded-3xl sm:border sm:px-5">
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between lg:justify-start">
<div className="flex items-center gap-3">
<Select
value={String(limit)}
onChange={(val) => {
onLimitChange(Number(val));
onPageChange(1);
}}
options={pageSizeOptions.map((option) => ({
value: String(option),
label: String(toPersianNum(option)),
}))}
className="w-24 shrink-0"
buttonClassName="h-10 rounded-2xl border-slate-200 bg-slate-50 font-medium text-slate-700 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200"
/>
<span className="inline-flex h-10 items-center rounded-2xl border border-slate-200 bg-slate-50 px-4 text-sm font-medium text-slate-600 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300 sm:hidden">
{toPersianNum(currentPage)} / {toPersianNum(totalPages)}
</span>
</div>
<span className="text-sm text-slate-500 dark:text-slate-400">
{t.pagination?.showing || 'Showing'} <strong className="text-slate-700 dark:text-slate-200">{toPersianNum(startItem)}</strong> {t.pagination?.to || '-'} <strong className="text-slate-700 dark:text-slate-200">{toPersianNum(endItem)}</strong> {t.pagination?.of || 'of'} <strong className="text-slate-700 dark:text-slate-200">{toPersianNum(totalCount)}</strong>
</span>
</div>
<div className="flex items-center gap-3">
<Button
variant="outline"
size="sm"
onClick={() => onPageChange(currentPage - 1)}
disabled={currentPage === 1}
>
{t.pagination?.previous || 'Previous'}
</Button>
<span className="text-sm text-slate-600 dark:text-slate-400 font-medium hidden sm:inline-block">
{t.pagination?.page || 'Page'} {toPersianNum(currentPage)} {t.pagination?.of || 'of'} {toPersianNum(totalPages)}
</span>
<Button
variant="outline"
size="sm"
onClick={() => onPageChange(currentPage + 1)}
disabled={currentPage >= totalPages}
>
{t.pagination?.next || 'Next'}
</Button>
</div>
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between lg:justify-end">
<div className="hidden items-center gap-2 md:flex">
{pageItems.map((pageItem, index) =>
typeof pageItem === 'number' ? (
<button
key={pageItem}
type="button"
onClick={() => onPageChange(pageItem)}
className={cn(
'inline-flex h-10 min-w-10 items-center justify-center rounded-2xl border px-3 text-sm font-semibold transition-colors',
pageItem === currentPage
? 'border-sky-500 bg-sky-500 text-white shadow-sm'
: 'border-slate-200 bg-slate-50 text-slate-600 hover:border-slate-300 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300 dark:hover:border-slate-600 dark:hover:bg-slate-800',
)}
>
{toPersianNum(pageItem)}
</button>
) : (
<span
key={`${pageItem}-${index}`}
className="inline-flex h-10 min-w-10 items-center justify-center rounded-2xl text-slate-400 dark:text-slate-500"
>
<MoreHorizontal className="h-4 w-4" />
</span>
),
)}
</div>
<div className="flex items-center justify-between gap-3 sm:justify-end">
<Button
variant="outline"
size="sm"
onClick={() => onPageChange(currentPage - 1)}
disabled={currentPage === 1}
className="h-10 rounded-2xl border-slate-200 bg-slate-50 px-4 text-slate-700 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200 dark:hover:bg-slate-800"
>
<ChevronLeft className="h-4 w-4 rtl:rotate-180" />
{t.pagination?.previous || 'Previous'}
</Button>
<div className="hidden text-sm font-medium text-slate-500 dark:text-slate-400 sm:block md:hidden">
{t.pagination?.page || 'Page'} {toPersianNum(currentPage)} {t.pagination?.of || 'of'} {toPersianNum(totalPages)}
</div>
<Button
variant="outline"
size="sm"
onClick={() => onPageChange(currentPage + 1)}
disabled={currentPage >= totalPages}
className="h-10 rounded-2xl border-slate-200 bg-slate-50 px-4 text-slate-700 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200 dark:hover:bg-slate-800"
>
{t.pagination?.next || 'Next'}
<ChevronRight className="h-4 w-4 rtl:rotate-180" />
</Button>
</div>
</div>
</div>
</div>
);
};

View File

@@ -1,5 +1,5 @@
import { useEffect, useState } from "react"
import { Plus, Building2, Loader2, Pencil, Trash2 } from "lucide-react"
import { Plus, Building2, Pencil, Trash2 } from "lucide-react"
import { toast } from "sonner"
import { useWorkspace } from "../context/WorkspaceContext"
import { useAppContext } from "../context/AppContext"
@@ -16,6 +16,7 @@ import CreateClientModal from "../components/CreateClientModal"
import EditClientModal from "../components/EditClientModal"
import DeleteClientModal from "../components/DeleteClientModal"
import FilterBar from "../components/FilterBar"
import { ListPageSkeleton } from "../components/ListPageSkeleton"
import { Button } from "../components/ui/button"
import { Card, CardContent, CardTitle } from "../components/ui/card"
import { Pagination } from "../components/Pagination"
@@ -120,7 +121,8 @@ export default function Clients() {
}
return (
<div className="mx-auto max-w-7xl space-y-5 p-4 md:p-6">
<div className="mx-auto flex min-h-full max-w-7xl flex-col p-4 md:p-6">
<div className="flex flex-1 flex-col gap-5">
<div className="rounded-3xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-6">
<div className="flex items-start justify-between gap-4">
<div>
@@ -155,15 +157,11 @@ export default function Clients() {
</div>
{isLoading ? (
<div className="rounded-3xl border border-slate-200 bg-white p-12 shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div className="flex items-center justify-center text-slate-500 dark:text-slate-400">
<Loader2 className="h-8 w-8 animate-spin" />
</div>
</div>
<ListPageSkeleton variant="standard-grid" />
) : (
<div className="space-y-6">
<div className="flex flex-1 flex-col gap-6">
{clients.length === 0 ? (
<div className="rounded-3xl border-2 border-dashed border-slate-200 bg-white p-12 text-center shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div className="flex flex-1 rounded-3xl border-2 border-dashed border-slate-200 bg-white p-12 text-center shadow-sm dark:border-slate-800 dark:bg-slate-900">
<Building2 className="mx-auto mb-3 h-12 w-12 text-slate-300 dark:text-slate-700" />
<h3 className="text-lg font-medium text-slate-900 dark:text-white">{t.clients.noClients}</h3>
<p className="mt-1 text-slate-500 dark:text-slate-400">
@@ -246,6 +244,7 @@ export default function Clients() {
)}
</div>
)}
</div>
{canCreateClient && (
<CreateClientModal

View File

@@ -10,6 +10,7 @@ import { Pagination } from "../components/Pagination";
import { Plus, Archive, Building2, Pencil, Trash2, X } from "lucide-react";
import FilterBar from "../components/FilterBar";
import { ListPageSkeleton } from "../components/ListPageSkeleton";
import { Button } from "../components/ui/button";
import { Card, CardContent, CardTitle } from "../components/ui/card";
import { Modal } from "../components/Modal";
@@ -181,7 +182,8 @@ export const Projects: React.FC = () => {
return (
<div className="mx-auto max-w-7xl space-y-5 p-4 md:p-6">
<div className="mx-auto flex min-h-full max-w-7xl flex-col p-4 md:p-6">
<div className="flex flex-1 flex-col gap-5">
<div className="rounded-3xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-6">
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
<div>
@@ -285,13 +287,11 @@ export const Projects: React.FC = () => {
</div>
{loading ? (
<div className="rounded-3xl border border-slate-200 bg-white p-12 shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div className="text-center text-slate-500 dark:text-slate-400">{t.projects?.loading || 'Loading...'}</div>
</div>
<ListPageSkeleton variant="standard-grid" />
) : (
<div className="space-y-6">
<div className="flex flex-1 flex-col gap-6">
{projects.length === 0 ? (
<div className="rounded-3xl border-2 border-dashed border-slate-200 bg-white p-12 text-center shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div className="flex flex-1 rounded-3xl border-2 border-dashed border-slate-200 bg-white p-12 text-center shadow-sm dark:border-slate-800 dark:bg-slate-900">
<Building2 className="mx-auto mb-3 h-12 w-12 text-slate-300 dark:text-slate-700" />
<p className="font-medium text-slate-500 dark:text-slate-400">{t.projects?.emptyState || 'No projects found'}</p>
</div>
@@ -380,6 +380,7 @@ export const Projects: React.FC = () => {
/>
</div>
)}
</div>
{/* Modals */}
{canCreateProject && isCreateModalOpen && (

View File

@@ -11,6 +11,7 @@ import {
type WorkspaceRole,
} from '../lib/permissions';
import FilterBar from '../components/FilterBar';
import { ListPageSkeleton } from '../components/ListPageSkeleton';
import { Button } from '../components/ui/button';
import { Input } from '../components/ui/input';
import { Card, CardContent, CardTitle } from '../components/ui/card';
@@ -116,7 +117,8 @@ export default function Workspaces() {
};
return (
<div className="mx-auto max-w-7xl space-y-5 p-4 md:p-6">
<div className="mx-auto flex min-h-full max-w-7xl flex-col p-4 md:p-6">
<div className="flex flex-1 flex-col gap-5">
<div className="rounded-3xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-6">
<div className="flex items-start justify-between gap-4">
<div>
@@ -146,14 +148,10 @@ export default function Workspaces() {
</div>
{isLoading ? (
<div className="rounded-3xl border border-slate-200 bg-white p-12 shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div className="text-center text-slate-500 dark:text-slate-400">
<div className="animate-pulse">{t.workspace?.loading || 'Loading...'}</div>
</div>
</div>
<ListPageSkeleton variant="list" />
) : (
<div className="space-y-6">
<div className="flex flex-col gap-4">
<div className="flex flex-1 flex-col gap-6">
<div className="flex flex-1 flex-col gap-4">
{workspaces.map((workspace) => {
const canDeleteWorkspace = canWorkspace(workspace.my_role, WORKSPACE_DELETE);
const canEditWorkspace = canWorkspace(workspace.my_role, WORKSPACE_EDIT);
@@ -220,7 +218,7 @@ export default function Workspaces() {
})}
{workspaces.length === 0 && (
<div className="rounded-3xl border-2 border-dashed border-slate-200 bg-white py-16 shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div className="flex flex-1 rounded-3xl border-2 border-dashed border-slate-200 bg-white py-16 shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div className="flex flex-col items-center justify-center">
<p className="text-slate-500 dark:text-slate-400 font-medium">{t.workspace?.emptyState || 'No workspaces found'}</p>
</div>
@@ -238,6 +236,7 @@ export default function Workspaces() {
/>
</div>
)}
</div>
{deleteModal.workspace && (
<Modal