-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathDetails.js
More file actions
60 lines (49 loc) · 1.25 KB
/
Details.js
File metadata and controls
60 lines (49 loc) · 1.25 KB
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
50
51
52
53
54
55
56
57
58
59
60
import DocumentItem from "./DocumentItem.js";
import { createDocumentsListElement, findDocumentElement } from "../../utils/helper.js";
export default function Details({
$target,
initialState = {
id: null,
title: "",
documents: [],
},
onAddButtonClick,
}) {
this.$target = $target;
this.state = initialState;
this.init = () => {
this.render();
};
this.render = () => {
const { documents } = this.state;
this.$target.innerHTML = `
<details id="document-details">
<summary></summary>
<ul>${createDocumentsListElement(documents)}</ul>
</details>
`;
this.mounted();
};
this.mounted = () => {
const $rootDocument = this.$target.querySelector("summary");
const { id, title, documents } = this.state;
new DocumentItem({
$target: $rootDocument,
initialState: { id, title },
onAddButtonClick,
});
documents.forEach(({ id, title, documents }) => {
const $target = findDocumentElement(id);
new Details({
$target,
initialState: { title, id, documents },
onAddButtonClick,
});
});
};
this.setState = (nextState) => {
this.state = { ...this.state, ...nextState };
this.render();
};
this.init();
}