alteração do shopcard

This commit is contained in:
2026-02-26 17:11:49 +00:00
parent b1099f04bc
commit d948273c16
2 changed files with 14 additions and 14 deletions

View File

@@ -21,13 +21,13 @@ export const ShopCard = ({ shop }: { shop: BarberShop }) => (
</span>
<span className="flex items-center gap-1 text-indigo-600 font-semibold">
<Star size={14} className="fill-indigo-500 text-indigo-500" />
{shop.rating.toFixed(1)}
{(shop.rating || 0).toFixed(1)}
</span>
</div>
<div className="flex items-center gap-3 text-xs text-slate-500 pt-1">
<span>{shop.services.length} serviços</span>
<span>{(shop.services || []).length} serviços</span>
<span></span>
<span>{shop.barbers.length} barbeiros</span>
<span>{(shop.barbers || []).length} barbeiros</span>
</div>
</div>
</div>

View File

@@ -33,30 +33,30 @@ export default function Explore() {
// Regra 2: Restrições de Chip
const passesFilter = (shop: (typeof shops)[number]) => {
if (filter === 'top') return shop.rating >= 4.7;
if (filter === 'produtos') return shop.products.length > 0;
if (filter === 'barbeiros') return shop.barbers.length >= 2;
if (filter === 'servicos') return shop.services.length >= 2;
if (filter === 'top') return (shop.rating || 0) >= 4.7;
if (filter === 'produtos') return (shop.products || []).length > 0;
if (filter === 'barbeiros') return (shop.barbers || []).length >= 2;
if (filter === 'servicos') return (shop.services || []).length >= 2;
return true;
};
// Aplicação condicional com Sort
const sorted = [...shops]
.filter((shop) => matchesQuery(shop.name, shop.address))
.filter((shop) => matchesQuery(shop.name, shop.address || ''))
.filter(passesFilter)
.sort((a, b) => {
if (sortBy === 'avaliacao') return b.rating - a.rating;
if (sortBy === 'servicos') return b.services.length - a.services.length;
if (sortBy === 'avaliacao') return (b.rating || 0) - (a.rating || 0);
if (sortBy === 'servicos') return (b.services || []).length - (a.services || []).length;
if (sortBy === 'preco') {
// Extrai o preço mínimo nos serviços oferecidos e compara
const aMin = Math.min(...a.services.map((s) => s.price));
const bMin = Math.min(...b.services.map((s) => s.price));
const aMin = (a.services || []).length ? Math.min(...a.services.map((s) => s.price)) : Infinity;
const bMin = (b.services || []).length ? Math.min(...b.services.map((s) => s.price)) : Infinity;
return aMin - bMin;
}
// Critério por defeito ou quebra de empate: Avaliação descendente
if (b.rating !== a.rating) return b.rating - a.rating;
return b.services.length - a.services.length;
if (b.rating !== a.rating) return (b.rating || 0) - (a.rating || 0);
return (b.services || []).length - (a.services || []).length;
});
return sorted;