-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreview.html
More file actions
1393 lines (1273 loc) · 51.8 KB
/
Copy pathreview.html
File metadata and controls
1393 lines (1273 loc) · 51.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>llmbrary — Catalog Review</title>
<style>
:root {
--bg: #1a1a2e;
--bg2: #16213e;
--bg3: #0f3460;
--surface: #1e2a4a;
--surface2: #253458;
--text: #e0e0e0;
--text2: #a0aec0;
--accent: #e94560;
--accent2: #ff6b6b;
--green: #48bb78;
--yellow: #ecc94b;
--blue: #63b3ed;
--border: #2d3748;
--radius: 6px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.5;
}
/* ── Layout ── */
.app { max-width: 1200px; margin: 0 auto; padding: 1rem; }
header {
display: flex; align-items: baseline; gap: 1rem;
padding: 1rem 0 0.5rem;
}
header h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; }
header h1 span { color: var(--accent); }
header .subtitle { color: var(--text2); font-size: 0.85rem; }
/* ── Stats ── */
.stats {
display: flex; gap: 1rem; padding: 0.75rem 0; flex-wrap: wrap;
}
.stat {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 0.5rem 1rem;
font-size: 0.85rem;
}
.stat strong { font-size: 1.2rem; display: block; }
.stat.warn strong { color: var(--yellow); }
.stat.ok strong { color: var(--green); }
.stat.info strong { color: var(--blue); }
/* ── Tabs ── */
.tabs {
display: flex; gap: 0; border-bottom: 2px solid var(--border);
margin: 1rem 0 0;
}
.tab-btn {
background: none; border: none; color: var(--text2);
padding: 0.6rem 1.2rem; cursor: pointer; font-size: 0.9rem;
border-bottom: 2px solid transparent;
margin-bottom: -2px; transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; padding: 1rem 0; }
.tab-content.active { display: block; }
/* ── Toolbar ── */
.toolbar {
display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
padding: 0.5rem 0; margin-bottom: 0.5rem;
}
.toolbar select, .toolbar input, .toolbar button {
background: var(--surface);
border: 1px solid var(--border);
color: var(--text);
padding: 0.4rem 0.7rem;
border-radius: var(--radius);
font-size: 0.85rem;
}
.toolbar input { min-width: 200px; }
.toolbar button { cursor: pointer; }
.toolbar button:hover { background: var(--surface2); }
.toolbar .spacer { flex: 1; }
.btn-accent {
background: var(--accent) !important;
border-color: var(--accent) !important;
font-weight: 600;
}
.btn-accent:hover { background: var(--accent2) !important; }
.btn-green { background: var(--green) !important; border-color: var(--green) !important; color: #1a1a2e !important; font-weight: 600; }
/* ── Pagination ── */
.pagination {
display: flex; gap: 0.5rem; align-items: center;
justify-content: center; padding: 0.75rem 0;
font-size: 0.85rem; color: var(--text2);
}
.pagination button {
background: var(--surface); border: 1px solid var(--border);
color: var(--text); padding: 0.3rem 0.8rem;
border-radius: var(--radius); cursor: pointer; font-size: 0.85rem;
}
.pagination button:hover { background: var(--surface2); }
.pagination button:disabled { opacity: 0.3; cursor: default; }
/* ── Entry Card ── */
.entry-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 1rem 1.25rem;
margin-bottom: 0.75rem;
transition: border-color 0.15s;
position: relative;
}
.entry-card.selected { border-color: var(--accent); }
.entry-card.reviewed { border-left: 3px solid var(--green); }
.entry-card.flagged { border-left: 3px solid var(--accent); opacity: 0.6; }
.entry-header {
display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap;
margin-bottom: 0.5rem;
}
.entry-title { font-size: 1.1rem; font-weight: 600; }
.entry-author { color: var(--text2); font-size: 0.9rem; }
.entry-year { color: var(--text2); font-size: 0.85rem; }
.entry-badges { display: flex; gap: 0.4rem; margin-left: auto; }
.badge {
font-size: 0.7rem; padding: 0.15rem 0.5rem;
border-radius: 999px; font-weight: 600; text-transform: uppercase;
letter-spacing: 0.03em;
}
.badge-high { background: rgba(72,187,120,0.15); color: var(--green); }
.badge-medium { background: rgba(236,201,75,0.15); color: var(--yellow); }
.badge-review { background: rgba(233,69,96,0.15); color: var(--accent); }
.badge-reviewed { background: rgba(72,187,120,0.2); color: var(--green); }
.badge-flagged { background: rgba(233,69,96,0.25); color: var(--accent2); }
.badge-enrichment { background: rgba(255,167,38,0.18); color: #ffa726; }
.badge-book { background: rgba(99,179,237,0.15); color: var(--blue); }
.badge-film { background: rgba(187,99,237,0.18); color: #bb63ed; }
.badge-music { background: rgba(237,179,99,0.18); color: #edaa63; }
.entry-synopsis {
font-size: 0.85rem; color: var(--text2);
margin: 0.4rem 0; line-height: 1.55;
}
.entry-meta {
display: flex; gap: 1.5rem; flex-wrap: wrap;
font-size: 0.8rem; color: var(--text2);
margin-top: 0.5rem;
}
.entry-meta label { color: var(--blue); font-weight: 500; }
.theme-tag {
display: inline-block; background: var(--bg3);
padding: 0.1rem 0.5rem; border-radius: 999px;
font-size: 0.75rem; margin: 0.1rem 0.15rem;
}
.convo-tag {
display: inline-block; font-style: italic;
font-size: 0.8rem;
}
/* ── Entry Actions ── */
.entry-actions {
display: flex; gap: 0.4rem; margin-top: 0.6rem;
}
.entry-actions button {
background: var(--bg2); border: 1px solid var(--border);
color: var(--text2); padding: 0.25rem 0.6rem;
border-radius: var(--radius); cursor: pointer; font-size: 0.78rem;
}
.entry-actions button:hover { background: var(--surface2); color: var(--text); }
/* ── Edit Mode ── */
.edit-form { display: none; margin-top: 0.75rem; }
.entry-card.editing .edit-form { display: block; }
.entry-card.editing .entry-display { display: none; }
.edit-row {
display: flex; gap: 0.5rem; align-items: flex-start;
margin-bottom: 0.5rem;
}
.edit-row label {
min-width: 80px; font-size: 0.8rem; color: var(--text2);
padding-top: 0.4rem; text-align: right;
}
.edit-row input, .edit-row textarea {
flex: 1; background: var(--bg);
border: 1px solid var(--border); color: var(--text);
padding: 0.4rem 0.6rem; border-radius: var(--radius);
font-size: 0.85rem; font-family: inherit;
}
.edit-row textarea { min-height: 80px; resize: vertical; }
.edit-buttons { display: flex; gap: 0.4rem; margin-top: 0.5rem; justify-content: flex-end; }
.edit-buttons button {
padding: 0.35rem 1rem; border-radius: var(--radius);
border: 1px solid var(--border); cursor: pointer;
font-size: 0.85rem;
}
.edit-save { background: var(--green); color: #1a1a2e; border-color: var(--green) !important; font-weight: 600; }
.edit-cancel { background: var(--surface); color: var(--text); }
/* ── Unreadable Tab ── */
.unreadable-card {
display: flex; gap: 1.5rem;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 1.25rem;
margin-bottom: 1rem;
}
.unreadable-photo {
flex: 0 0 400px; max-height: 350px;
border-radius: var(--radius); overflow: hidden;
}
.unreadable-photo img {
width: 100%; height: 100%;
object-fit: contain; background: #111;
}
.unreadable-info { flex: 1; min-width: 250px; }
.unreadable-desc {
font-size: 0.95rem; margin-bottom: 0.25rem;
}
.unreadable-pos {
font-size: 0.8rem; color: var(--text2); margin-bottom: 1rem;
}
.unreadable-form .edit-row { margin-bottom: 0.5rem; }
.unreadable-form input, .unreadable-form textarea {
flex: 1; background: var(--bg);
border: 1px solid var(--border); color: var(--text);
padding: 0.4rem 0.6rem; border-radius: var(--radius);
font-size: 0.85rem; font-family: inherit;
}
.unreadable-form textarea { min-height: 60px; resize: vertical; }
.unreadable-actions {
display: flex; gap: 0.4rem; margin-top: 1rem;
}
.unreadable-actions button {
padding: 0.4rem 1rem; border-radius: var(--radius);
border: 1px solid var(--border); cursor: pointer;
font-size: 0.85rem; background: var(--surface2); color: var(--text);
}
.unreadable-counter {
font-size: 0.85rem; color: var(--text2); margin-bottom: 1rem;
}
/* ── Toast ── */
.toast {
position: fixed; bottom: 1.5rem; right: 1.5rem;
background: var(--green); color: #1a1a2e;
padding: 0.6rem 1.2rem; border-radius: var(--radius);
font-weight: 600; font-size: 0.9rem;
opacity: 0; transition: opacity 0.3s;
pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; }
/* ── Shortcuts help ── */
.shortcuts {
position: fixed; bottom: 1.5rem; left: 1.5rem;
background: var(--surface); border: 1px solid var(--border);
border-radius: var(--radius); padding: 0.6rem 0.9rem;
font-size: 0.75rem; color: var(--text2); line-height: 1.7;
}
.shortcuts kbd {
background: var(--bg); border: 1px solid var(--border);
border-radius: 3px; padding: 0.1rem 0.35rem;
font-family: monospace; font-size: 0.75rem; color: var(--text);
}
/* ── Loading / Error ── */
.loading-msg {
text-align: center; padding: 3rem;
color: var(--text2); font-size: 1rem;
}
.error-msg {
background: rgba(233,69,96,0.1); border: 1px solid var(--accent);
border-radius: var(--radius); padding: 1rem 1.25rem;
color: var(--accent2); margin: 1rem 0; font-size: 0.9rem;
}
.error-msg code {
display: block; margin-top: 0.5rem;
font-size: 0.85rem; color: var(--text2);
}
/* ── Text Import Tab ── */
.import-area {
display: flex; gap: 1.5rem; margin-top: 0.5rem;
}
.import-input { flex: 1; min-width: 0; }
.import-input textarea {
width: 100%; min-height: 300px; resize: vertical;
background: var(--bg); border: 1px solid var(--border);
color: var(--text); padding: 0.75rem; border-radius: var(--radius);
font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.85rem;
line-height: 1.6;
}
.import-input textarea::placeholder { color: var(--text2); opacity: 0.5; }
.import-controls {
display: flex; gap: 0.5rem; align-items: center;
margin-top: 0.75rem; flex-wrap: wrap;
}
.import-controls select, .import-controls button {
background: var(--surface); border: 1px solid var(--border);
color: var(--text); padding: 0.4rem 0.7rem;
border-radius: var(--radius); font-size: 0.85rem; cursor: pointer;
}
.import-controls button:hover { background: var(--surface2); }
.import-preview { flex: 1; min-width: 0; }
.import-preview-header {
font-size: 0.9rem; font-weight: 600; margin-bottom: 0.5rem;
color: var(--text2);
}
.import-preview-list {
max-height: 400px; overflow-y: auto;
background: var(--bg); border: 1px solid var(--border);
border-radius: var(--radius); padding: 0.5rem;
}
.import-item {
padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border);
font-size: 0.85rem;
}
.import-item:last-child { border-bottom: none; }
.import-item .ii-title { font-weight: 600; }
.import-item .ii-author { color: var(--text2); }
.import-item .ii-year { color: var(--blue); font-size: 0.8rem; }
.import-item.ii-dup { opacity: 0.4; text-decoration: line-through; }
.import-item.ii-dup::after {
content: ' (duplicate)'; color: var(--accent); font-size: 0.75rem;
font-style: italic; text-decoration: none;
}
.import-summary {
margin-top: 0.75rem; font-size: 0.85rem; color: var(--text2);
padding: 0.5rem 0.75rem; background: var(--surface);
border-radius: var(--radius); border: 1px solid var(--border);
}
.import-summary strong { color: var(--text); }
/* ── Responsive ── */
@media (max-width: 768px) {
.unreadable-card { flex-direction: column; }
.unreadable-photo { flex: none; max-height: 250px; }
.import-area { flex-direction: column; }
}
</style>
</head>
<body>
<div class="app" id="app">
<header>
<h1><span>llm</span>brary</h1>
<span class="subtitle">catalog review tool</span>
</header>
<div class="stats" id="stats"></div>
<div class="tabs">
<button class="tab-btn active" data-tab="catalog">Catalog</button>
<button class="tab-btn" data-tab="unreadable">Unreadable</button>
<button class="tab-btn" data-tab="import">Text Import</button>
</div>
<!-- Catalog Tab -->
<div class="tab-content active" id="tab-catalog">
<div class="toolbar">
<select id="filter">
<option value="all">All entries</option>
<option value="needs_review">Needs review</option>
<option value="medium">Medium confidence</option>
<option value="reviewed">Reviewed</option>
<option value="flagged">Flagged</option>
<option value="enrichment">Needs enrichment</option>
<option value="type_book">Books only</option>
<option value="type_film">Films only</option>
<option value="type_music">Music only</option>
</select>
<input type="text" id="search" placeholder="Search title, author, theme…">
<span class="spacer"></span>
<button onclick="exportCatalog()" class="btn-green">⬇ Save catalog.json</button>
<button onclick="exportEnrichmentQueue()" style="background:#ffa726;border-color:#ffa726;color:#1a1a2e;font-weight:600;">⬇ Export changes for enrichment</button>
</div>
<div id="catalog-list"></div>
<div class="pagination" id="pagination"></div>
</div>
<!-- Unreadable Tab -->
<div class="tab-content" id="tab-unreadable">
<div class="unreadable-counter" id="unreadable-counter"></div>
<div id="unreadable-view"></div>
<div style="margin-top:1rem; display:flex; gap:0.5rem;">
<button onclick="exportCatalog()" class="btn-green" style="padding:0.4rem 1rem; border-radius:var(--radius); border:none; cursor:pointer; font-size:0.85rem;">⬇ Save catalog.json</button>
<button onclick="exportUnreadable()" style="padding:0.4rem 1rem; border-radius:var(--radius); border:1px solid var(--border); background:var(--surface); color:var(--text); cursor:pointer; font-size:0.85rem;">⬇ Save unreadable.json</button>
</div>
</div>
<!-- Text Import Tab -->
<div class="tab-content" id="tab-import">
<p style="font-size:0.85rem; color:var(--text2); margin-bottom:0.75rem;">
Paste a list of items below — one per line. Select the media type, then choose a format or auto-detect.<br>
<strong>Books:</strong> <code>Title - Author</code>, <code>Title by Author</code>, <code>Title, Author</code>, <code>Title (Author)</code>, <code>Author: Title</code>, <code>"Title","Author","Year"</code>, or just <code>Title</code>.<br>
<strong>Films:</strong> <code>Title (Year) - Director</code>, <code>Title - Director</code>, <code>Director: Title</code>, or just <code>Title (Year)</code>.<br>
<strong>Music:</strong> <code>Artist - Album (Year)</code>, <code>Artist - Album</code>, <code>Album by Artist</code>, or just <code>Album</code>.<br>
Lines starting with <code>#</code> are treated as comments.
</p>
<div class="import-area">
<div class="import-input">
<textarea id="import-text" placeholder="Paste your list here… # Books: Invisible Cities - Italo Calvino Gödel, Escher, Bach by Douglas Hofstadter # Films: Stalker (1979) - Andrei Tarkovsky Meshes of the Afternoon - Maya Deren # Music: John Coltrane - A Love Supreme (1965) Music for 18 Musicians by Steve Reich"></textarea>
<div class="import-controls">
<select id="import-media-type" onchange="updateImportFormatOptions()">
<option value="book">Book</option>
<option value="film">Film</option>
<option value="music">Music</option>
</select>
<select id="import-format">
<option value="auto">Auto-detect format</option>
<option value="dash">Dash: Title - Author</option>
<option value="by">By: Title by Author</option>
<option value="comma">Comma: Title, Author</option>
<option value="paren">Paren: Title (Author)</option>
<option value="colon">Colon: Author: Title</option>
<option value="tab">Tab-separated</option>
<option value="csv">CSV: "Title","Author"</option>
<option value="title-only">Title only</option>
</select>
<button onclick="previewImport()">Preview</button>
<span class="spacer"></span>
<button class="btn-green" id="import-confirm-btn" onclick="confirmImport()" disabled style="color:#1a1a2e">✓ Add to Catalog</button>
<button onclick="exportImportedJSON()" id="import-export-btn" disabled style="background:#ffa726;border-color:#ffa726;color:#1a1a2e;font-weight:600;">⬇ Export JSON</button>
</div>
</div>
<div class="import-preview">
<div class="import-preview-header">Preview <span id="import-preview-count"></span></div>
<div class="import-preview-list" id="import-preview-list">
<div style="padding:1rem; color:var(--text2); text-align:center; font-size:0.85rem;">
Paste text and click Preview to see parsed results.
</div>
</div>
<div class="import-summary" id="import-summary" style="display:none;"></div>
</div>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<div class="shortcuts">
<kbd>↑</kbd><kbd>↓</kbd> navigate
<kbd>e</kbd> edit
<kbd>n</kbd> next
<kbd>r</kbd> reviewed
<kbd>s</kbd> save
<kbd>f</kbd> flag
</div>
<script>
// ── State ──
let catalog = [];
let unreadable = [];
let promoted = []; // entries moved from unreadable → catalog (also in catalog[])
let promotedCount = 0; // tracks how many were promoted for stats
let reviewState = {}; // idx → { reviewed, flagged }
let editState = {}; // idx → edited field values
let originalValues = {}; // idx → { title, author } snapshotted on load
let enrichmentNeeded = {}; // idx → { enrichment_needed, edited_fields }
let currentFilter = 'all';
let searchQuery = '';
let page = 0;
const PAGE_SIZE = 15;
let selectedIdx = 0; // index into filteredList
let filteredList = [];
let unreadableIdx = 0;
// ── Load Data ──
async function init() {
const listEl = document.getElementById('catalog-list');
listEl.innerHTML = '<div class="loading-msg">Loading catalog…</div>';
try {
const [catRes, unrRes] = await Promise.all([
fetch('catalog.json'),
fetch('unreadable.json')
]);
if (!catRes.ok || !unrRes.ok) throw new Error('Fetch failed');
catalog = await catRes.json();
unreadable = await unrRes.json();
// Snapshot original title/author for enrichment tracking
catalog.forEach((e, i) => {
originalValues[i] = { title: e.title ?? '', author: e.author ?? '' };
});
} catch (e) {
listEl.innerHTML = `
<div class="error-msg">
Could not load JSON files. You likely need to serve this directory locally.
<code>cd ~/Development/llmbrary && python3 -m http.server 8000</code>
Then open <strong>http://localhost:8000/review.html</strong>
</div>`;
return;
}
applyFilter();
renderStats();
renderUnreadable();
}
// ── Filtering ──
function applyFilter() {
const q = searchQuery.toLowerCase();
filteredList = catalog.map((e, i) => ({ entry: e, origIdx: i })).filter(({ entry, origIdx }) => {
const rs = reviewState[origIdx] || {};
if (currentFilter === 'needs_review' && !entry.needs_review) return false;
if (currentFilter === 'medium' && entry.confidence !== 'medium') return false;
if (currentFilter === 'reviewed' && !rs.reviewed) return false;
if (currentFilter === 'flagged' && !rs.flagged) return false;
if (currentFilter === 'enrichment' && !enrichmentNeeded[origIdx]) return false;
if (currentFilter === 'type_book' && (entry.media_type || 'book') !== 'book') return false;
if (currentFilter === 'type_film' && (entry.media_type || 'book') !== 'film') return false;
if (currentFilter === 'type_music' && (entry.media_type || 'book') !== 'music') return false;
if (q) {
const haystack = [
entry.title, entry.author, ...(entry.themes || []),
entry.synopsis, ...(entry.in_conversation_with || [])
].filter(Boolean).join(' ').toLowerCase();
if (!haystack.includes(q)) return false;
}
return true;
});
page = 0;
selectedIdx = 0;
renderCatalog();
}
// ── Render Catalog ──
function renderCatalog() {
const listEl = document.getElementById('catalog-list');
const start = page * PAGE_SIZE;
const pageItems = filteredList.slice(start, start + PAGE_SIZE);
listEl.innerHTML = pageItems.map((item, i) => {
const e = item.entry;
const oi = item.origIdx;
const rs = reviewState[oi] || {};
const ed = editState[oi] || {};
const globalPageIdx = start + i;
const classes = [
'entry-card',
globalPageIdx === selectedIdx ? 'selected' : '',
rs.reviewed ? 'reviewed' : '',
rs.flagged ? 'flagged' : '',
ed._editing ? 'editing' : ''
].filter(Boolean).join(' ');
const mt = e.media_type || 'book';
const title = ed.title ?? e.title ?? '';
const author = ed.author ?? e.author ?? '';
const director = ed.director ?? e.director ?? '';
const artist = ed.artist ?? e.artist ?? '';
const creator = mt === 'film' ? director : mt === 'music' ? artist : author;
const creatorLabel = mt === 'film' ? 'Director' : mt === 'music' ? 'Artist' : 'Author';
const year = ed.year ?? e.year ?? '';
const synopsis = ed.synopsis ?? e.synopsis ?? '';
const themes = ed.themes ?? e.themes ?? [];
const convo = ed.in_conversation_with ?? e.in_conversation_with ?? [];
return `
<div class="${classes}" data-page-idx="${globalPageIdx}" data-orig-idx="${oi}">
<div class="entry-display">
<div class="entry-header">
<span class="entry-title">${esc(title)}</span>
<span class="entry-author">${esc(creator)}</span>
<span class="entry-year">${year || ''}</span>
<div class="entry-badges">
${(() => { const mt = e.media_type || 'book'; return mt !== 'book' ? `<span class="badge badge-${mt}">${mt}</span>` : ''; })()}
${e.confidence === 'medium' ? '<span class="badge badge-medium">medium</span>' : '<span class="badge badge-high">high</span>'}
${e.needs_review ? '<span class="badge badge-review">needs review</span>' : ''}
${rs.reviewed ? '<span class="badge badge-reviewed">✓ reviewed</span>' : ''}
${rs.flagged ? '<span class="badge badge-flagged">⚑ flagged</span>' : ''}
${enrichmentNeeded[oi] ? '<span class="badge badge-enrichment">needs enrichment</span>' : ''}
</div>
</div>
<div class="entry-synopsis">${esc(synopsis)}</div>
<div class="entry-meta">
<div><label>Themes:</label> ${themes.length ? themes.map(t => `<span class="theme-tag">${esc(t)}</span>`).join('') : (enrichmentNeeded[oi] ? '<span style="color:#ffa726;font-style:italic"> Will be populated after enrichment.</span>' : '')}</div>
<div><label>In conversation with:</label> ${convo.length ? convo.map(c => `<span class="convo-tag">${esc(c)}</span>`).join(', ') : (enrichmentNeeded[oi] ? '<span style="color:#ffa726;font-style:italic"> Will be populated after enrichment.</span>' : '')}</div>
<div><label>Source:</label> ${esc(e.source_image)}</div>
</div>
<div class="entry-actions">
<button onclick="startEdit(${oi})">✏ Edit</button>
<button onclick="toggleReviewed(${oi})">${rs.reviewed ? '↩ Unmark' : '✓ Reviewed'}</button>
<button onclick="toggleFlagged(${oi})">${rs.flagged ? '↩ Unflag' : '⚑ Flag'}</button>
</div>
</div>
<div class="edit-form" id="edit-${oi}">
<div class="edit-row"><label>Title</label><input value="${escAttr(title)}" data-field="title"></div>
<div class="edit-row"><label>${creatorLabel}</label><input value="${escAttr(creator)}" data-field="${mt === 'film' ? 'director' : mt === 'music' ? 'artist' : 'author'}"></div>
<div class="edit-row"><label>Year</label><input type="number" value="${year || ''}" data-field="year"></div>
<div class="edit-row"><label>Synopsis</label><textarea data-field="synopsis">${esc(synopsis)}</textarea></div>
<div class="edit-row"><label>Themes</label><input value="${escAttr(themes.join(', '))}" data-field="themes" placeholder="comma separated"></div>
<div class="edit-buttons">
<button class="edit-cancel" onclick="cancelEdit(${oi})">Cancel</button>
<button class="edit-save" onclick="saveEdit(${oi})">Save</button>
</div>
</div>
</div>`;
}).join('');
renderPagination();
renderStats();
}
function renderPagination() {
const total = filteredList.length;
const totalPages = Math.ceil(total / PAGE_SIZE);
const el = document.getElementById('pagination');
if (totalPages <= 1) { el.innerHTML = `<span>${total} entries</span>`; return; }
el.innerHTML = `
<button ${page === 0 ? 'disabled' : ''} onclick="goPage(${page - 1})">← Prev</button>
<span>Page ${page + 1} of ${totalPages} (${total} entries)</span>
<button ${page >= totalPages - 1 ? 'disabled' : ''} onclick="goPage(${page + 1})">Next →</button>
`;
}
function goPage(p) {
page = p;
selectedIdx = page * PAGE_SIZE;
renderCatalog();
document.getElementById('catalog-list').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
// ── Stats ──
function renderStats() {
const total = catalog.length;
const reviewedCount = Object.values(reviewState).filter(r => r.reviewed).length;
const needsReview = catalog.filter(e => e.needs_review).length;
const flaggedCount = Object.values(reviewState).filter(r => r.flagged).length;
const mediumCount = catalog.filter(e => e.confidence === 'medium').length;
const unreadLeft = unreadable.length;
const enrichCount = Object.keys(enrichmentNeeded).length;
const bookCount = catalog.filter(e => (e.media_type || 'book') === 'book').length;
const filmCount = catalog.filter(e => e.media_type === 'film').length;
const musicCount = catalog.filter(e => e.media_type === 'music').length;
document.getElementById('stats').innerHTML = `
<div class="stat info"><strong>${total}</strong>catalog entries</div>
${filmCount ? `<div class="stat" style="border-color:#bb63ed"><strong style="color:#bb63ed">${filmCount}</strong>films</div>` : ''}
${musicCount ? `<div class="stat" style="border-color:#edaa63"><strong style="color:#edaa63">${musicCount}</strong>music</div>` : ''}
<div class="stat ok"><strong>${reviewedCount}</strong>reviewed</div>
<div class="stat warn"><strong>${needsReview}</strong>needs review</div>
<div class="stat"><strong>${mediumCount}</strong>medium conf.</div>
<div class="stat warn"><strong>${flaggedCount}</strong>flagged</div>
${enrichCount ? `<div class="stat" style="border-color:#ffa726"><strong style="color:#ffa726">${enrichCount}</strong>needs enrichment</div>` : ''}
<div class="stat"><strong>${unreadLeft}</strong>unreadable left</div>
${promotedCount ? `<div class="stat ok"><strong>${promotedCount}</strong>newly identified</div>` : ''}
`;
}
// ── Edit ──
function startEdit(oi) {
if (!editState[oi]) editState[oi] = {};
editState[oi]._editing = true;
renderCatalog();
const form = document.getElementById(`edit-${oi}`);
if (form) form.querySelector('input')?.focus();
}
function cancelEdit(oi) {
if (editState[oi]) editState[oi]._editing = false;
renderCatalog();
}
function saveEdit(oi) {
const form = document.getElementById(`edit-${oi}`);
if (!form) return;
const inputs = form.querySelectorAll('[data-field]');
if (!editState[oi]) editState[oi] = {};
inputs.forEach(inp => {
const field = inp.dataset.field;
let val = inp.value.trim();
if (field === 'year') val = val ? parseInt(val, 10) : null;
if (field === 'themes') val = val.split(',').map(s => s.trim()).filter(Boolean);
editState[oi][field] = val;
catalog[oi][field] = val; // apply to in-memory catalog
});
editState[oi]._editing = false;
// Check if title or author changed from original loaded values
const orig = originalValues[oi] || { title: '', author: '' };
const changedFields = [];
if ((editState[oi].title ?? '') !== orig.title) changedFields.push('title');
if ((editState[oi].author ?? '') !== orig.author) changedFields.push('author');
if (changedFields.length > 0) {
enrichmentNeeded[oi] = { enrichment_needed: true, edited_fields: changedFields };
catalog[oi].enrichment_needed = true;
catalog[oi].edited_fields = changedFields;
// Clear stale data — title/author changed means different book
const staleNotice = 'Awaiting enrichment \u2014 title/author was corrected during review.';
catalog[oi].synopsis = staleNotice;
catalog[oi].themes = [];
catalog[oi].in_conversation_with = [];
catalog[oi].year = null;
editState[oi].synopsis = staleNotice;
editState[oi].themes = [];
editState[oi].in_conversation_with = [];
editState[oi].year = null;
toast('Changes saved — stale data cleared, marked for enrichment');
} else {
toast('Changes saved in memory');
}
renderCatalog();
}
function toggleReviewed(oi) {
if (!reviewState[oi]) reviewState[oi] = {};
reviewState[oi].reviewed = !reviewState[oi].reviewed;
renderCatalog();
}
function toggleFlagged(oi) {
if (!reviewState[oi]) reviewState[oi] = {};
reviewState[oi].flagged = !reviewState[oi].flagged;
renderCatalog();
}
// ── Export ──
function exportCatalog() {
const output = catalog
.filter((_, i) => !(reviewState[i] || {}).flagged)
.map(e => {
const copy = { ...e };
delete copy.needs_review; // clean up review flags
return copy;
});
downloadJSON(output, 'catalog.json');
toast(`Exported ${output.length} entries (${promotedCount} newly identified, flagged removed)`);
}
function exportEnrichmentQueue() {
const queue = catalog
.filter((_, i) => enrichmentNeeded[i])
.map(e => ({ ...e }));
if (queue.length === 0) {
toast('No entries need enrichment');
return;
}
downloadJSON(queue, 'enrichment_queue.json');
toast(`Exported ${queue.length} entries for enrichment`);
}
function exportUnreadable() {
downloadJSON(unreadable, 'unreadable.json');
toast(`Exported ${unreadable.length} unreadable entries`);
}
function downloadJSON(data, filename) {
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = filename;
a.click();
URL.revokeObjectURL(a.href);
}
// ── Unreadable Tab ──
function renderUnreadable() {
const el = document.getElementById('unreadable-view');
const counter = document.getElementById('unreadable-counter');
if (unreadable.length === 0) {
el.innerHTML = '<div class="loading-msg">All unreadable entries have been processed.</div>';
counter.textContent = '';
renderStats();
return;
}
if (unreadableIdx >= unreadable.length) unreadableIdx = unreadable.length - 1;
const entry = unreadable[unreadableIdx];
counter.textContent = `Entry ${unreadableIdx + 1} of ${unreadable.length}`;
el.innerHTML = `
<div class="unreadable-card">
<div class="unreadable-photo">
<img src="photos/${esc(entry.source_image)}" alt="${esc(entry.source_image)}">
</div>
<div class="unreadable-info">
<div class="unreadable-desc"><strong>Description:</strong> ${esc(entry.description)}</div>
<div class="unreadable-pos"><strong>Position:</strong> ${esc(entry.position)} · <strong>Source:</strong> ${esc(entry.source_image)}</div>
<div class="unreadable-form">
<div class="edit-row"><label style="min-width:70px">Title</label><input id="ur-title" placeholder="Book title"></div>
<div class="edit-row"><label style="min-width:70px">Author</label><input id="ur-author" placeholder="Author name"></div>
<div class="edit-row"><label style="min-width:70px">Year</label><input id="ur-year" type="number" placeholder="Year"></div>
<div class="edit-row"><label style="min-width:70px">Synopsis</label><textarea id="ur-synopsis" placeholder="Brief synopsis (optional)"></textarea></div>
<div class="edit-row"><label style="min-width:70px">Themes</label><input id="ur-themes" placeholder="Comma separated themes"></div>
</div>
<div class="unreadable-actions">
<button class="btn-green" onclick="promoteUnreadable()" style="color:#1a1a2e">✓ Add to Catalog</button>
<button onclick="skipUnreadable()">Skip →</button>
<button onclick="cantIdentify()" style="color:var(--yellow)">? Can't Identify</button>
${unreadableIdx > 0 ? '<button onclick="prevUnreadable()">← Back</button>' : ''}
</div>
</div>
</div>
`;
}
function promoteUnreadable() {
const title = document.getElementById('ur-title').value.trim();
const author = document.getElementById('ur-author').value.trim();
if (!title) { toast('Title is required'); return; }
const entry = unreadable[unreadableIdx];
const newEntry = {
title,
author: author || null,
year: null,
synopsis: 'Awaiting enrichment.',
themes: [],
source_image: entry.source_image,
confidence: 'manual',
in_conversation_with: [],
manually_added: true,
enrichment_needed: true
};
catalog.push(newEntry);
const newIdx = catalog.length - 1;
originalValues[newIdx] = { title: newEntry.title, author: newEntry.author ?? '' };
enrichmentNeeded[newIdx] = { enrichment_needed: true, edited_fields: [] };
promoted.push(newEntry);
promotedCount++;
unreadable.splice(unreadableIdx, 1);
if (unreadableIdx >= unreadable.length) unreadableIdx = Math.max(0, unreadable.length - 1);
toast(`"${title}" added to catalog (needs enrichment)`);
applyFilter();
renderUnreadable();
renderStats();
}
function skipUnreadable() {
unreadableIdx = (unreadableIdx + 1) % Math.max(1, unreadable.length);
renderUnreadable();
}
function prevUnreadable() {
if (unreadableIdx > 0) unreadableIdx--;
renderUnreadable();
}
function cantIdentify() {
toast('Kept as unreadable, moving on');
skipUnreadable();
}
// ── Tabs ──
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(t => t.classList.remove('active'));
btn.classList.add('active');
document.getElementById(`tab-${btn.dataset.tab}`).classList.add('active');
});
});
// ── Filter / Search ──
document.getElementById('filter').addEventListener('change', e => {
currentFilter = e.target.value;
applyFilter();
});
document.getElementById('search').addEventListener('input', e => {
searchQuery = e.target.value;
applyFilter();
});
// ── Keyboard Shortcuts ──
document.addEventListener('keydown', e => {
// Don't interfere with inputs
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.tagName === 'SELECT') {
if (e.key === 'Escape') { e.target.blur(); e.preventDefault(); }
return;
}
const catalogVisible = document.getElementById('tab-catalog').classList.contains('active');
if (e.key === 'ArrowDown' || e.key === 'j') {
e.preventDefault();
if (catalogVisible) moveSelection(1);
} else if (e.key === 'ArrowUp' || e.key === 'k') {
e.preventDefault();
if (catalogVisible) moveSelection(-1);
} else if (e.key === 'e') {
e.preventDefault();
if (catalogVisible) editSelected();
} else if (e.key === 'n') {
e.preventDefault();
if (catalogVisible) moveSelection(1);
else skipUnreadable();
} else if (e.key === 'r') {
e.preventDefault();
if (catalogVisible) reviewSelected();
} else if (e.key === 'f') {
e.preventDefault();
if (catalogVisible) flagSelected();
} else if (e.key === 's') {
e.preventDefault();
exportCatalog();
}
});
function moveSelection(delta) {
const newIdx = selectedIdx + delta;
if (newIdx < 0 || newIdx >= filteredList.length) return;
selectedIdx = newIdx;
const newPage = Math.floor(selectedIdx / PAGE_SIZE);
if (newPage !== page) { page = newPage; }
renderCatalog();
const card = document.querySelector(`.entry-card[data-page-idx="${selectedIdx}"]`);
if (card) card.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
function editSelected() {
const item = filteredList[selectedIdx];
if (item) startEdit(item.origIdx);
}
function reviewSelected() {
const item = filteredList[selectedIdx];
if (item) toggleReviewed(item.origIdx);
}
function flagSelected() {
const item = filteredList[selectedIdx];
if (item) toggleFlagged(item.origIdx);
}
// ── Helpers ──
function esc(s) {
if (s == null) return '';
return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
}
function escAttr(s) {
return esc(s).replace(/'/g, ''');
}
function toast(msg) {
const el = document.getElementById('toast');
el.textContent = msg;
el.classList.add('show');
clearTimeout(toast._t);
toast._t = setTimeout(() => el.classList.remove('show'), 2000);
}
// ── Text Import ──────────────────────────────────────────────────────────────
function updateImportFormatOptions() {
const mt = document.getElementById('import-media-type').value;
const sel = document.getElementById('import-format');
const bookFormats = [
['auto','Auto-detect format'],['dash','Dash: Title - Author'],['by','By: Title by Author'],
['comma','Comma: Title, Author'],['paren','Paren: Title (Author)'],['colon','Colon: Author: Title'],
['tab','Tab-separated'],['csv','CSV: "Title","Author"'],['title-only','Title only']
];
const filmFormats = [
['auto','Auto-detect format'],['dash','Title (Year) - Director'],
['colon','Director: Title (Year)'],['title-year','Title (Year) or Title']
];
const musicFormats = [
['auto','Auto-detect format'],['dash','Artist - Album (Year)'],
['by','Album by Artist'],['csv','CSV: "Artist","Album","Year"'],['title-only','Title only']
];
const formats = mt === 'film' ? filmFormats : mt === 'music' ? musicFormats : bookFormats;
sel.innerHTML = formats.map(([v, l]) => `<option value="${v}">${l}</option>`).join('');
}
let importParsed = []; // { title, author/director/artist, year, isDuplicate, matchedTitle, media_type }
const TITLE_WORDS = new Set([
'the','a','an','of','in','on','for','and','to','with',
'introduction','guide','history','art','how','why','what'
]);
function normalizeTitle(t) {
t = t.toLowerCase().trim();
for (const p of ['the ','a ','an ']) {
if (t.startsWith(p)) { t = t.slice(p.length); break; }
}
return t;