Skip to content

Commit

Permalink
fix(casos-activos): use search url params to set default page state
Browse files Browse the repository at this point in the history
  • Loading branch information
Hashs7 committed Nov 6, 2024
1 parent a9e1352 commit 618fc90
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/app/casos-activos/puntos/page.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
'use client';

import { useState, useEffect } from 'react';
import { MapPin, Phone, Calendar, User, HeartHandshake, Users, Truck, Search, Package, MapPinIcon } from 'lucide-react';
import { useEffect, useState } from 'react';
import { HeartHandshake } from 'lucide-react';
import { supabase } from '@/lib/supabase/client';
import { tiposAyudaAcepta } from '@/helpers/constants';
import Pagination from '@/components/Pagination';
import { useRouter, useSearchParams } from 'next/navigation';
import PickupPoint from '@/components/PickupPoint';
import { useTowns } from '@/context/TownProvider';

export default function Puntos() {
const towns = useTowns();
const searchParams = useSearchParams();
const router = useRouter();

const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

const [data, setData] = useState([]);
const [currentPage, setCurrentPage] = useState(1);
const [currentPage, setCurrentPage] = useState(parseInt(searchParams.get('page')) || 1);
const [currentCount, setCurrentCount] = useState(0);
const [cityOptions, setCityOptions] = useState([]);

Expand Down Expand Up @@ -56,20 +54,17 @@ export default function Puntos() {
try {
setError(null);

// Comenzamos la consulta
const query = supabase.from('distinct_collection_cities').select('city');

// Ejecutar la consulta
const { data, count, error } = await query;
const { data, count, error } = await supabase.from('distinct_collection_cities').select('city');
if (error) {
console.log('Error fetching ciudades:', error);
setCityOptions([]);
} else {
const trimmedCities = data.map((punto) => punto.city.trim());
const cities = [...new Set(trimmedCities)].sort();
setCityOptions(cities || []);
setCurrentCount(count);
return;
}

const trimmedCities = data.map((punto) => punto.city?.trim());
const cities = [...new Set(trimmedCities)].sort();
setCityOptions(cities || []);
setCurrentCount(count);
} catch (err) {
console.log('Error general:', err);
setError('Error de conexión.');
Expand Down

0 comments on commit 618fc90

Please sign in to comment.