feat: persist client sorting preference across page reloads using localStorage
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m28s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m28s
This commit is contained in:
@@ -14,17 +14,25 @@ const Clients = () => {
|
|||||||
ordersData: OrderData[]
|
ordersData: OrderData[]
|
||||||
}>();
|
}>();
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
const [sortBy, setSortBy] = useState<SortOption>('recent');
|
const [sortBy, setSortBy] = useState<SortOption>(() => {
|
||||||
|
const saved = localStorage.getItem('nexstar_client_sort');
|
||||||
|
return (saved as SortOption) || 'recent';
|
||||||
|
});
|
||||||
|
|
||||||
// Pagination state
|
// Pagination state
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [itemsPerPage, setItemsPerPage] = useState(10);
|
const [itemsPerPage, setItemsPerPage] = useState(10);
|
||||||
|
|
||||||
// Reset to first page when search, sort, or date changes
|
// Reset to first page when search or sort changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCurrentPage(1);
|
setCurrentPage(1);
|
||||||
}, [searchTerm, sortBy, dateRange]);
|
}, [searchTerm, sortBy, dateRange]);
|
||||||
|
|
||||||
|
// Persist sort option
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem('nexstar_client_sort', sortBy);
|
||||||
|
}, [sortBy]);
|
||||||
|
|
||||||
const clientsData = useMemo(() => {
|
const clientsData = useMemo(() => {
|
||||||
const orders = ordersData.filter(order => {
|
const orders = ordersData.filter(order => {
|
||||||
const orderDate = parseOrderDate(order.Data_Pedido);
|
const orderDate = parseOrderDate(order.Data_Pedido);
|
||||||
|
|||||||
Reference in New Issue
Block a user