Anna Zhou commited on
Commit
c9da65d
·
1 Parent(s): 5bcace4

Restore working navigation buttons

Browse files
Files changed (1) hide show
  1. app/app.py +41 -94
app/app.py CHANGED
@@ -5,7 +5,6 @@ import ast
5
  import uuid
6
  import os
7
  from datetime import datetime, timezone
8
- from html import escape
9
  from pathlib import Path
10
  import streamlit as st
11
 
@@ -146,114 +145,62 @@ def _render_apa_source_links(raw_links, limit: int | None = None) -> None:
146
  st.markdown(f" - [PDF]({link['pdf_url']})")
147
 
148
  def _render_navigation(current_page: str, conversation_id: str) -> None:
149
- nav_items = [
150
- ("ask", "Ask"),
151
- ("previous_responses", "Previous Responses"),
152
- ("how_to_use", "How to Use"),
153
- ("new_case_requests", "New Case Study Requests"),
154
- ("case_studies", "Case Studies"),
155
- ("about", "About"),
156
- ]
157
- hidden_params = {
158
- "disclaimer_accepted": "true",
159
- "conversation_id": conversation_id,
160
- }
161
- hidden_inputs = "\n".join(
162
- f'<input type="hidden" name="{escape(key)}" value="{escape(value)}">'
163
- for key, value in hidden_params.items()
164
- )
165
- buttons = []
166
- for page, label in nav_items:
167
- classes = "rfr-nav-button is-active" if page == current_page else "rfr-nav-button"
168
- disabled = " disabled" if page == current_page else ""
169
- buttons.append(
170
- f'<button class="{classes}" type="submit" name="page" '
171
- f'value="{escape(page)}"{disabled}>{escape(label)}</button>'
172
- )
173
-
174
  st.markdown(
175
- f"""
176
  <style>
177
- .rfr-nav {{
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  display: flex;
179
  align-items: center;
180
- gap: 0.9rem 1.4rem;
181
- width: 100%;
182
- }}
183
- .rfr-nav-brand {{
184
  color: #17324d;
185
  font-weight: 700;
186
  font-size: 1.05rem;
187
  white-space: nowrap;
188
- margin-right: auto;
189
- }}
190
- .rfr-nav-form {{
191
- display: flex;
192
- flex-wrap: wrap;
193
- justify-content: flex-end;
194
- align-items: center;
195
- gap: 0.55rem 0.7rem;
196
- margin: 0;
197
- min-width: 0;
198
- }}
199
- .rfr-nav-button {{
200
- min-height: 2.25rem;
201
- padding: 0.45rem 0.8rem;
202
- border: 1px solid #d1d5db;
203
- border-radius: 6px;
204
- background: #ffffff;
205
- color: #2f3340;
206
- font: inherit;
207
- line-height: 1.15;
208
- white-space: nowrap;
209
- cursor: pointer;
210
- }}
211
- .rfr-nav-button:hover:not(:disabled) {{
212
- border-color: #aeb6c2;
213
- background: #f8fafc;
214
- color: #17324d;
215
- }}
216
- .rfr-nav-button.is-active {{
217
- background: #edf4f8;
218
- border-color: #d6e3ea;
219
- color: #17324d;
220
- font-weight: 600;
221
- cursor: default;
222
- }}
223
- .rfr-nav-rule {{
224
  border-bottom: 1px solid #dfe4ea;
225
  margin: 0.25rem 0 1.5rem 0;
226
- }}
227
- @media (max-width: 980px) {{
228
- .rfr-nav {{
229
- align-items: flex-start;
230
- flex-direction: column;
231
- gap: 0.65rem;
232
- }}
233
- .rfr-nav-brand {{
234
- margin-right: 0;
235
- }}
236
- .rfr-nav-form {{
237
- justify-content: flex-start;
238
- gap: 0.45rem 0.55rem;
239
- }}
240
- .rfr-nav-button {{
241
- padding: 0.42rem 0.7rem;
242
- }}
243
- }}
244
  </style>
245
- <nav class="rfr-nav" aria-label="Primary navigation">
246
- <div class="rfr-nav-brand">RFR Knowledge Platform</div>
247
- <form class="rfr-nav-form" method="get" target="_self">
248
- {hidden_inputs}
249
- {"".join(buttons)}
250
- </form>
251
- </nav>
252
- <div class="rfr-nav-rule"></div>
253
  """,
254
  unsafe_allow_html=True,
255
  )
256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
 
258
  def _case_sort_key(case_id: str) -> int:
259
  m = re.search(r"\d+", case_id or "")
 
5
  import uuid
6
  import os
7
  from datetime import datetime, timezone
 
8
  from pathlib import Path
9
  import streamlit as st
10
 
 
145
  st.markdown(f" - [PDF]({link['pdf_url']})")
146
 
147
  def _render_navigation(current_page: str, conversation_id: str) -> None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  st.markdown(
149
+ """
150
  <style>
151
+ div[data-testid="stHorizontalBlock"] {
152
+ column-gap: 0.65rem;
153
+ row-gap: 0.45rem;
154
+ }
155
+ div[data-testid="stHorizontalBlock"] .stButton > button {
156
+ min-height: 2.25rem;
157
+ width: 100%;
158
+ border-radius: 6px;
159
+ white-space: normal;
160
+ line-height: 1.15;
161
+ padding: 0.45rem 0.65rem;
162
+ }
163
+ .rfr-nav-brand {
164
+ min-height: 2.25rem;
165
  display: flex;
166
  align-items: center;
 
 
 
 
167
  color: #17324d;
168
  font-weight: 700;
169
  font-size: 1.05rem;
170
  white-space: nowrap;
171
+ }
172
+ .rfr-nav-rule {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  border-bottom: 1px solid #dfe4ea;
174
  margin: 0.25rem 0 1.5rem 0;
175
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  </style>
 
 
 
 
 
 
 
 
177
  """,
178
  unsafe_allow_html=True,
179
  )
180
 
181
+ def nav_button(col, page: str, label: str) -> None:
182
+ if col.button(
183
+ label,
184
+ key=f"nav_{page}",
185
+ type="primary" if page == current_page else "secondary",
186
+ disabled=page == current_page,
187
+ ):
188
+ _set_query_param("disclaimer_accepted", "true")
189
+ _set_query_param("conversation_id", conversation_id)
190
+ _set_query_param("page", page)
191
+ st.rerun()
192
+
193
+ cols = st.columns([3.4, 0.75, 1.55, 1.05, 1.95, 1.25, 0.8], gap="small")
194
+ cols[0].markdown('<div class="rfr-nav-brand">RFR Knowledge Platform</div>', unsafe_allow_html=True)
195
+ nav_button(cols[1], "ask", "Ask")
196
+ nav_button(cols[2], "previous_responses", "Previous Responses")
197
+ nav_button(cols[3], "how_to_use", "How to Use")
198
+ nav_button(cols[4], "new_case_requests", "New Case Study Requests")
199
+ nav_button(cols[5], "case_studies", "Case Studies")
200
+ nav_button(cols[6], "about", "About")
201
+
202
+ st.markdown('<div class="rfr-nav-rule"></div>', unsafe_allow_html=True)
203
+
204
 
205
  def _case_sort_key(case_id: str) -> int:
206
  m = re.search(r"\d+", case_id or "")