Skip to content

Commit a1fecfa

Browse files
authored
feat: add toggle for conversation control sidebar (#546) #none
1 parent ab6b3fc commit a1fecfa

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

libs/ktem/ktem/assets/css/main.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ button.selected {
9797
#chat-info-panel {
9898
max-height: var(--main-area-height) !important;
9999
overflow: auto !important;
100-
transition: all 0.5s;
100+
transition: all 0.4s;
101101
}
102102

103103
body.dark #chat-info-panel figure>img{
@@ -109,12 +109,12 @@ body.dark #chat-info-panel figure>img{
109109
flex-wrap: unset;
110110
overflow-y: scroll !important;
111111
position: sticky;
112-
min-width: min(305px, 100%) !important;
113112
column-gap: 2px !important;
114113
scrollbar-width: none;
115114
/* Firefox */
116115
-ms-overflow-style: none;
117116
/* Internet Explorer 10+ */
117+
transition: all 0.3s;
118118
}
119119

120120
#conv-settings-panel::-webkit-scrollbar {
@@ -204,6 +204,13 @@ mark {
204204
right: 15px;
205205
}
206206

207+
#chat-expand-button {
208+
position: absolute;
209+
top: 6px;
210+
right: -10px;
211+
z-index: 10;
212+
}
213+
207214
#use-mindmap-checkbox {
208215
position: absolute;
209216
width: 110px;
Lines changed: 1 addition & 0 deletions
Loading

libs/ktem/ktem/assets/js/main.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ function run() {
1616
let chat_info_panel = document.getElementById("info-expand");
1717
chat_info_panel.insertBefore(info_expand_button, chat_info_panel.childNodes[2]);
1818

19+
// move toggle-side-bar button
20+
let chat_expand_button = document.getElementById("chat-expand-button");
21+
let chat_column = document.getElementById("main-chat-bot");
22+
let conv_column = document.getElementById("conv-settings-panel");
23+
24+
let default_conv_column_min_width = "min(300px, 100%)";
25+
conv_column.style.minWidth = default_conv_column_min_width
26+
27+
globalThis.toggleChatColumn = (() => {
28+
/* get flex-grow value of chat_column */
29+
let flex_grow = conv_column.style.flexGrow;
30+
console.log("chat col", flex_grow);
31+
if (flex_grow == '0') {
32+
conv_column.style.flexGrow = '1';
33+
conv_column.style.minWidth = default_conv_column_min_width;
34+
} else {
35+
conv_column.style.flexGrow = '0';
36+
conv_column.style.minWidth = "0px";
37+
}
38+
});
39+
40+
chat_column.insertBefore(chat_expand_button, chat_column.firstChild);
41+
1942
// move use mind-map checkbox
2043
let mindmap_checkbox = document.getElementById("use-mindmap-checkbox");
2144
let chat_setting_panel = document.getElementById("chat-settings-expand");

libs/ktem/ktem/pages/chat/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ktem.app import BasePage
99
from ktem.components import reasonings
1010
from ktem.db.models import Conversation, engine
11-
from ktem.index.file.ui import File, chat_input_focus_js
11+
from ktem.index.file.ui import File
1212
from ktem.reasoning.prompt_optimization.suggest_conversation_name import (
1313
SuggestConvNamePipeline,
1414
)
@@ -31,6 +31,12 @@
3131
DEFAULT_SETTING = "(default)"
3232
INFO_PANEL_SCALES = {True: 8, False: 4}
3333

34+
chat_input_focus_js = """
35+
function() {
36+
let chatInput = document.querySelector("#chat-input textarea");
37+
chatInput.focus();
38+
}
39+
"""
3440

3541
pdfview_js = """
3642
function() {
@@ -403,6 +409,9 @@ def on_register_events(self):
403409
inputs=self._info_panel_expanded,
404410
outputs=[self.info_column, self._info_panel_expanded],
405411
)
412+
self.chat_control.btn_chat_expand.click(
413+
fn=None, inputs=None, js="function() {toggleChatColumn();}"
414+
)
406415

407416
self.chat_panel.chatbot.like(
408417
fn=self.is_liked,

libs/ktem/ktem/pages/chat/control.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,17 @@ def on_building_ui(self):
4848
elem_classes=["no-background", "body-text-color"],
4949
elem_id="toggle-dark-button",
5050
)
51+
self.btn_chat_expand = gr.Button(
52+
value="",
53+
icon=f"{ASSETS_DIR}/expand.svg",
54+
scale=1,
55+
size="sm",
56+
elem_classes=["no-background", "body-text-color"],
57+
elem_id="chat-expand-button",
58+
)
5159
self.btn_info_expand = gr.Button(
5260
value="",
53-
icon=f"{ASSETS_DIR}/sidebar.svg",
61+
icon=f"{ASSETS_DIR}/expand.svg",
5462
min_width=2,
5563
scale=1,
5664
size="sm",

0 commit comments

Comments
 (0)