:zap: [Enhance] Better button controls of sidebar, and memorize toggle preferences
Browse files- components/buttons_binder.js +44 -8
- components/inputs_binder.js +6 -3
- index.html +2 -3
components/buttons_binder.js
CHANGED
@@ -12,7 +12,7 @@ import { setup_available_models_on_select } from "./llm_models_loader.js";
|
|
12 |
import { screen_scroller } from "../storage/states.js";
|
13 |
|
14 |
export class ButtonsBinder {
|
15 |
-
constructor() {}
|
16 |
bind() {
|
17 |
let send_user_input_binder = new SendUserInputButtonBinder();
|
18 |
send_user_input_binder.bind();
|
@@ -28,6 +28,9 @@ export class ButtonsBinder {
|
|
28 |
scroll_to_bottom_binder.bind();
|
29 |
let screenshot_button_binder = new ScreenshotButtonBinder();
|
30 |
screenshot_button_binder.bind();
|
|
|
|
|
|
|
31 |
let available_models_select_binder = new AvailableModelsSelectBinder();
|
32 |
available_models_select_binder.bind();
|
33 |
}
|
@@ -110,7 +113,7 @@ class SendUserInputButtonBinder {
|
|
110 |
}
|
111 |
|
112 |
class NewChatButtonBinder {
|
113 |
-
constructor() {}
|
114 |
bind() {
|
115 |
const button = $("#new-chat-session");
|
116 |
button.attr("status", "new").attr("title", "New Chat");
|
@@ -121,7 +124,7 @@ class NewChatButtonBinder {
|
|
121 |
}
|
122 |
|
123 |
class OpenaiEndpointButtonBinder {
|
124 |
-
constructor() {}
|
125 |
bind() {
|
126 |
const button = $("#openai-endpoint-button");
|
127 |
button.attr("title", "Submit Endpoint");
|
@@ -143,7 +146,7 @@ class OpenaiEndpointButtonBinder {
|
|
143 |
}
|
144 |
|
145 |
class OpenaiAPIKeyButtonBinder {
|
146 |
-
constructor() {}
|
147 |
bind() {
|
148 |
const button = $("#openai-api-key-button");
|
149 |
button.attr("title", "Submit API Key");
|
@@ -160,7 +163,7 @@ class OpenaiAPIKeyButtonBinder {
|
|
160 |
}
|
161 |
|
162 |
class ShowEndpointAndKeyButtonBinder {
|
163 |
-
constructor() {}
|
164 |
bind() {
|
165 |
const button = $("#show-endpoint-and-key-button");
|
166 |
button.attr("title", "Show endpoint and api key");
|
@@ -185,7 +188,7 @@ class ShowEndpointAndKeyButtonBinder {
|
|
185 |
}
|
186 |
|
187 |
class ScrollToBottomButtonBinder {
|
188 |
-
constructor() {}
|
189 |
bind() {
|
190 |
const button = $("#scroll-to-bottom-button");
|
191 |
button.attr("title", "Scroll to bottom");
|
@@ -197,7 +200,7 @@ class ScrollToBottomButtonBinder {
|
|
197 |
}
|
198 |
|
199 |
class ScreenshotButtonBinder {
|
200 |
-
constructor() {}
|
201 |
bind() {
|
202 |
const button = $("#screenshot-button");
|
203 |
button.attr("title", "Take screenshot for whole chat");
|
@@ -231,8 +234,41 @@ class ScreenshotButtonBinder {
|
|
231 |
}
|
232 |
}
|
233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
class AvailableModelsSelectBinder {
|
235 |
-
constructor() {}
|
236 |
bind() {
|
237 |
const select = $("#available-models-select");
|
238 |
select.change(() => {
|
|
|
12 |
import { screen_scroller } from "../storage/states.js";
|
13 |
|
14 |
export class ButtonsBinder {
|
15 |
+
constructor() { }
|
16 |
bind() {
|
17 |
let send_user_input_binder = new SendUserInputButtonBinder();
|
18 |
send_user_input_binder.bind();
|
|
|
28 |
scroll_to_bottom_binder.bind();
|
29 |
let screenshot_button_binder = new ScreenshotButtonBinder();
|
30 |
screenshot_button_binder.bind();
|
31 |
+
let chat_history_sidebar_toggle_button_binder =
|
32 |
+
new ChatHistorySidebarToggleButtonBinder();
|
33 |
+
chat_history_sidebar_toggle_button_binder.bind();
|
34 |
let available_models_select_binder = new AvailableModelsSelectBinder();
|
35 |
available_models_select_binder.bind();
|
36 |
}
|
|
|
113 |
}
|
114 |
|
115 |
class NewChatButtonBinder {
|
116 |
+
constructor() { }
|
117 |
bind() {
|
118 |
const button = $("#new-chat-session");
|
119 |
button.attr("status", "new").attr("title", "New Chat");
|
|
|
124 |
}
|
125 |
|
126 |
class OpenaiEndpointButtonBinder {
|
127 |
+
constructor() { }
|
128 |
bind() {
|
129 |
const button = $("#openai-endpoint-button");
|
130 |
button.attr("title", "Submit Endpoint");
|
|
|
146 |
}
|
147 |
|
148 |
class OpenaiAPIKeyButtonBinder {
|
149 |
+
constructor() { }
|
150 |
bind() {
|
151 |
const button = $("#openai-api-key-button");
|
152 |
button.attr("title", "Submit API Key");
|
|
|
163 |
}
|
164 |
|
165 |
class ShowEndpointAndKeyButtonBinder {
|
166 |
+
constructor() { }
|
167 |
bind() {
|
168 |
const button = $("#show-endpoint-and-key-button");
|
169 |
button.attr("title", "Show endpoint and api key");
|
|
|
188 |
}
|
189 |
|
190 |
class ScrollToBottomButtonBinder {
|
191 |
+
constructor() { }
|
192 |
bind() {
|
193 |
const button = $("#scroll-to-bottom-button");
|
194 |
button.attr("title", "Scroll to bottom");
|
|
|
200 |
}
|
201 |
|
202 |
class ScreenshotButtonBinder {
|
203 |
+
constructor() { }
|
204 |
bind() {
|
205 |
const button = $("#screenshot-button");
|
206 |
button.attr("title", "Take screenshot for whole chat");
|
|
|
234 |
}
|
235 |
}
|
236 |
|
237 |
+
class ChatHistorySidebarToggleButtonBinder {
|
238 |
+
constructor() { }
|
239 |
+
get_show_sidebar_storage() {
|
240 |
+
return localStorage.getItem("show_chat_history_sidebar");
|
241 |
+
}
|
242 |
+
bind() {
|
243 |
+
const sidebar = $("#chat-history-sidebar");
|
244 |
+
|
245 |
+
// this line is not to check value as false,
|
246 |
+
// but to check item not existed in localStorage
|
247 |
+
if (!this.get_show_sidebar_storage()) {
|
248 |
+
localStorage.setItem("show_chat_history_sidebar", "true");
|
249 |
+
}
|
250 |
+
if (this.get_show_sidebar_storage() === "true") {
|
251 |
+
sidebar.addClass("show");
|
252 |
+
}
|
253 |
+
|
254 |
+
const toggle_button = $("#chat-history-sidebar-toggle-button");
|
255 |
+
toggle_button.click(() => {
|
256 |
+
sidebar.toggleClass("show");
|
257 |
+
localStorage.setItem(
|
258 |
+
"show_chat_history_sidebar", sidebar.hasClass("show").toString()
|
259 |
+
);
|
260 |
+
});
|
261 |
+
|
262 |
+
const close_button = $("#chat-history-sidebar-close-button");
|
263 |
+
close_button.click(() => {
|
264 |
+
sidebar.removeClass("show");
|
265 |
+
localStorage.setItem("show_chat_history_sidebar", "false");
|
266 |
+
});
|
267 |
+
}
|
268 |
+
}
|
269 |
+
|
270 |
class AvailableModelsSelectBinder {
|
271 |
+
constructor() { }
|
272 |
bind() {
|
273 |
const select = $("#available-models-select");
|
274 |
select.change(() => {
|
components/inputs_binder.js
CHANGED
@@ -66,12 +66,15 @@ class ChatHistorySidebarResizeBinder {
|
|
66 |
get_side_margin() {
|
67 |
return (this.get_window_width() - this.get_user_interations_width()) / 2 - this.SIDEBAR_GAP;
|
68 |
}
|
|
|
|
|
|
|
|
|
69 |
resize() {
|
70 |
let sidebar = $("#chat-history-sidebar");
|
71 |
-
let user_interactions = $("#user-interactions");
|
72 |
let is_sidebar_show = sidebar[0].classList.contains("show");
|
73 |
if (this.get_side_margin() >= this.SIDEBAR_MAX_WIDTH) {
|
74 |
-
if (
|
75 |
sidebar.addClass("show");
|
76 |
}
|
77 |
sidebar.css("max-width", this.SIDEBAR_MAX_WIDTH + "px");
|
@@ -83,7 +86,7 @@ class ChatHistorySidebarResizeBinder {
|
|
83 |
sidebar.css("max-width", this.SIDEBAR_MAX_WIDTH + "px");
|
84 |
sidebar.css("min-width", this.SIDEBAR_MIN_WIDTH + "px");
|
85 |
} else {
|
86 |
-
if (
|
87 |
sidebar.addClass("show");
|
88 |
}
|
89 |
sidebar.css("max-width", this.get_side_margin());
|
|
|
66 |
get_side_margin() {
|
67 |
return (this.get_window_width() - this.get_user_interations_width()) / 2 - this.SIDEBAR_GAP;
|
68 |
}
|
69 |
+
need_to_show() {
|
70 |
+
let sidebar = $("#chat-history-sidebar");
|
71 |
+
return (!sidebar.hasClass("show")) && localStorage.getItem("show_chat_history_sidebar") === "true";
|
72 |
+
}
|
73 |
resize() {
|
74 |
let sidebar = $("#chat-history-sidebar");
|
|
|
75 |
let is_sidebar_show = sidebar[0].classList.contains("show");
|
76 |
if (this.get_side_margin() >= this.SIDEBAR_MAX_WIDTH) {
|
77 |
+
if (this.need_to_show()) {
|
78 |
sidebar.addClass("show");
|
79 |
}
|
80 |
sidebar.css("max-width", this.SIDEBAR_MAX_WIDTH + "px");
|
|
|
86 |
sidebar.css("max-width", this.SIDEBAR_MAX_WIDTH + "px");
|
87 |
sidebar.css("min-width", this.SIDEBAR_MIN_WIDTH + "px");
|
88 |
} else {
|
89 |
+
if (this.need_to_show()) {
|
90 |
sidebar.addClass("show");
|
91 |
}
|
92 |
sidebar.css("max-width", this.get_side_margin());
|
index.html
CHANGED
@@ -27,7 +27,7 @@
|
|
27 |
<h5 class="offcanvas-title" id="chat-history-label">
|
28 |
<a style="text-decoration: none; color:inherit;" href="#">Chat History</a>
|
29 |
</h5>
|
30 |
-
<button id="chat-history-close-button" class="btn-close"
|
31 |
</button>
|
32 |
</div>
|
33 |
<div class="offcanvas-body">
|
@@ -92,8 +92,7 @@
|
|
92 |
</button>
|
93 |
</div>
|
94 |
<div class="col-auto">
|
95 |
-
<button id="chat-history-sidebar-toggle-button" class="btn px-0"
|
96 |
-
data-bs-target="#chat-history-sidebar">
|
97 |
<i class="fa fa-bars"></i>
|
98 |
</button>
|
99 |
</div>
|
|
|
27 |
<h5 class="offcanvas-title" id="chat-history-label">
|
28 |
<a style="text-decoration: none; color:inherit;" href="#">Chat History</a>
|
29 |
</h5>
|
30 |
+
<button id="chat-history-sidebar-close-button" class="btn-close">
|
31 |
</button>
|
32 |
</div>
|
33 |
<div class="offcanvas-body">
|
|
|
92 |
</button>
|
93 |
</div>
|
94 |
<div class="col-auto">
|
95 |
+
<button id="chat-history-sidebar-toggle-button" class="btn px-0">
|
|
|
96 |
<i class="fa fa-bars"></i>
|
97 |
</button>
|
98 |
</div>
|