File size: 8,704 Bytes
5e17e07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c0127c
5e17e07
 
 
 
 
 
 
 
6c0127c
5e17e07
 
 
 
6c0127c
5e17e07
6c0127c
5e17e07
6c0127c
5e17e07
 
 
 
6c0127c
5e17e07
 
 
 
 
 
 
 
 
 
 
6c0127c
5e17e07
 
6c0127c
 
5e17e07
 
 
 
 
6c0127c
5e17e07
 
 
 
 
 
6c0127c
5e17e07
 
 
 
 
6c0127c
5e17e07
 
 
 
6c0127c
 
5e17e07
 
 
 
 
 
 
 
 
 
 
6c0127c
 
 
5e17e07
 
 
 
 
 
 
 
 
 
 
 
 
6c0127c
5e17e07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c0127c
 
5e17e07
 
 
 
 
 
 
 
 
 
 
 
 
 
6c0127c
5e17e07
 
 
 
 
 
 
 
6c0127c
5e17e07
 
 
 
 
 
 
 
 
 
6c0127c
5e17e07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c0127c
5e17e07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c0127c
eb89325
5e17e07
 
 
 
 
 
 
 
6c0127c
 
5e17e07
 
 
 
 
 
6c0127c
5e17e07
 
6c0127c
5e17e07
 
 
 
 
6c0127c
5e17e07
 
 
 
 
 
 
 
 
6c0127c
5e17e07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useRef, useState } from 'react';

interface DocumentManagerProps {
  documents: Array<{ id: string; title: string; filepath: string }>;
  onUpload: (files: FileList) => void;
  onPaste: (text: string, filename: string) => void;
}

function PasteModal({ onClose, onConfirm }: { onClose: () => void; onConfirm: (text: string, filename: string) => void }) {
  const [text, setText] = useState('');
  const [filename, setFilename] = useState('pasted-document.md');

  function handleConfirm() {
    const trimmed = text.trim();
    if (!trimmed) return;
    onConfirm(trimmed, filename.trim() || 'pasted-document.md');
    onClose();
  }

  return (
    <div style={{
      position: 'fixed',
      inset: 0,
      background: 'var(--modal-bg)',
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      zIndex: 1000,
    }}
    onClick={e => { if (e.target === e.currentTarget) onClose(); }}
    >
      <div style={{
        background: 'var(--bg-card)',
        borderRadius: '10px',
        padding: '1.5rem',
        width: '90%',
        maxWidth: '560px',
        boxShadow: '0 8px 32px var(--shadow)',
        fontFamily: 'system-ui, -apple-system, sans-serif',
        border: '1px solid var(--border)',
      }}>
        <h3 style={{ margin: '0 0 1rem 0', fontSize: '1rem', color: 'var(--text)' }}>
          Paste Document
        </h3>

        <div style={{ marginBottom: '0.75rem' }}>
          <label style={{ fontSize: '0.8rem', color: 'var(--text-secondary)', display: 'block', marginBottom: '0.3rem' }}>
            Filename
          </label>
          <input
            type="text"
            value={filename}
            onChange={e => setFilename(e.target.value)}
            style={{
              width: '100%',
              padding: '0.45rem 0.65rem',
              fontSize: '0.85rem',
              fontFamily: "'SF Mono', 'Fira Code', 'Cascadia Code', monospace",
              border: '1px solid var(--input-border)',
              borderRadius: '5px',
              boxSizing: 'border-box',
              background: 'var(--bg-input)',
              color: 'var(--text)',
            }}
          />
        </div>

        <div style={{ marginBottom: '1rem' }}>
          <label style={{ fontSize: '0.8rem', color: 'var(--text-secondary)', display: 'block', marginBottom: '0.3rem' }}>
            Content (Markdown or plain text)
          </label>
          <textarea
            value={text}
            onChange={e => setText(e.target.value)}
            rows={12}
            placeholder="Paste your document content here\u2026"
            style={{
              width: '100%',
              padding: '0.5rem 0.65rem',
              fontSize: '0.8rem',
              fontFamily: "'SF Mono', 'Fira Code', 'Cascadia Code', monospace",
              border: '1px solid var(--input-border)',
              borderRadius: '5px',
              resize: 'vertical',
              boxSizing: 'border-box',
              lineHeight: 1.5,
              background: 'var(--bg-input)',
              color: 'var(--text)',
            }}
          />
        </div>

        <div style={{ display: 'flex', justifyContent: 'flex-end', gap: '0.5rem' }}>
          <button
            onClick={onClose}
            style={{
              padding: '0.5rem 1rem',
              fontSize: '0.85rem',
              fontFamily: 'system-ui, -apple-system, sans-serif',
              background: 'var(--bg-section)',
              color: 'var(--text-secondary)',
              border: '1px solid var(--border)',
              borderRadius: '5px',
              cursor: 'pointer',
            }}
          >
            Cancel
          </button>
          <button
            onClick={handleConfirm}
            disabled={!text.trim()}
            style={{
              padding: '0.5rem 1rem',
              fontSize: '0.85rem',
              fontFamily: 'system-ui, -apple-system, sans-serif',
              background: text.trim() ? '#4285F4' : 'var(--border)',
              color: '#fff',
              border: 'none',
              borderRadius: '5px',
              cursor: text.trim() ? 'pointer' : 'not-allowed',
              fontWeight: 600,
            }}
          >
            Add Document
          </button>
        </div>
      </div>
    </div>
  );
}

export default function DocumentManager({ documents, onUpload, onPaste }: DocumentManagerProps) {
  const fileInputRef = useRef<HTMLInputElement>(null);
  const [pasteOpen, setPasteOpen] = useState(false);

  function handleFileChange(e: React.ChangeEvent<HTMLInputElement>) {
    const files = e.target.files;
    if (files && files.length > 0) {
      onUpload(files);
    }
    e.target.value = '';
  }

  return (
    <div style={{
      padding: '1rem',
      background: 'var(--bg-section)',
      border: '1px solid var(--border)',
      borderRadius: '8px',
      marginBottom: '1.5rem',
      fontFamily: 'system-ui, -apple-system, sans-serif',
    }}>
      <div style={{
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'space-between',
        marginBottom: '0.6rem',
      }}>
        <h3 style={{
          margin: 0,
          fontSize: '0.85rem',
          fontWeight: 600,
          color: 'var(--text-secondary)',
          textTransform: 'uppercase',
          letterSpacing: '0.05em',
        }}>
          Documents
          <span style={{
            marginLeft: '0.5rem',
            fontSize: '0.75rem',
            fontWeight: 400,
            color: 'var(--text-muted)',
          }}>
            ({documents.length})
          </span>
        </h3>
        <div style={{ display: 'flex', gap: '0.4rem' }}>
          <button
            onClick={() => fileInputRef.current?.click()}
            style={{
              padding: '0.3rem 0.7rem',
              fontSize: '0.78rem',
              background: 'var(--bg-card)',
              color: '#4285F4',
              border: '1px solid #4285F4',
              borderRadius: '5px',
              cursor: 'pointer',
              fontFamily: 'system-ui, -apple-system, sans-serif',
              fontWeight: 500,
            }}
          >
            Upload
          </button>
          <button
            onClick={() => setPasteOpen(true)}
            style={{
              padding: '0.3rem 0.7rem',
              fontSize: '0.78rem',
              background: 'var(--bg-card)',
              color: '#34a853',
              border: '1px solid #34a853',
              borderRadius: '5px',
              cursor: 'pointer',
              fontFamily: 'system-ui, -apple-system, sans-serif',
              fontWeight: 500,
            }}
          >
            Paste
          </button>
        </div>
      </div>

      <input
        ref={fileInputRef}
        type="file"
        accept=".md,.txt"
        multiple
        style={{ display: 'none' }}
        onChange={handleFileChange}
      />

      {documents.length === 0 ? (
        <p style={{ fontSize: '0.82rem', color: 'var(--text-muted)', margin: 0 }}>
          No documents loaded. Upload .md or .txt files, or paste text. They stay local to this browser session.
        </p>
      ) : (
        <div style={{ maxHeight: '180px', overflowY: 'auto' }}>
          {documents.map(doc => (
            <div key={doc.id} style={{
              display: 'flex',
              alignItems: 'center',
              padding: '0.35rem 0.6rem',
              background: 'var(--bg-card)',
              border: '1px solid var(--border)',
              borderRadius: '5px',
              marginBottom: '0.3rem',
              gap: '0.5rem',
            }}>
              <span style={{
                fontSize: '0.75rem',
                color: 'var(--text-muted)',
                flexShrink: 0,
              }}>
                {'\u25AA'}
              </span>
              <span style={{
                flex: 1,
                fontSize: '0.8rem',
                fontWeight: 500,
                color: 'var(--text)',
                overflow: 'hidden',
                textOverflow: 'ellipsis',
                whiteSpace: 'nowrap',
              }}>
                {doc.title}
              </span>
              <span style={{
                fontFamily: "'SF Mono', 'Fira Code', 'Cascadia Code', monospace",
                fontSize: '0.68rem',
                color: 'var(--text-muted)',
                flexShrink: 0,
              }}>
                {doc.filepath}
              </span>
            </div>
          ))}
        </div>
      )}

      {pasteOpen && (
        <PasteModal
          onClose={() => setPasteOpen(false)}
          onConfirm={onPaste}
        />
      )}
    </div>
  );
}