Skip to content

Commit

Permalink
fetch user categories from back
Browse files Browse the repository at this point in the history
  • Loading branch information
oybek committed Oct 14, 2023
1 parent d97cdf7 commit efd0333
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
21 changes: 21 additions & 0 deletions spendbook/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
</head>
<script>
$(document).ready(function () {
const searchParams = new URLSearchParams(window.location.search);
const chatId = searchParams.get("chatId");
const ip = "82.146.46.151"
const port = "5555"
fetch(`http://${ip}:${port}/categories?chatId=${chatId}`)
.then((response) => response.json())
.then((userCategories) => {
const categoriesFiltered = categories.filter(
(c) => !userCategories.includes(c)
);
const finalCategories = userCategories.concat(categoriesFiltered);
$.each(finalCategories, function (key, str) {
$("#category").append(`<option value="${str}">${str}</option>`);
});
})
.catch((error) =>
$.each(categories, function (key, str) {
$("#category").append(`<option value="${str}">${str}</option>`);
})
);

function collectData() {
var category = $("#category").val();
if (category === categories[categories.length-1]) {
Expand Down
21 changes: 4 additions & 17 deletions spendbook/js/dropDowns.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
const categories = [
"Супермаркеты",
"Транспорт",
"Рестораны",
"Подписки",
"Аптеки",
"ЖКХ",
"Аренда квартиры",
"Развлечения",
"Хобби",
"Красота",
"Кредиты",
"Медицина",
"Образование",
"Одежда",
"Подарки",
"Путешествия",
"Ремонт",
"Техника",
"Подписки",
"Развлечения",
"Супермаркеты",
"Транспорт",

// Должно быть последним
"Ввести свою категорию",
Expand All @@ -38,9 +28,6 @@ const months = [
];

$(document).ready(function () {
$.each(categories, function (key, str) {
$("#category").append(`<option value="${str}">${str}</option>`);
});
$.each(months, function (key, obj) {
$("#month").append(`<option value="${obj.value}">${obj.text}</option>`);
});
Expand Down

0 comments on commit efd0333

Please sign in to comment.