Anna Zhou commited on
Commit
b1b5dab
·
1 Parent(s): 423e236

Use Streamlit-native navigation tabs

Browse files
Files changed (1) hide show
  1. app/app.py +27 -76
app/app.py CHANGED
@@ -3,9 +3,7 @@ import json
3
  import re
4
  import ast
5
  import uuid
6
- from html import escape
7
  from pathlib import Path
8
- from urllib.parse import urlencode
9
  import streamlit as st
10
 
11
  sys.path.insert(0, str(Path(__file__).parent.parent))
@@ -138,16 +136,6 @@ def _render_apa_source_links(raw_links, limit: int | None = None) -> None:
138
  if link.get("pdf_url"):
139
  st.markdown(f" - [PDF]({link['pdf_url']})")
140
 
141
-
142
- def _nav_url(page: str, conversation_id: str) -> str:
143
- params = {
144
- "disclaimer_accepted": "true",
145
- "conversation_id": conversation_id,
146
- "page": page,
147
- }
148
- return "?" + urlencode(params)
149
-
150
-
151
  def _render_navigation(current_page: str, conversation_id: str) -> None:
152
  nav_items = [
153
  ("ask", "Ask"),
@@ -155,82 +143,45 @@ def _render_navigation(current_page: str, conversation_id: str) -> None:
155
  ("previous_responses", "Previous Responses"),
156
  ("about", "About"),
157
  ]
158
- nav_links = "\n".join(
159
- (
160
- f'<a class="{"is-active" if page == current_page else ""}" '
161
- f'href="{escape(_nav_url(page, conversation_id))}">{label}</a>'
162
- )
163
- for page, label in nav_items
164
- )
165
- nav_html = """
166
  <style>
167
- .rfr-nav {
168
- position: sticky;
169
- top: 0;
170
- z-index: 999;
171
- display: flex;
172
- align-items: center;
173
- justify-content: space-between;
174
- gap: 1rem;
175
- margin: -0.75rem 0 1.5rem 0;
176
- padding: 0.75rem 0;
177
- background: rgba(255, 255, 255, 0.96);
178
- border-bottom: 1px solid #dfe4ea;
179
- backdrop-filter: blur(8px);
180
- }
181
- .rfr-nav__brand {
182
- font-weight: 700;
183
- color: #17324d;
184
  white-space: nowrap;
185
  }
186
- .rfr-nav__links {
 
187
  display: flex;
188
- flex-wrap: wrap;
189
- justify-content: flex-end;
190
- gap: 0.35rem;
191
- }
192
- .rfr-nav__links a {
193
- display: inline-flex;
194
  align-items: center;
195
- min-height: 2rem;
196
- padding: 0.35rem 0.65rem;
197
- border-radius: 6px;
198
- color: #2c3e50;
199
- text-decoration: none;
200
- font-size: 0.92rem;
201
- }
202
- .rfr-nav__links a:hover {
203
- background: #edf3f7;
204
- color: #17324d;
205
- text-decoration: none;
206
- }
207
- .rfr-nav__links a.is-active {
208
- background: #edf3f7;
209
  color: #17324d;
210
  font-weight: 700;
 
211
  }
212
- @media (max-width: 720px) {
213
- .rfr-nav {
214
- align-items: flex-start;
215
- flex-direction: column;
216
- gap: 0.5rem;
217
- }
218
- .rfr-nav__links {
219
- justify-content: flex-start;
220
- }
221
  }
222
  </style>
223
- <nav class="rfr-nav" aria-label="Primary navigation">
224
- <div class="rfr-nav__brand">RFR Knowledge Platform</div>
225
- <div class="rfr-nav__links">
226
- __NAV_LINKS__
227
- </div>
228
- </nav>
229
- """.replace("__NAV_LINKS__", nav_links)
230
- st.markdown(
231
- nav_html,
232
  unsafe_allow_html=True,
233
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
 
235
 
236
  def _case_sort_key(case_id: str) -> int:
 
3
  import re
4
  import ast
5
  import uuid
 
6
  from pathlib import Path
 
7
  import streamlit as st
8
 
9
  sys.path.insert(0, str(Path(__file__).parent.parent))
 
136
  if link.get("pdf_url"):
137
  st.markdown(f" - [PDF]({link['pdf_url']})")
138
 
 
 
 
 
 
 
 
 
 
 
139
  def _render_navigation(current_page: str, conversation_id: str) -> None:
140
  nav_items = [
141
  ("ask", "Ask"),
 
143
  ("previous_responses", "Previous Responses"),
144
  ("about", "About"),
145
  ]
146
+ st.markdown(
147
+ """
 
 
 
 
 
 
148
  <style>
149
+ div[data-testid="stHorizontalBlock"] .stButton > button {
150
+ min-height: 2.25rem;
151
+ width: 100%;
152
+ border-radius: 6px;
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  white-space: nowrap;
154
  }
155
+ .rfr-nav-brand {
156
+ min-height: 2.25rem;
157
  display: flex;
 
 
 
 
 
 
158
  align-items: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  color: #17324d;
160
  font-weight: 700;
161
+ font-size: 1.05rem;
162
  }
163
+ .rfr-nav-rule {
164
+ border-bottom: 1px solid #dfe4ea;
165
+ margin: 0.25rem 0 1.5rem 0;
 
 
 
 
 
 
166
  }
167
  </style>
168
+ """,
 
 
 
 
 
 
 
 
169
  unsafe_allow_html=True,
170
  )
171
+ cols = st.columns([4.5, 0.9, 1.35, 1.75, 0.95])
172
+ cols[0].markdown('<div class="rfr-nav-brand">RFR Knowledge Platform</div>', unsafe_allow_html=True)
173
+ for col, (page, label) in zip(cols[1:], nav_items):
174
+ if col.button(
175
+ label,
176
+ key=f"nav_{page}",
177
+ type="primary" if page == current_page else "secondary",
178
+ disabled=page == current_page,
179
+ ):
180
+ _set_query_param("disclaimer_accepted", "true")
181
+ _set_query_param("conversation_id", conversation_id)
182
+ _set_query_param("page", page)
183
+ st.rerun()
184
+ st.markdown('<div class="rfr-nav-rule"></div>', unsafe_allow_html=True)
185
 
186
 
187
  def _case_sort_key(case_id: str) -> int: