Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import json
|
| 6 |
-
from datetime import datetime
|
| 7 |
from pathlib import Path
|
| 8 |
from uuid import uuid4
|
| 9 |
|
|
@@ -12,8 +11,7 @@ from shiny import App, reactive, render, ui
|
|
| 12 |
|
| 13 |
# -----------------------------------------------------------------------------
|
| 14 |
# Persistence (file-backed)
|
| 15 |
-
# -
|
| 16 |
-
# - If /data isn't available, we fall back to current directory
|
| 17 |
# -----------------------------------------------------------------------------
|
| 18 |
|
| 19 |
def _pick_state_dir() -> Path:
|
|
@@ -86,7 +84,6 @@ app_ui = ui.page_fluid(
|
|
| 86 |
:root{
|
| 87 |
--navy:#062a4d;
|
| 88 |
--navy2:#041f3a;
|
| 89 |
-
--gold:#f2b705;
|
| 90 |
--cardBorder:#d8e1ee;
|
| 91 |
--cardBg:#ffffff;
|
| 92 |
--muted:#6b778c;
|
|
@@ -94,71 +91,26 @@ app_ui = ui.page_fluid(
|
|
| 94 |
|
| 95 |
body { background: #f3f6fb; }
|
| 96 |
|
| 97 |
-
/* Top bar */
|
| 98 |
.topbar{
|
| 99 |
background: linear-gradient(0deg, var(--navy2), var(--navy));
|
| 100 |
-
color: white;
|
| 101 |
padding: 14px 18px;
|
| 102 |
border-radius: 0 0 14px 14px;
|
| 103 |
box-shadow: 0 2px 10px rgba(0,0,0,.12);
|
| 104 |
display:flex;
|
|
|
|
| 105 |
align-items:center;
|
| 106 |
-
justify-content:space-between;
|
| 107 |
-
gap: 14px;
|
| 108 |
margin-bottom: 18px;
|
| 109 |
}
|
| 110 |
|
| 111 |
-
.nav-left{
|
| 112 |
-
display:flex;
|
| 113 |
-
align-items:center;
|
| 114 |
-
gap: 22px;
|
| 115 |
-
font-weight: 600;
|
| 116 |
-
font-size: 16px;
|
| 117 |
-
white-space:nowrap;
|
| 118 |
-
}
|
| 119 |
-
.nav-item{
|
| 120 |
-
color: rgba(255,255,255,.92);
|
| 121 |
-
text-decoration:none;
|
| 122 |
-
}
|
| 123 |
-
.nav-item:hover{ color: white; text-decoration:underline; }
|
| 124 |
-
|
| 125 |
-
.nav-center{
|
| 126 |
-
display:flex;
|
| 127 |
-
align-items:center;
|
| 128 |
-
justify-content:center;
|
| 129 |
-
min-width: 140px;
|
| 130 |
-
}
|
| 131 |
-
.logo{
|
| 132 |
-
font-weight: 900;
|
| 133 |
-
font-size: 26px;
|
| 134 |
-
letter-spacing: 1px;
|
| 135 |
-
color: var(--gold);
|
| 136 |
-
text-shadow: 0 1px 0 rgba(0,0,0,.25);
|
| 137 |
-
user-select:none;
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
.nav-right{
|
| 141 |
-
display:flex;
|
| 142 |
-
align-items:center;
|
| 143 |
-
gap: 10px;
|
| 144 |
-
white-space:nowrap;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
.save-status{
|
| 148 |
-
color: rgba(255,255,255,.8);
|
| 149 |
-
font-size: 12px;
|
| 150 |
-
margin-right: 8px;
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
/* Top-right + button */
|
| 154 |
.top-add button{
|
| 155 |
background: white !important;
|
| 156 |
color: var(--navy) !important;
|
| 157 |
border: 1px solid rgba(0,0,0,.08) !important;
|
| 158 |
border-radius: 12px !important;
|
| 159 |
padding: 10px 18px !important;
|
| 160 |
-
font-weight:
|
| 161 |
-
font-size:
|
| 162 |
line-height: 1 !important;
|
| 163 |
box-shadow: 0 2px 8px rgba(0,0,0,.14);
|
| 164 |
}
|
|
@@ -198,17 +150,6 @@ app_ui = ui.page_fluid(
|
|
| 198 |
gap: 10px;
|
| 199 |
margin-bottom: 6px;
|
| 200 |
}
|
| 201 |
-
.pill{
|
| 202 |
-
display:inline-block;
|
| 203 |
-
padding: 2px 10px;
|
| 204 |
-
border-radius: 999px;
|
| 205 |
-
font-weight: 800;
|
| 206 |
-
font-size: 12px;
|
| 207 |
-
background: #eef3fb;
|
| 208 |
-
color: #2a3b57;
|
| 209 |
-
border: 1px solid #d9e4f5;
|
| 210 |
-
user-select:none;
|
| 211 |
-
}
|
| 212 |
|
| 213 |
.del-btn button{
|
| 214 |
border: none !important;
|
|
@@ -220,12 +161,6 @@ app_ui = ui.page_fluid(
|
|
| 220 |
}
|
| 221 |
.del-btn button:hover{ color: #1c2b44 !important; }
|
| 222 |
|
| 223 |
-
.help{
|
| 224 |
-
color: var(--muted);
|
| 225 |
-
font-size: 12px;
|
| 226 |
-
margin-top: 6px;
|
| 227 |
-
}
|
| 228 |
-
|
| 229 |
.form-control { border-radius: 10px; }
|
| 230 |
textarea.form-control { min-height: 92px; }
|
| 231 |
|
|
@@ -243,29 +178,12 @@ app_ui = ui.page_fluid(
|
|
| 243 |
"""
|
| 244 |
),
|
| 245 |
|
| 246 |
-
# Top bar
|
| 247 |
ui.tags.div(
|
| 248 |
{"class": "topbar"},
|
| 249 |
-
ui.tags.div(
|
| 250 |
-
{"class": "nav-left"},
|
| 251 |
-
ui.tags.a("Cards", {"class": "nav-item", "href": "#"}),
|
| 252 |
-
ui.tags.a("Models", {"class": "nav-item", "href": "#"}),
|
| 253 |
-
ui.tags.a("Glossary", {"class": "nav-item", "href": "#"}),
|
| 254 |
-
ui.tags.a("Notes", {"class": "nav-item", "href": "#"}),
|
| 255 |
-
),
|
| 256 |
-
ui.tags.div({"class": "nav-center"}, ui.tags.div({"class": "logo"}, "WVU")),
|
| 257 |
-
ui.tags.div(
|
| 258 |
-
{"class": "nav-right"},
|
| 259 |
-
ui.tags.div({"class": "save-status"}, ui.output_text("save_status")),
|
| 260 |
-
ui.tags.div({"class": "top-add"}, ui.input_action_button("add_card", "+")),
|
| 261 |
-
),
|
| 262 |
),
|
| 263 |
|
| 264 |
ui.output_ui("grid"),
|
| 265 |
-
ui.tags.div(
|
| 266 |
-
{"class": "help"},
|
| 267 |
-
f"Saving to: {STATE_PATH} • Note: persistence is server-wide (if this Space is public, all users share the same saved board).",
|
| 268 |
-
),
|
| 269 |
)
|
| 270 |
|
| 271 |
|
|
@@ -274,9 +192,8 @@ app_ui = ui.page_fluid(
|
|
| 274 |
# -----------------------------------------------------------------------------
|
| 275 |
|
| 276 |
def server(input, output, session):
|
| 277 |
-
cards_rv = reactive.Value(load_cards()) #
|
| 278 |
last_saved_json = reactive.Value("")
|
| 279 |
-
last_saved_at = reactive.Value(None)
|
| 280 |
|
| 281 |
def snapshot_cards() -> list[dict]:
|
| 282 |
cards = cards_rv.get()
|
|
@@ -308,9 +225,7 @@ def server(input, output, session):
|
|
| 308 |
if s != last_saved_json.get():
|
| 309 |
save_cards(cards)
|
| 310 |
last_saved_json.set(s)
|
| 311 |
-
last_saved_at.set(datetime.utcnow())
|
| 312 |
|
| 313 |
-
# Add card
|
| 314 |
@reactive.Effect
|
| 315 |
@reactive.event(input.add_card)
|
| 316 |
def _add_card():
|
|
@@ -358,20 +273,13 @@ def server(input, output, session):
|
|
| 358 |
cards = snapshot_cards()
|
| 359 |
persist(cards)
|
| 360 |
|
| 361 |
-
@output
|
| 362 |
-
@render.text
|
| 363 |
-
def save_status():
|
| 364 |
-
t = last_saved_at.get()
|
| 365 |
-
if t is None:
|
| 366 |
-
return "Loaded" if len(cards_rv.get()) else ""
|
| 367 |
-
return "Saved"
|
| 368 |
-
|
| 369 |
@output
|
| 370 |
@render.ui
|
| 371 |
def grid():
|
| 372 |
cards = cards_rv.get()
|
| 373 |
|
| 374 |
if not cards:
|
|
|
|
| 375 |
return ui.tags.div(
|
| 376 |
{"style": "padding: 10px 6px;"},
|
| 377 |
ui.tags.div(
|
|
@@ -385,7 +293,7 @@ def server(input, output, session):
|
|
| 385 |
"""
|
| 386 |
},
|
| 387 |
ui.tags.b("No cards yet."),
|
| 388 |
-
ui.tags.div("Click the +
|
| 389 |
),
|
| 390 |
)
|
| 391 |
|
|
@@ -400,7 +308,7 @@ def server(input, output, session):
|
|
| 400 |
{"class": "card"},
|
| 401 |
ui.tags.div(
|
| 402 |
{"class": "card-header"},
|
| 403 |
-
ui.tags.
|
| 404 |
ui.tags.div({"class": "del-btn"}, ui.input_action_button(f"del_{cid}", "×")),
|
| 405 |
),
|
| 406 |
ui.input_text(
|
|
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import json
|
|
|
|
| 6 |
from pathlib import Path
|
| 7 |
from uuid import uuid4
|
| 8 |
|
|
|
|
| 11 |
|
| 12 |
# -----------------------------------------------------------------------------
|
| 13 |
# Persistence (file-backed)
|
| 14 |
+
# - Hugging Face Spaces: enable Persistent Storage to persist /data across restarts
|
|
|
|
| 15 |
# -----------------------------------------------------------------------------
|
| 16 |
|
| 17 |
def _pick_state_dir() -> Path:
|
|
|
|
| 84 |
:root{
|
| 85 |
--navy:#062a4d;
|
| 86 |
--navy2:#041f3a;
|
|
|
|
| 87 |
--cardBorder:#d8e1ee;
|
| 88 |
--cardBg:#ffffff;
|
| 89 |
--muted:#6b778c;
|
|
|
|
| 91 |
|
| 92 |
body { background: #f3f6fb; }
|
| 93 |
|
| 94 |
+
/* Top bar: ONLY plus button on right */
|
| 95 |
.topbar{
|
| 96 |
background: linear-gradient(0deg, var(--navy2), var(--navy));
|
|
|
|
| 97 |
padding: 14px 18px;
|
| 98 |
border-radius: 0 0 14px 14px;
|
| 99 |
box-shadow: 0 2px 10px rgba(0,0,0,.12);
|
| 100 |
display:flex;
|
| 101 |
+
justify-content:flex-end;
|
| 102 |
align-items:center;
|
|
|
|
|
|
|
| 103 |
margin-bottom: 18px;
|
| 104 |
}
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
.top-add button{
|
| 107 |
background: white !important;
|
| 108 |
color: var(--navy) !important;
|
| 109 |
border: 1px solid rgba(0,0,0,.08) !important;
|
| 110 |
border-radius: 12px !important;
|
| 111 |
padding: 10px 18px !important;
|
| 112 |
+
font-weight: 900 !important;
|
| 113 |
+
font-size: 20px !important;
|
| 114 |
line-height: 1 !important;
|
| 115 |
box-shadow: 0 2px 8px rgba(0,0,0,.14);
|
| 116 |
}
|
|
|
|
| 150 |
gap: 10px;
|
| 151 |
margin-bottom: 6px;
|
| 152 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
.del-btn button{
|
| 155 |
border: none !important;
|
|
|
|
| 161 |
}
|
| 162 |
.del-btn button:hover{ color: #1c2b44 !important; }
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
.form-control { border-radius: 10px; }
|
| 165 |
textarea.form-control { min-height: 92px; }
|
| 166 |
|
|
|
|
| 178 |
"""
|
| 179 |
),
|
| 180 |
|
|
|
|
| 181 |
ui.tags.div(
|
| 182 |
{"class": "topbar"},
|
| 183 |
+
ui.tags.div({"class": "top-add"}, ui.input_action_button("add_card", "+")),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
),
|
| 185 |
|
| 186 |
ui.output_ui("grid"),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
)
|
| 188 |
|
| 189 |
|
|
|
|
| 192 |
# -----------------------------------------------------------------------------
|
| 193 |
|
| 194 |
def server(input, output, session):
|
| 195 |
+
cards_rv = reactive.Value(load_cards()) # empty if no saved file yet
|
| 196 |
last_saved_json = reactive.Value("")
|
|
|
|
| 197 |
|
| 198 |
def snapshot_cards() -> list[dict]:
|
| 199 |
cards = cards_rv.get()
|
|
|
|
| 225 |
if s != last_saved_json.get():
|
| 226 |
save_cards(cards)
|
| 227 |
last_saved_json.set(s)
|
|
|
|
| 228 |
|
|
|
|
| 229 |
@reactive.Effect
|
| 230 |
@reactive.event(input.add_card)
|
| 231 |
def _add_card():
|
|
|
|
| 273 |
cards = snapshot_cards()
|
| 274 |
persist(cards)
|
| 275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
@output
|
| 277 |
@render.ui
|
| 278 |
def grid():
|
| 279 |
cards = cards_rv.get()
|
| 280 |
|
| 281 |
if not cards:
|
| 282 |
+
# Starts with nothing; + adds the first card
|
| 283 |
return ui.tags.div(
|
| 284 |
{"style": "padding: 10px 6px;"},
|
| 285 |
ui.tags.div(
|
|
|
|
| 293 |
"""
|
| 294 |
},
|
| 295 |
ui.tags.b("No cards yet."),
|
| 296 |
+
ui.tags.div("Click the + to add your first card."),
|
| 297 |
),
|
| 298 |
)
|
| 299 |
|
|
|
|
| 308 |
{"class": "card"},
|
| 309 |
ui.tags.div(
|
| 310 |
{"class": "card-header"},
|
| 311 |
+
ui.tags.div(), # left spacer (keeps delete aligned right)
|
| 312 |
ui.tags.div({"class": "del-btn"}, ui.input_action_button(f"del_{cid}", "×")),
|
| 313 |
),
|
| 314 |
ui.input_text(
|