Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/api/fetch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// en lugar de fetch podr'ia llamarse product.service.js o categories.service.js

// Obtener todos los productos
export async function fetchData() {
try {
Expand Down Expand Up @@ -28,6 +30,7 @@ export async function fetchCategories() {
}
}

// esto deber'ia ir en otro archivo ya que sino se mezclan responsabilidades
// Mapper para estructurar datos que necesito
function mapperProducts(products) {
return products.map((product) => ({
Expand All @@ -38,6 +41,7 @@ function mapperProducts(products) {
}));
}

// esto deber'ia ir en otro archivo ya que sino se mezclan responsabilidades
// Mapper para categorías (API devuelve un objeto con más propiedades)
function mapperCategories(categories) {
return categories.map((category) => category.slug);
Expand Down
1 change: 1 addition & 0 deletions src/dom/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ const cartElement = document.querySelector("#cart-counter");
export function addToCart() {
cartCount++;
cartElement.textContent = cartCount;
// no dejemos console log
console.log('adding')
}
1 change: 1 addition & 0 deletions src/dom/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function renderCategory(categories, categorySelect) {
categories.forEach((category) => {
const option = document.createElement("option");
option.value = category;
// esto se podr'ia reemplazar con un text-transform: capitalize; en css
option.textContent = category.charAt(0).toUpperCase() + category.slice(1);
categorySelect.appendChild(option);
});
Expand Down
3 changes: 3 additions & 0 deletions src/utils/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { showMessage } from "../dom/message.js";

export function selectProduct(products, selectedCategory, container, imageUrl) {
container.innerHTML = "";
// no palabras magicas estos valores escritos manualmente deben estar en enum para evitar errores
// usemos un if cl'asico los ternarios son para condicionales simples usarlos para validaciones que tienen dentro cada evaluaci'on l'ogica compleja se vuelve tedioso de leer
const filteredProducts =
selectedCategory === "all" ? products : products.filter((product) => product.category === selectedCategory);

Expand Down Expand Up @@ -36,6 +38,7 @@ export function searchProduct(products, searchTerm, container, imageUrl) {

export function initializeFilters(productsData, contentCards, inputSelect, searchInput) {
let selectedCategory = "all";
// esto podr'ia estar en una constante global
const imageUrl = '/src/assets/error.png';

inputSelect.addEventListener("change", () => {
Expand Down