-
Notifications
You must be signed in to change notification settings - Fork 0
/
daily-account-list.js
49 lines (40 loc) · 1.71 KB
/
daily-account-list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { getAccountDaily } from "./server/api.js";
Array.prototype.isEmpty = function () {
return this.length === 0;
};
const updateAccountListTitle = (selectedDate) =>
(document.querySelector("#footer-title").innerHTML = `${selectedDate.getFullYear()}년 ${
selectedDate.getMonth() + 1
}월 ${selectedDate.getDate()}일의 내역입니다.`);
const getClassByAccountType = (accountType) =>
accountType === "plus" ? "list-text-plus" : "list-text-minus";
const getStringByAccountType = (accountType) => (accountType === "plus" ? "입금" : "출금");
const getHtmlForList = (account) => `
<li>
<div class="${getClassByAccountType(account.type)}">${getStringByAccountType(account.type)} ${
account.money
}원</div>
<div class="list-text-description">${account.description}</div>
</li>
`;
const updateAccountListContent = (accountsOfSelectedDate) =>
(document.querySelector("#footer-list").innerHTML = accountsOfSelectedDate
.map(getHtmlForList)
.join(""));
const getSelectedDateForGet = (selectedDate) =>
new Date(+selectedDate + 3240 * 10000).toISOString().substring(0, 10);
const showAccountList = () => (document.querySelector("footer").style.visibility = "visible");
const hideAccountList = () => (document.querySelector("footer").style.visibility = "hidden");
const updateAccountList = async (selectedDate) => {
updateAccountListTitle(selectedDate);
const { result: accountsOfSelectedDate } = await getAccountDaily(
getSelectedDateForGet(selectedDate)
);
if (accountsOfSelectedDate.isEmpty()) {
hideAccountList();
} else {
updateAccountListContent(accountsOfSelectedDate);
showAccountList();
}
};
export { updateAccountList };