2024-01-12 11:45:16 +04:00

33 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getAllItemTypes, getAllLines } from "../lines-rest-api.js";
import { indexPageCatalog } from "../lines-ui.js";
import { getProductItem } from "./getProductItem.js";
// Проверка, есть ли вообще на странице каталога место,
// где будут отображаться карточки
if (indexPageCatalog) {
drawCatalog();
}
async function drawCatalog() {
try {
// Получаю все типы
const itemTypes = await getAllItemTypes();
// Получаю все товары
const lines = await getAllLines();
// Бегу по товарам через for
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
// Получаею его тип
const itemType = itemTypes.find(it => it.id === +line.itemsId);
// console.log(itemType);
// добавление в каталог карточек товара через функцию
indexPageCatalog.innerHTML += getProductItem(line.image, itemType.name, line.price);
}
} catch (err) {
console.log(err);
}
}