|
| 1 | +"use client"; |
| 2 | +import { useRef } from "react"; |
1 | 3 | import { Button } from "@repo/ui/components/ui/button"; |
2 | 4 | import { Checkbox } from "@repo/ui/components/ui/checkbox"; |
3 | | -import { ChevronDown } from "lucide-react"; |
4 | | - |
5 | | -const NODE_TYPES = [ |
6 | | - { |
7 | | - label: "Claim", |
8 | | - description: |
9 | | - "An assertion about how something works or should work. Usually a single declarative sentence.", |
10 | | - candidateTag: "#clm-candidate", |
11 | | - color: "#7DA13E", |
12 | | - }, |
13 | | - { |
14 | | - label: "Question", |
15 | | - description: |
16 | | - "An unknown being explored through research. Framed as a question that can be investigated.", |
17 | | - candidateTag: "#que-candidate", |
18 | | - color: "#99890E", |
19 | | - }, |
20 | | - { |
21 | | - label: "Hypothesis", |
22 | | - description: |
23 | | - "A proposed answer to a question. Collects evidence for or against.", |
24 | | - candidateTag: "#hyp-candidate", |
25 | | - color: "#7C4DFF", |
26 | | - }, |
27 | | - { |
28 | | - label: "Evidence", |
29 | | - description: |
30 | | - "A discrete observation from a published dataset or experiment. Usually in past tense with observable, model system, and method.", |
31 | | - candidateTag: "#evd-candidate", |
32 | | - color: "#dc0c4a", |
33 | | - }, |
34 | | - { |
35 | | - label: "Result", |
36 | | - description: |
37 | | - "A discrete observation from ongoing research, in past tense. Includes source context.", |
38 | | - candidateTag: "#res-candidate", |
39 | | - color: "#E6A23C", |
40 | | - }, |
41 | | - { |
42 | | - label: "Source", |
43 | | - description: "A referenced publication or external resource.", |
44 | | - candidateTag: "#src-candidate", |
45 | | - color: "#9E9E9E", |
46 | | - }, |
47 | | - { |
48 | | - label: "Theory", |
49 | | - description: "A theoretical framework or model that explains phenomena.", |
50 | | - candidateTag: "#the-candidate", |
51 | | - color: "#8B5CF6", |
52 | | - }, |
53 | | -]; |
| 5 | +import { Label } from "@repo/ui/components/ui/label"; |
| 6 | +import { Textarea } from "@repo/ui/components/ui/textarea"; |
| 7 | +import { ChevronDown, Upload } from "lucide-react"; |
| 8 | +import { NODE_TYPE_DEFINITIONS } from "~/types/extraction"; |
54 | 9 |
|
55 | 10 | const SECTION_LABEL_CLASS = |
56 | | - "mb-3 block px-1 text-[18px] font-semibold tracking-[-0.016em] text-slate-800"; |
| 11 | + "mb-3 block px-1 text-lg font-semibold tracking-tight text-slate-800"; |
| 12 | + |
| 13 | +type SidebarProps = { |
| 14 | + pdfFile: File | null; |
| 15 | + onFileSelect: (file: File) => void; |
| 16 | + researchQuestion: string; |
| 17 | + onResearchQuestionChange: (value: string) => void; |
| 18 | + selectedTypes: Set<string>; |
| 19 | + onToggleType: (candidateTag: string) => void; |
| 20 | +}; |
| 21 | + |
| 22 | +export const Sidebar = ({ |
| 23 | + pdfFile, |
| 24 | + onFileSelect, |
| 25 | + researchQuestion, |
| 26 | + onResearchQuestionChange, |
| 27 | + selectedTypes, |
| 28 | + onToggleType, |
| 29 | +}: SidebarProps): React.ReactElement => { |
| 30 | + const fileInputRef = useRef<HTMLInputElement>(null); |
| 31 | + |
| 32 | + const handleFileInput = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 33 | + const file = event.target.files?.[0]; |
| 34 | + if (file?.type === "application/pdf") { |
| 35 | + onFileSelect(file); |
| 36 | + } |
| 37 | + event.target.value = ""; |
| 38 | + }; |
57 | 39 |
|
58 | | -export const Sidebar = (): React.ReactElement => { |
59 | 40 | return ( |
60 | | - <aside className="flex w-full shrink-0 flex-col overflow-hidden rounded-[24px] border border-slate-200/85 bg-white shadow-[0_26px_52px_-38px_rgba(15,23,42,0.6)] lg:w-[390px] xl:w-[420px]"> |
| 41 | + <aside className="flex w-full shrink-0 flex-col overflow-hidden rounded-3xl border border-slate-200/85 bg-white shadow-xl lg:w-96"> |
61 | 42 | <div className="flex-1 overflow-y-auto p-4 lg:p-5"> |
62 | 43 | <section className="mb-6"> |
63 | 44 | <h3 className={SECTION_LABEL_CLASS}>Paper</h3> |
64 | | - <div className="flex w-full items-start gap-3 rounded-2xl border border-slate-200 bg-white p-3.5"> |
65 | | - <div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-gradient-to-b from-rose-500 to-rose-600"> |
66 | | - <span className="text-[11px] font-bold tracking-[0.02em] text-white"> |
67 | | - PDF |
68 | | - </span> |
69 | | - </div> |
70 | | - <div className="min-w-0 flex-1 pt-0.5"> |
71 | | - <p className="truncate text-[16px] font-semibold leading-tight text-slate-900"> |
72 | | - Yamamoto et al. - 2015 - Basolate... |
73 | | - </p> |
74 | | - <p className="mt-1 text-[14px] leading-tight text-slate-500"> |
75 | | - 7.8 MB ·{" "} |
76 | | - <span className="font-medium text-slate-500">Replace file</span> |
77 | | - </p> |
78 | | - </div> |
79 | | - </div> |
| 45 | + <input |
| 46 | + ref={fileInputRef} |
| 47 | + type="file" |
| 48 | + accept=".pdf,application/pdf" |
| 49 | + className="hidden" |
| 50 | + onChange={handleFileInput} |
| 51 | + /> |
| 52 | + {pdfFile ? ( |
| 53 | + <Button |
| 54 | + type="button" |
| 55 | + variant="outline" |
| 56 | + onClick={() => fileInputRef.current?.click()} |
| 57 | + className="group h-auto w-full items-start justify-start gap-3 whitespace-normal rounded-2xl border-slate-200 p-3.5 text-left hover:border-slate-300 hover:bg-white" |
| 58 | + > |
| 59 | + <div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-gradient-to-b from-rose-500 to-rose-600"> |
| 60 | + <span className="text-xs font-bold tracking-wide text-white"> |
| 61 | + PDF |
| 62 | + </span> |
| 63 | + </div> |
| 64 | + <div className="min-w-0 flex-1 pt-0.5"> |
| 65 | + <p className="truncate text-base font-semibold leading-tight text-slate-900"> |
| 66 | + {pdfFile.name} |
| 67 | + </p> |
| 68 | + <p className="mt-1 text-sm leading-tight text-slate-500"> |
| 69 | + {(pdfFile.size / 1024 / 1024).toFixed(1)} MB ·{" "} |
| 70 | + <span className="font-medium transition-colors group-hover:text-sky-700"> |
| 71 | + Replace file |
| 72 | + </span> |
| 73 | + </p> |
| 74 | + </div> |
| 75 | + </Button> |
| 76 | + ) : ( |
| 77 | + <Button |
| 78 | + type="button" |
| 79 | + variant="outline" |
| 80 | + onClick={() => fileInputRef.current?.click()} |
| 81 | + className="h-auto w-full flex-col gap-2.5 rounded-2xl border-2 border-dashed border-slate-300 px-4 py-9 text-center hover:border-slate-400 hover:bg-slate-50 [&_svg]:size-5" |
| 82 | + > |
| 83 | + <div className="flex h-11 w-11 items-center justify-center rounded-xl bg-slate-100"> |
| 84 | + <Upload className="text-slate-500" /> |
| 85 | + </div> |
| 86 | + <div> |
| 87 | + <p className="text-base font-semibold text-slate-800"> |
| 88 | + Upload PDF |
| 89 | + </p> |
| 90 | + <p className="mt-1 text-sm text-slate-500"> |
| 91 | + Click to choose a file |
| 92 | + </p> |
| 93 | + </div> |
| 94 | + </Button> |
| 95 | + )} |
80 | 96 | </section> |
81 | 97 |
|
82 | 98 | <section className="mb-6"> |
83 | 99 | <h3 className={SECTION_LABEL_CLASS}>Model</h3> |
84 | 100 | <Button |
85 | 101 | variant="outline" |
86 | | - className="w-full justify-between rounded-xl border-slate-300 px-3.5 py-3 text-[16px] font-medium text-slate-700" |
| 102 | + className="w-full justify-between rounded-xl border-slate-300 px-3.5 py-3 text-base font-medium text-slate-700" |
87 | 103 | > |
88 | 104 | <span>Claude Sonnet 4.6</span> |
89 | | - <ChevronDown className="h-4 w-4 text-slate-500" /> |
| 105 | + <ChevronDown className="text-slate-500" /> |
90 | 106 | </Button> |
91 | 107 | </section> |
92 | 108 |
|
93 | 109 | <section className="mb-5"> |
94 | 110 | <h3 className={SECTION_LABEL_CLASS}>Research Question</h3> |
95 | | - <div className="w-full rounded-xl border border-slate-300 bg-white px-3.5 py-3 text-[16px] text-slate-700"> |
96 | | - What are the molecular determinants of lumenoid formation in hiPSCs? |
97 | | - </div> |
| 111 | + <Textarea |
| 112 | + value={researchQuestion} |
| 113 | + onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => |
| 114 | + onResearchQuestionChange(e.target.value) |
| 115 | + } |
| 116 | + placeholder="e.g., What are the molecular determinants of lumenoid formation in hiPSCs?" |
| 117 | + className="min-h-36 resize-none rounded-xl border-slate-300 bg-white px-3.5 py-3 text-base text-slate-700 placeholder:text-slate-400" |
| 118 | + /> |
98 | 119 | </section> |
99 | 120 |
|
100 | 121 | <div className="mx-1 mb-5 border-t border-slate-200" /> |
101 | 122 |
|
102 | 123 | <section> |
103 | 124 | <div className="mb-2.5 flex items-center justify-between px-1"> |
104 | | - <h3 className="text-[18px] font-semibold tracking-[-0.016em] text-slate-800"> |
| 125 | + <h3 className="text-lg font-semibold tracking-tight text-slate-800"> |
105 | 126 | Node Types |
106 | 127 | </h3> |
107 | | - <span className="text-[13px] font-semibold tabular-nums text-slate-500"> |
108 | | - {NODE_TYPES.length}/{NODE_TYPES.length} |
| 128 | + <span className="text-xs font-semibold tabular-nums text-slate-500"> |
| 129 | + {selectedTypes.size}/{NODE_TYPE_DEFINITIONS.length} |
109 | 130 | </span> |
110 | 131 | </div> |
111 | 132 |
|
112 | 133 | <div className="space-y-1.5"> |
113 | | - {NODE_TYPES.map((type) => ( |
114 | | - <label |
| 134 | + {NODE_TYPE_DEFINITIONS.map((type) => ( |
| 135 | + <Label |
115 | 136 | key={type.candidateTag} |
116 | 137 | className="flex w-full cursor-pointer items-center gap-2.5 rounded-xl border border-slate-200 bg-white px-2.5 py-2.5 text-slate-800 shadow-sm" |
117 | 138 | > |
118 | | - <Checkbox checked /> |
119 | | - <span className="min-w-0 flex-1 text-[16px] font-medium"> |
| 139 | + <Checkbox |
| 140 | + checked={selectedTypes.has(type.candidateTag)} |
| 141 | + onCheckedChange={() => onToggleType(type.candidateTag)} |
| 142 | + /> |
| 143 | + <span className="min-w-0 flex-1 text-base font-medium"> |
120 | 144 | {type.label} |
121 | 145 | </span> |
122 | | - <span className="shrink-0 text-[11px] font-medium text-slate-400"> |
| 146 | + <span className="shrink-0 text-xs font-medium text-slate-400"> |
123 | 147 | {type.candidateTag} |
124 | 148 | </span> |
125 | | - </label> |
| 149 | + </Label> |
126 | 150 | ))} |
127 | 151 | </div> |
128 | 152 | </section> |
129 | 153 | </div> |
130 | 154 |
|
131 | 155 | <div className="border-t border-slate-200/90 bg-white/95 p-4 backdrop-blur-xl"> |
132 | | - <p className="mb-2 text-[14px] font-medium text-slate-500"> |
| 156 | + <p className="mb-2 text-sm font-medium text-slate-500"> |
133 | 157 | Ready to run extraction. |
134 | 158 | </p> |
135 | | - <Button className="w-full rounded-xl bg-slate-900 py-6 text-[17px] font-semibold text-white hover:bg-slate-800"> |
| 159 | + <Button className="w-full rounded-xl bg-slate-900 py-6 text-lg font-semibold text-white hover:bg-slate-800"> |
136 | 160 | Re-Extract |
137 | 161 | </Button> |
138 | 162 | </div> |
|
0 commit comments