benresnic commited on
Commit
f727999
·
verified ·
1 Parent(s): 03d45a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -56
app.py CHANGED
@@ -8,7 +8,6 @@ from pathlib import Path
8
  from uuid import uuid4
9
 
10
  from shiny import App, ui
11
-
12
  from starlette.applications import Starlette
13
  from starlette.requests import Request
14
  from starlette.responses import JSONResponse, Response
@@ -118,8 +117,7 @@ def _json(data: dict, status_code: int = 200) -> JSONResponse:
118
 
119
  async def api_cards(request: Request) -> Response:
120
  if request.method == "GET":
121
- state = await get_state()
122
- return _json(state)
123
 
124
  if request.method == "POST":
125
  state = await get_state()
@@ -180,6 +178,7 @@ app_ui = ui.page_fluid(
180
  --cardBorder:#d8e1ee;
181
  --cardBg:#ffffff;
182
  --muted:#6b778c;
 
183
  }
184
  body { background: #f3f6fb; }
185
 
@@ -219,7 +218,7 @@ app_ui = ui.page_fluid(
219
  display:none;
220
  }
221
 
222
- /* GRID: 2 columns, FULL WIDTH */
223
  .cards-grid{
224
  display:grid;
225
  grid-template-columns: repeat(2, minmax(0, 1fr));
@@ -233,7 +232,7 @@ app_ui = ui.page_fluid(
233
  .cards-grid{ grid-template-columns: 1fr; }
234
  }
235
 
236
- /* Card = true square */
237
  .card{
238
  background: var(--cardBg);
239
  border: 1px solid var(--cardBorder);
@@ -248,13 +247,42 @@ app_ui = ui.page_fluid(
248
  }
249
 
250
  .card-header{
 
251
  display:flex;
252
  align-items:center;
253
  justify-content:space-between;
254
- padding: 12px 12px 8px 12px;
 
255
  border-bottom: 1px solid #eef2f8;
256
  flex: 0 0 auto;
257
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  .del-btn{
259
  border: none;
260
  background: transparent;
@@ -263,6 +291,7 @@ app_ui = ui.page_fluid(
263
  font-size: 20px;
264
  cursor:pointer;
265
  padding: 0 8px;
 
266
  }
267
  .del-btn:hover{ color:#1c2b44; }
268
 
@@ -270,12 +299,35 @@ app_ui = ui.page_fluid(
270
  padding: 12px;
271
  display:flex;
272
  flex-direction:column;
273
- gap: 10px;
274
  flex: 1 1 auto;
275
  min-height: 0;
276
  overflow:hidden; /* no card scroll */
277
  }
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  .card-footer{
280
  padding: 12px;
281
  border-top: 1px solid #eef2f8;
@@ -302,14 +354,6 @@ app_ui = ui.page_fluid(
302
  background: white;
303
  }
304
 
305
- /* ~3–4 lines visible; scroll inside textarea if more */
306
- textarea.ta{
307
- height: 92px;
308
- line-height: 1.25;
309
- resize: none;
310
- overflow: auto;
311
- }
312
-
313
  .resource-link{
314
  display:inline-block;
315
  margin-top: 8px;
@@ -325,7 +369,7 @@ app_ui = ui.page_fluid(
325
  color: #41516b;
326
  }
327
 
328
- /* DELETE MODAL (renamed to avoid Bootstrap .modal conflicts) */
329
  .del-backdrop{
330
  position: fixed;
331
  inset: 0;
@@ -341,23 +385,11 @@ app_ui = ui.page_fluid(
341
  border-radius: 14px;
342
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
343
  padding: 14px 14px 12px 14px;
344
- display:block; /* force visible */
345
- }
346
- .del-dialog h3{
347
- margin: 0 0 8px 0;
348
- font-size: 16px;
349
- }
350
- .del-muted{
351
- color: var(--muted);
352
- font-size: 13px;
353
- margin-bottom: 10px;
354
- }
355
- .del-checks{
356
- display:flex;
357
- flex-direction:column;
358
- gap: 8px;
359
- margin: 10px 0;
360
  }
 
 
 
361
  .del-checks label{
362
  margin: 0;
363
  font-weight: 650;
@@ -367,12 +399,7 @@ app_ui = ui.page_fluid(
367
  align-items:center;
368
  gap: 8px;
369
  }
370
- .del-actions{
371
- display:flex;
372
- gap: 10px;
373
- justify-content:flex-end;
374
- margin-top: 12px;
375
- }
376
  .btn{
377
  border-radius: 12px;
378
  padding: 9px 12px;
@@ -386,17 +413,14 @@ app_ui = ui.page_fluid(
386
  background: #fff1f2;
387
  color: #9f1239;
388
  }
389
- .btn[disabled]{
390
- opacity: .55;
391
- cursor: not-allowed;
392
- }
393
  """
394
  ),
395
  ui.tags.div({"class": "topbar"}, ui.tags.button("+", {"id": "add-btn", "type": "button"})),
396
  ui.tags.div({"id": "err", "class": "err"}),
397
  ui.tags.div({"id": "grid", "class": "cards-grid"}),
398
  ui.tags.script(
399
- """
400
  (() => {
401
  const grid = document.getElementById("grid");
402
  const addBtn = document.getElementById("add-btn");
@@ -512,26 +536,24 @@ app_ui = ui.page_fluid(
512
  card.className = "card";
513
  card.dataset.id = c.id;
514
 
 
 
 
515
  card.innerHTML = `
516
  <div class="card-header">
517
- <div></div>
518
  <button class="del-btn" type="button" title="Delete">×</button>
519
  </div>
520
 
521
  <div class="card-main">
522
- <div>
523
- <label>Model</label>
524
- <input type="text" class="model" value="${escapeHtml(c.model)}" />
525
- </div>
526
-
527
  <div>
528
  <label>How it Works</label>
529
- <textarea class="how ta">${escapeHtml(c.how_it_works)}</textarea>
530
  </div>
531
 
532
- <div>
533
  <label>Use Cases</label>
534
- <textarea class="use ta">${escapeHtml(c.use_cases)}</textarea>
535
  </div>
536
  </div>
537
 
@@ -542,8 +564,8 @@ app_ui = ui.page_fluid(
542
  </div>
543
  `;
544
 
545
- const delBtn = card.querySelector(".del-btn");
546
- const modelEl = card.querySelector(".model");
547
  const howEl = card.querySelector(".how");
548
  const useEl = card.querySelector(".use");
549
  const linkEl = card.querySelector(".link");
@@ -556,9 +578,14 @@ app_ui = ui.page_fluid(
556
  : "";
557
  }
558
 
 
 
 
 
 
559
  async function saveNow(){
560
  const payload = {
561
- model: modelEl.value || "",
562
  how_it_works: howEl.value || "",
563
  use_cases: useEl.value || "",
564
  link: linkEl.value || "",
@@ -572,6 +599,7 @@ app_ui = ui.page_fluid(
572
  state.cards = data.cards;
573
  showErr("");
574
  updateLink();
 
575
  }catch(e){
576
  showErr(String(e.message || e));
577
  }
@@ -579,12 +607,13 @@ app_ui = ui.page_fluid(
579
 
580
  function scheduleSave(){
581
  updateLink();
 
582
  const existing = saveTimers.get(c.id);
583
  if(existing) clearTimeout(existing);
584
  saveTimers.set(c.id, setTimeout(saveNow, 350));
585
  }
586
 
587
- [modelEl, howEl, useEl, linkEl].forEach(el => el.addEventListener("input", scheduleSave));
588
 
589
  delBtn.addEventListener("click", (e) => {
590
  e.preventDefault();
 
8
  from uuid import uuid4
9
 
10
  from shiny import App, ui
 
11
  from starlette.applications import Starlette
12
  from starlette.requests import Request
13
  from starlette.responses import JSONResponse, Response
 
117
 
118
  async def api_cards(request: Request) -> Response:
119
  if request.method == "GET":
120
+ return _json(await get_state())
 
121
 
122
  if request.method == "POST":
123
  state = await get_state()
 
178
  --cardBorder:#d8e1ee;
179
  --cardBg:#ffffff;
180
  --muted:#6b778c;
181
+ --headerBg:#f3f6fb;
182
  }
183
  body { background: #f3f6fb; }
184
 
 
218
  display:none;
219
  }
220
 
221
+ /* GRID: 2 columns, full width */
222
  .cards-grid{
223
  display:grid;
224
  grid-template-columns: repeat(2, minmax(0, 1fr));
 
232
  .cards-grid{ grid-template-columns: 1fr; }
233
  }
234
 
235
+ /* Card = square */
236
  .card{
237
  background: var(--cardBg);
238
  border: 1px solid var(--cardBorder);
 
247
  }
248
 
249
  .card-header{
250
+ background: var(--headerBg);
251
  display:flex;
252
  align-items:center;
253
  justify-content:space-between;
254
+ gap: 10px;
255
+ padding: 10px 10px 8px 10px;
256
  border-bottom: 1px solid #eef2f8;
257
  flex: 0 0 auto;
258
  }
259
+
260
+ /* Title input in header */
261
+ .title-input{
262
+ width: 100%;
263
+ border: none;
264
+ outline: none;
265
+ background: transparent;
266
+ padding: 6px 8px;
267
+ border-radius: 10px;
268
+ font-size: 16px;
269
+ font-weight: 650;
270
+ color: #1f2a44;
271
+ }
272
+ .title-input::placeholder{
273
+ color: #7b879c;
274
+ font-weight: 650;
275
+ }
276
+ /* When filled, make it look like a bold title */
277
+ .card.has-title .title-input{
278
+ font-weight: 900;
279
+ }
280
+ /* Optional subtle focus background so it feels editable */
281
+ .title-input:focus{
282
+ background: rgba(255,255,255,.8);
283
+ border: 1px solid #d8e1ee;
284
+ }
285
+
286
  .del-btn{
287
  border: none;
288
  background: transparent;
 
291
  font-size: 20px;
292
  cursor:pointer;
293
  padding: 0 8px;
294
+ flex: 0 0 auto;
295
  }
296
  .del-btn:hover{ color:#1c2b44; }
297
 
 
299
  padding: 12px;
300
  display:flex;
301
  flex-direction:column;
302
+ gap: 12px;
303
  flex: 1 1 auto;
304
  min-height: 0;
305
  overflow:hidden; /* no card scroll */
306
  }
307
 
308
+ /* How fixed height (~3-4 lines) */
309
+ textarea.ta-fixed{
310
+ height: 92px;
311
+ line-height: 1.25;
312
+ resize: none;
313
+ overflow: auto;
314
+ }
315
+
316
+ /* Use Cases grows to fill remaining space (kills the blank gap) */
317
+ .grow{
318
+ display:flex;
319
+ flex-direction:column;
320
+ flex: 1 1 auto;
321
+ min-height: 0;
322
+ }
323
+ textarea.ta-grow{
324
+ flex: 1 1 auto;
325
+ min-height: 0;
326
+ line-height: 1.25;
327
+ resize: none;
328
+ overflow: auto;
329
+ }
330
+
331
  .card-footer{
332
  padding: 12px;
333
  border-top: 1px solid #eef2f8;
 
354
  background: white;
355
  }
356
 
 
 
 
 
 
 
 
 
357
  .resource-link{
358
  display:inline-block;
359
  margin-top: 8px;
 
369
  color: #41516b;
370
  }
371
 
372
+ /* Delete modal (avoid Bootstrap conflicts) */
373
  .del-backdrop{
374
  position: fixed;
375
  inset: 0;
 
385
  border-radius: 14px;
386
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
387
  padding: 14px 14px 12px 14px;
388
+ display:block;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  }
390
+ .del-dialog h3{ margin: 0 0 8px 0; font-size: 16px; }
391
+ .del-muted{ color: var(--muted); font-size: 13px; margin-bottom: 10px; }
392
+ .del-checks{ display:flex; flex-direction:column; gap: 8px; margin: 10px 0; }
393
  .del-checks label{
394
  margin: 0;
395
  font-weight: 650;
 
399
  align-items:center;
400
  gap: 8px;
401
  }
402
+ .del-actions{ display:flex; gap: 10px; justify-content:flex-end; margin-top: 12px; }
 
 
 
 
 
403
  .btn{
404
  border-radius: 12px;
405
  padding: 9px 12px;
 
413
  background: #fff1f2;
414
  color: #9f1239;
415
  }
416
+ .btn[disabled]{ opacity: .55; cursor: not-allowed; }
 
 
 
417
  """
418
  ),
419
  ui.tags.div({"class": "topbar"}, ui.tags.button("+", {"id": "add-btn", "type": "button"})),
420
  ui.tags.div({"id": "err", "class": "err"}),
421
  ui.tags.div({"id": "grid", "class": "cards-grid"}),
422
  ui.tags.script(
423
+ r"""
424
  (() => {
425
  const grid = document.getElementById("grid");
426
  const addBtn = document.getElementById("add-btn");
 
536
  card.className = "card";
537
  card.dataset.id = c.id;
538
 
539
+ // mark title bold if filled
540
+ if((c.model || "").trim().length > 0) card.classList.add("has-title");
541
+
542
  card.innerHTML = `
543
  <div class="card-header">
544
+ <input class="title-input" type="text" value="${escapeHtml(c.model)}" placeholder="Model" />
545
  <button class="del-btn" type="button" title="Delete">×</button>
546
  </div>
547
 
548
  <div class="card-main">
 
 
 
 
 
549
  <div>
550
  <label>How it Works</label>
551
+ <textarea class="how ta-fixed">${escapeHtml(c.how_it_works)}</textarea>
552
  </div>
553
 
554
+ <div class="grow">
555
  <label>Use Cases</label>
556
+ <textarea class="use ta-grow">${escapeHtml(c.use_cases)}</textarea>
557
  </div>
558
  </div>
559
 
 
564
  </div>
565
  `;
566
 
567
+ const delBtn = card.querySelector(".del-btn");
568
+ const titleEl = card.querySelector(".title-input");
569
  const howEl = card.querySelector(".how");
570
  const useEl = card.querySelector(".use");
571
  const linkEl = card.querySelector(".link");
 
578
  : "";
579
  }
580
 
581
+ function updateTitleStyle(){
582
+ const has = (titleEl.value || "").trim().length > 0;
583
+ card.classList.toggle("has-title", has);
584
+ }
585
+
586
  async function saveNow(){
587
  const payload = {
588
+ model: titleEl.value || "",
589
  how_it_works: howEl.value || "",
590
  use_cases: useEl.value || "",
591
  link: linkEl.value || "",
 
599
  state.cards = data.cards;
600
  showErr("");
601
  updateLink();
602
+ updateTitleStyle();
603
  }catch(e){
604
  showErr(String(e.message || e));
605
  }
 
607
 
608
  function scheduleSave(){
609
  updateLink();
610
+ updateTitleStyle();
611
  const existing = saveTimers.get(c.id);
612
  if(existing) clearTimeout(existing);
613
  saveTimers.set(c.id, setTimeout(saveNow, 350));
614
  }
615
 
616
+ [titleEl, howEl, useEl, linkEl].forEach(el => el.addEventListener("input", scheduleSave));
617
 
618
  delBtn.addEventListener("click", (e) => {
619
  e.preventDefault();