:recycle: [Refactor] MessagerViewer: Separate elements creation, and prettify styles
Browse files
apps/llm_mixer/js/messager.js
CHANGED
@@ -5,18 +5,32 @@ export class MessagerViewer {
|
|
5 |
}
|
6 |
create_elements() {
|
7 |
this.container = $("<div>").addClass("row no-gutters message-viewer");
|
8 |
-
this.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
if (this.message.role === "user") {
|
10 |
this.role_displayer.append("You");
|
11 |
} else {
|
12 |
this.role_displayer.append(this.message.model);
|
13 |
}
|
14 |
-
|
|
|
15 |
this.content_displayer = $("<div>")
|
16 |
-
.addClass(
|
17 |
-
|
18 |
-
)
|
19 |
.append(this.message.content);
|
|
|
|
|
20 |
this.button = $("<button>").addClass(
|
21 |
"col-auto btn btn-primary regenerate-button"
|
22 |
);
|
@@ -25,10 +39,6 @@ export class MessagerViewer {
|
|
25 |
} else {
|
26 |
this.button.append("Regenerate");
|
27 |
}
|
28 |
-
this.container
|
29 |
-
.append(this.role_displayer)
|
30 |
-
.append(this.content_displayer)
|
31 |
-
.append(this.button);
|
32 |
}
|
33 |
}
|
34 |
|
|
|
5 |
}
|
6 |
create_elements() {
|
7 |
this.container = $("<div>").addClass("row no-gutters message-viewer");
|
8 |
+
this.create_role_displayer();
|
9 |
+
this.create_content_displayer();
|
10 |
+
this.create_button();
|
11 |
+
this.container
|
12 |
+
.append(this.role_displayer)
|
13 |
+
.append(this.content_displayer)
|
14 |
+
.append(this.button);
|
15 |
+
}
|
16 |
+
create_role_displayer() {
|
17 |
+
this.role_displayer = $("<div>")
|
18 |
+
.addClass("col-auto mb-2 p-2")
|
19 |
+
.addClass("role-displayer");
|
20 |
if (this.message.role === "user") {
|
21 |
this.role_displayer.append("You");
|
22 |
} else {
|
23 |
this.role_displayer.append(this.message.model);
|
24 |
}
|
25 |
+
}
|
26 |
+
create_content_displayer() {
|
27 |
this.content_displayer = $("<div>")
|
28 |
+
.addClass("col mb-2 p-2")
|
29 |
+
.addClass("content-displayer")
|
30 |
+
.addClass(`chat-${this.message.role}`)
|
31 |
.append(this.message.content);
|
32 |
+
}
|
33 |
+
create_button() {
|
34 |
this.button = $("<button>").addClass(
|
35 |
"col-auto btn btn-primary regenerate-button"
|
36 |
);
|
|
|
39 |
} else {
|
40 |
this.button.append("Regenerate");
|
41 |
}
|
|
|
|
|
|
|
|
|
42 |
}
|
43 |
}
|
44 |
|