Hansimov commited on
Commit
c00fa7c
1 Parent(s): 5089a01

:gem: [Feature] Responsive and adaptive chat-history-sidebar

Browse files
Files changed (3) hide show
  1. components/inputs_binder.js +50 -1
  2. css/default.css +17 -1
  3. index.html +14 -12
components/inputs_binder.js CHANGED
@@ -9,6 +9,9 @@ export class InputsBinder {
9
  let chat_session_container_resize_binder =
10
  new ChatSessionContainerResizeBinder();
11
  chat_session_container_resize_binder.bind();
 
 
 
12
  }
13
  }
14
 
@@ -31,7 +34,7 @@ class ChatSessionContainerResizeBinder {
31
  constructor() { }
32
  bind() {
33
  this.resize();
34
- $(window).on("resize", this.resize);
35
  }
36
  resize() {
37
  let user_interaction_height = $("#user-interactions").outerHeight(true);
@@ -42,3 +45,49 @@ class ChatSessionContainerResizeBinder {
42
  );
43
  }
44
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  let chat_session_container_resize_binder =
10
  new ChatSessionContainerResizeBinder();
11
  chat_session_container_resize_binder.bind();
12
+ let chat_history_sidebar_resize_binder =
13
+ new ChatHistorySidebarResizeBinder();
14
+ chat_history_sidebar_resize_binder.bind();
15
  }
16
  }
17
 
 
34
  constructor() { }
35
  bind() {
36
  this.resize();
37
+ $(window).resize(this.resize.bind(this));
38
  }
39
  resize() {
40
  let user_interaction_height = $("#user-interactions").outerHeight(true);
 
45
  );
46
  }
47
  }
48
+
49
+ class ChatHistorySidebarResizeBinder {
50
+ constructor() {
51
+ this.USER_INTERACTIONS_MAX_WIDTH = 900;
52
+ this.SIDEBAR_GAP = 10;
53
+ this.SIDEBAR_MAX_WIDTH = 300;
54
+ this.SIDEBAR_MIN_WIDTH = 120;
55
+ }
56
+ bind() {
57
+ this.resize();
58
+ $(window).resize(this.resize.bind(this));
59
+ }
60
+ get_window_width() {
61
+ return $(window).width();
62
+ }
63
+ get_user_interations_width() {
64
+ return $("#user-interactions").width();
65
+ }
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 (!is_sidebar_show) {
75
+ sidebar.addClass("show");
76
+ }
77
+ sidebar.css("max-width", this.SIDEBAR_MAX_WIDTH + "px");
78
+ sidebar.css("min-width", this.SIDEBAR_MIN_WIDTH + "px");
79
+ } else if (this.get_side_margin() <= this.SIDEBAR_MIN_WIDTH) {
80
+ if (is_sidebar_show) {
81
+ sidebar.removeClass("show");
82
+ }
83
+ sidebar.css("max-width", this.SIDEBAR_MAX_WIDTH + "px");
84
+ sidebar.css("min-width", this.SIDEBAR_MIN_WIDTH + "px");
85
+ } else {
86
+ if (!is_sidebar_show) {
87
+ sidebar.addClass("show");
88
+ }
89
+ sidebar.css("max-width", this.get_side_margin());
90
+ sidebar.css("min-width", this.SIDEBAR_MIN_WIDTH + "px");
91
+ }
92
+ }
93
+ }
css/default.css CHANGED
@@ -4,11 +4,27 @@
4
  grid-gap: 10px;
5
  }
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  .available-model-item {
8
  display: flex;
9
  align-items: center;
10
  justify-content: center;
11
  }
 
12
  .available-model-item:hover {
13
  background-color: #dbedff;
14
  cursor: pointer;
@@ -111,4 +127,4 @@
111
 
112
  .icon-success {
113
  color: green;
114
- }
 
4
  grid-gap: 10px;
5
  }
6
 
7
+ .container {
8
+ max-width: 100vw;
9
+ }
10
+
11
+ #chat-history-sidebar {
12
+ background-color: rgba(255, 255, 255, 0.5);
13
+ }
14
+
15
+ /* Adaptation for mobile */
16
+ @media (min-width: 900px) {
17
+ .container {
18
+ max-width: 900px;
19
+ }
20
+ }
21
+
22
  .available-model-item {
23
  display: flex;
24
  align-items: center;
25
  justify-content: center;
26
  }
27
+
28
  .available-model-item:hover {
29
  background-color: #dbedff;
30
  cursor: pointer;
 
127
 
128
  .icon-success {
129
  color: green;
130
+ }
index.html CHANGED
@@ -20,19 +20,21 @@
20
  </head>
21
 
22
  <body>
23
-
24
  <div id="main-container">
25
- <div class="offcanvas offcanvas-start text-bg-dark" tabindex="-1" id="chat-history-sidebar">
 
26
  <div class="offcanvas-header">
27
- <h5 class="offcanvas-title" id="chat-history-label">Chat History</h5>
28
- <button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas">
 
 
29
  </button>
30
  </div>
31
  <div class="offcanvas-body">
32
- <form class="d-flex" role="search">
33
  <input class="form-control" type="search" placeholder="Search chats">
34
  <button class="btn btn-success" type="submit">Search</button>
35
- </form>
36
  <ul class="navbar-nav justify-content-end flex-grow-1">
37
  <li class="nav-item">
38
  <a class="nav-link active" href="#chat-session-example-1">Chat-Session-Example-1</a>
@@ -68,12 +70,6 @@
68
  </div>
69
  </div>
70
  <div class="mt-2 row no-gutters">
71
- <div class="col-auto pr-0">
72
- <button id="chat-history-sidebar-button" class="btn px-0" data-bs-toggle="offcanvas"
73
- data-bs-target="#chat-history-sidebar">
74
- <i class="fa fa-bars"></i>
75
- </button>
76
- </div>
77
  <div class="col-auto">
78
  <button id="show-endpoint-and-key-button" class="btn px-0">
79
  <i class="fa fa-key"></i>
@@ -95,6 +91,12 @@
95
  <i class="fa fa-angles-down"></i>
96
  </button>
97
  </div>
 
 
 
 
 
 
98
  </div>
99
  <div class="mt-2 row no-gutters">
100
  <div class="col-auto pr-0">
 
20
  </head>
21
 
22
  <body>
 
23
  <div id="main-container">
24
+ <div class="offcanvas offcanvas-start" data-bs-scroll="true" data-bs-backdrop="false" tabindex="-1"
25
+ id="chat-history-sidebar" aria-labelledby="chat-history-sidebar-label">
26
  <div class="offcanvas-header">
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" data-bs-dismiss="offcanvas">
31
  </button>
32
  </div>
33
  <div class="offcanvas-body">
34
+ <!-- <form class="d-flex" role="search" id="chat-history-search-form">
35
  <input class="form-control" type="search" placeholder="Search chats">
36
  <button class="btn btn-success" type="submit">Search</button>
37
+ </form> -->
38
  <ul class="navbar-nav justify-content-end flex-grow-1">
39
  <li class="nav-item">
40
  <a class="nav-link active" href="#chat-session-example-1">Chat-Session-Example-1</a>
 
70
  </div>
71
  </div>
72
  <div class="mt-2 row no-gutters">
 
 
 
 
 
 
73
  <div class="col-auto">
74
  <button id="show-endpoint-and-key-button" class="btn px-0">
75
  <i class="fa fa-key"></i>
 
91
  <i class="fa fa-angles-down"></i>
92
  </button>
93
  </div>
94
+ <div class="col-auto">
95
+ <button id="chat-history-sidebar-toggle-button" class="btn px-0" data-bs-toggle="offcanvas"
96
+ data-bs-target="#chat-history-sidebar">
97
+ <i class="fa fa-bars"></i>
98
+ </button>
99
+ </div>
100
  </div>
101
  <div class="mt-2 row no-gutters">
102
  <div class="col-auto pr-0">