| // src/components/data-hub/ObjectUploader.tsx | |
| import { useState, useRef } from "react"; | |
| import { X, Upload, Loader2, FileText } from "lucide-react"; | |
| import type { ObjectType, LicenseType } from "@/types/data-hub"; | |
| interface ObjectUploaderProps { | |
| onUpload: (file: File, metadata: any) => void; | |
| onClose: () => void; | |
| uploading: boolean; | |
| progress: number; | |
| } | |
| const LICENSES: LicenseType[] = ["cc-by", "cc0", "mit", "gpl-3.0", "apache-2.0"]; | |
| export function ObjectUploader({ onUpload, onClose, uploading, progress }: ObjectUploaderProps) { | |
| const [file, setFile] = useState<File | null>(null); | |
| const [title, setTitle] = useState(""); | |
| const [description, setDescription] = useState(""); | |
| const [type, setType] = useState<ObjectType>("dataset"); | |
| const [license, setLicense] = useState<LicenseType>("cc-by"); | |
| const [tags, setTags] = useState(""); | |
| const fileRef = useRef<HTMLInputElement>(null); | |
| const handleSubmit = () => { | |
| if (!file || !title.trim()) return; | |
| onUpload(file, { | |
| title: title.trim(), | |
| description, | |
| type, | |
| license, | |
| tags: tags.split(",").map(t => t.trim()).filter(Boolean), | |
| }); | |
| }; | |
| return ( | |
| <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4" onClick={onClose}> | |
| <div className="glass rounded-2xl max-w-md w-full p-6 space-y-4" onClick={e => e.stopPropagation()}> | |
| <div className="flex items-center justify-between"> | |
| <h3 className="font-bold text-lg">Upload Research Object</h3> | |
| <button onClick={onClose} className="text-gray-500"><X className="w-5 h-5"/></button> | |
| </div> | |
| <div className="border-2 border-dashed border-white/30 rounded-xl p-6 text-center cursor-pointer" onClick={() => fileRef.current?.click()}> | |
| <input ref={fileRef} type="file" className="hidden" onChange={e => setFile(e.target.files?.[0] ?? null)} /> | |
| {file ? <div className="flex items-center justify-center gap-2 text-primary"><FileText className="w-5 h-5"/>{file.name}</div> : <><Upload className="w-8 h-8 text-gray-400 mx-auto mb-2"/><p className="text-sm text-gray-500">Click to select file</p></>} | |
| </div> | |
| <input type="text" value={title} onChange={e => setTitle(e.target.value)} placeholder="Title *" className="input" /> | |
| <textarea value={description} onChange={e => setDescription(e.target.value)} placeholder="Description" className="input" rows={2} /> | |
| <div className="grid grid-cols-2 gap-3"> | |
| <select aria-label="Select option" value={type} onChange={e => setType(e.target.value as ObjectType)} className="input"> | |
| {Object.keys(TYPE_ICONS).map(k => <option key={k} value={k}>{k}</option>)} | |
| </select> | |
| <select aria-label="Select option" value={license} onChange={e => setLicense(e.target.value as LicenseType)} className="input"> | |
| {LICENSES.map(l => <option key={l} value={l}>{l}</option>)} | |
| </select> | |
| </div> | |
| <input type="text" value={tags} onChange={e => setTags(e.target.value)} placeholder="Tags (comma-separated)" className="input" /> | |
| {uploading && ( | |
| <div className="h-1.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden"> | |
| <div className="h-full bg-primary rounded-full" style={{ width: `${progress}%` }} /> | |
| </div> | |
| )} | |
| <button onClick={handleSubmit} disabled={!file || !title.trim() || uploading} className="btn btn-primary w-full gap-2"> | |
| {uploading ? <Loader2 className="w-4 h-4 animate-spin"/> : <Upload className="w-4 h-4"/>} | |
| {uploading ? `Uploading ${progress}%` : "Upload & Assign DOI"} | |
| </button> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| import { TYPE_ICONS } from "./RepositoryBrowser"; // reuse |
Xet Storage Details
- Size:
- 3.75 kB
- Xet hash:
- 3f5de06e469c3bef8ed82609139d8cab7ae82b4d192775e368375716ac385aa2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.