Spaces:
Sleeping
Sleeping
Anna Zhou commited on
Commit ·
0b8d85b
1
Parent(s): 632ee0b
Keep navigation in same tab
Browse files- app/app.py +43 -83
app/app.py
CHANGED
|
@@ -6,7 +6,6 @@ import uuid
|
|
| 6 |
import os
|
| 7 |
from datetime import datetime, timezone
|
| 8 |
from pathlib import Path
|
| 9 |
-
from urllib.parse import urlencode
|
| 10 |
import streamlit as st
|
| 11 |
|
| 12 |
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
@@ -146,103 +145,64 @@ 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 |
-
links = []
|
| 158 |
-
for page, label in nav_items:
|
| 159 |
-
classes = "rfr-nav-link is-active" if page == current_page else "rfr-nav-link"
|
| 160 |
-
href = "?" + urlencode({
|
| 161 |
-
"disclaimer_accepted": "true",
|
| 162 |
-
"conversation_id": conversation_id,
|
| 163 |
-
"page": page,
|
| 164 |
-
})
|
| 165 |
-
links.append(f'<a class="{classes}" href="{href}">{label}</a>')
|
| 166 |
-
|
| 167 |
st.markdown(
|
| 168 |
-
|
| 169 |
<style>
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
display: flex;
|
| 172 |
align-items: center;
|
| 173 |
-
gap: 1rem;
|
| 174 |
-
width: 100%;
|
| 175 |
-
}}
|
| 176 |
-
.rfr-nav-brand {{
|
| 177 |
color: #17324d;
|
| 178 |
font-weight: 700;
|
| 179 |
font-size: 1.05rem;
|
| 180 |
white-space: nowrap;
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
align-items: center;
|
| 187 |
-
justify-content: flex-end;
|
| 188 |
-
gap: 0.55rem;
|
| 189 |
-
min-width: 0;
|
| 190 |
-
}}
|
| 191 |
-
.rfr-nav-link {{
|
| 192 |
-
display: inline-flex;
|
| 193 |
-
align-items: center;
|
| 194 |
-
justify-content: center;
|
| 195 |
-
min-height: 2.25rem;
|
| 196 |
-
padding: 0.45rem 0.8rem;
|
| 197 |
-
border: 1px solid #d1d5db;
|
| 198 |
-
border-radius: 6px;
|
| 199 |
-
color: #2f3340 !important;
|
| 200 |
-
text-decoration: none !important;
|
| 201 |
-
background: #ffffff;
|
| 202 |
-
line-height: 1.15;
|
| 203 |
-
white-space: nowrap;
|
| 204 |
-
box-sizing: border-box;
|
| 205 |
-
}}
|
| 206 |
-
.rfr-nav-link:hover {{
|
| 207 |
-
border-color: #aeb6c2;
|
| 208 |
-
background: #f8fafc;
|
| 209 |
-
color: #17324d !important;
|
| 210 |
-
}}
|
| 211 |
-
.rfr-nav-link.is-active {{
|
| 212 |
-
background: #edf4f8;
|
| 213 |
-
border-color: #d6e3ea;
|
| 214 |
-
color: #17324d !important;
|
| 215 |
-
font-weight: 600;
|
| 216 |
-
}}
|
| 217 |
-
.rfr-nav-rule {{
|
| 218 |
border-bottom: 1px solid #dfe4ea;
|
| 219 |
margin: 0.25rem 0 1.5rem 0;
|
| 220 |
-
}
|
| 221 |
-
@media (max-width: 980px) {{
|
| 222 |
-
.rfr-nav {{
|
| 223 |
-
align-items: flex-start;
|
| 224 |
-
flex-direction: column;
|
| 225 |
-
gap: 0.75rem;
|
| 226 |
-
}}
|
| 227 |
-
.rfr-nav-brand {{
|
| 228 |
-
margin-right: 0;
|
| 229 |
-
}}
|
| 230 |
-
.rfr-nav-links {{
|
| 231 |
-
justify-content: flex-start;
|
| 232 |
-
}}
|
| 233 |
-
}}
|
| 234 |
</style>
|
| 235 |
-
<nav class="rfr-nav" aria-label="Primary navigation">
|
| 236 |
-
<div class="rfr-nav-brand">RFR Knowledge Platform</div>
|
| 237 |
-
<div class="rfr-nav-links">
|
| 238 |
-
{"".join(links)}
|
| 239 |
-
</div>
|
| 240 |
-
</nav>
|
| 241 |
-
<div class="rfr-nav-rule"></div>
|
| 242 |
""",
|
| 243 |
unsafe_allow_html=True,
|
| 244 |
)
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
def _case_sort_key(case_id: str) -> int:
|
| 248 |
m = re.search(r"\d+", case_id or "")
|
|
|
|
| 6 |
import os
|
| 7 |
from datetime import datetime, timezone
|
| 8 |
from pathlib import Path
|
|
|
|
| 9 |
import streamlit as st
|
| 10 |
|
| 11 |
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
| 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"] .stButton > button {
|
| 152 |
+
min-height: 2.25rem;
|
| 153 |
+
width: 100%;
|
| 154 |
+
border-radius: 6px;
|
| 155 |
+
white-space: normal;
|
| 156 |
+
line-height: 1.15;
|
| 157 |
+
padding: 0.45rem 0.65rem;
|
| 158 |
+
}
|
| 159 |
+
.rfr-nav-brand {
|
| 160 |
+
min-height: 2.25rem;
|
| 161 |
display: flex;
|
| 162 |
align-items: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
color: #17324d;
|
| 164 |
font-weight: 700;
|
| 165 |
font-size: 1.05rem;
|
| 166 |
white-space: nowrap;
|
| 167 |
+
}
|
| 168 |
+
.rfr-nav-spacer {
|
| 169 |
+
min-height: 0.35rem;
|
| 170 |
+
}
|
| 171 |
+
.rfr-nav-rule {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
border-bottom: 1px solid #dfe4ea;
|
| 173 |
margin: 0.25rem 0 1.5rem 0;
|
| 174 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
""",
|
| 177 |
unsafe_allow_html=True,
|
| 178 |
)
|
| 179 |
|
| 180 |
+
def nav_button(col, page: str, label: str) -> None:
|
| 181 |
+
if col.button(
|
| 182 |
+
label,
|
| 183 |
+
key=f"nav_{page}",
|
| 184 |
+
type="primary" if page == current_page else "secondary",
|
| 185 |
+
disabled=page == current_page,
|
| 186 |
+
):
|
| 187 |
+
_set_query_param("disclaimer_accepted", "true")
|
| 188 |
+
_set_query_param("conversation_id", conversation_id)
|
| 189 |
+
_set_query_param("page", page)
|
| 190 |
+
st.rerun()
|
| 191 |
+
|
| 192 |
+
top_cols = st.columns([3.45, 0.75, 1.55, 1.05])
|
| 193 |
+
top_cols[0].markdown('<div class="rfr-nav-brand">RFR Knowledge Platform</div>', unsafe_allow_html=True)
|
| 194 |
+
nav_button(top_cols[1], "ask", "Ask")
|
| 195 |
+
nav_button(top_cols[2], "previous_responses", "Previous Responses")
|
| 196 |
+
nav_button(top_cols[3], "how_to_use", "How to Use")
|
| 197 |
+
|
| 198 |
+
st.markdown('<div class="rfr-nav-spacer"></div>', unsafe_allow_html=True)
|
| 199 |
+
bottom_cols = st.columns([3.45, 2.2, 1.25, 0.8])
|
| 200 |
+
nav_button(bottom_cols[1], "new_case_requests", "New Case Study Requests")
|
| 201 |
+
nav_button(bottom_cols[2], "case_studies", "Case Studies")
|
| 202 |
+
nav_button(bottom_cols[3], "about", "About")
|
| 203 |
+
|
| 204 |
+
st.markdown('<div class="rfr-nav-rule"></div>', unsafe_allow_html=True)
|
| 205 |
+
|
| 206 |
|
| 207 |
def _case_sort_key(case_id: str) -> int:
|
| 208 |
m = re.search(r"\d+", case_id or "")
|