Spaces:
Runtime error

Maximm7's picture
Upload components/Sidebar.jsx with huggingface_hub
8f05b63 verified
Raw History Blame Contribute Delete
6.9 kB
import React from 'react'
import { Upload, Download, Trash2, MousePointer, Minus, ArrowUpDown, Square, TrendingUp, Sun, Moon, Type, Settings } from 'lucide-react'
import { Button } from './ui/button'
import { Separator } from './ui/separator'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './ui/tooltip'
const Sidebar = ({
onFileUpload,
onReset,
activeTool,
setActiveTool,
theme,
setTheme,
chartType,
setChartType,
currentSymbol,
symbolData,
onDownloadSample,
onNavigateToDate
}) => {
const [dateInput, setDateInput] = React.useState('')
const fileInputRef = React.useRef(null)
const tools = [
{ id: 'cursor', icon: MousePointer, label: 'Курсор' },
{ id: 'horizontal', icon: Minus, label: 'Горизонтальна лінія' },
{ id: 'vertical', icon: ArrowUpDown, label: 'Вертикальна лінія' },
{ id: 'rectangle', icon: Square, label: 'Прямокутник' },
{ id: 'fibonacci', icon: TrendingUp, label: 'Фібоначчі' },
]
const chartTypes = [
{ id: 'candlestick', label: 'Свічки' },
{ id: 'line', label: 'Лінія' },
{ id: 'area', label: 'З областю' },
]
const handleFileChange = (e) => {
const file = e.target.files?.[0]
if (file) onFileUpload(file)
e.target.value = ''
}
const handleNavigate = () => {
if (dateInput) {
onNavigateToDate(dateInput)
setDateInput('')
}
}
return (
<div className="w-full h-full flex flex-col bg-card border-r overflow-hidden">
<div className="p-4 flex-1 overflow-y-auto space-y-6">
<div className="space-y-2">
<h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Дані</h3>
<div className="space-y-2">
<Button
variant="outline"
className="w-full justify-start gap-2"
onClick={() => fileInputRef.current?.click()}
>
<Upload className="h-4 w-4" />
Завантажити CSV
</Button>
<input
ref={fileInputRef}
type="file"
accept=".csv"
className="hidden"
onChange={handleFileChange}
/>
<Button
variant="outline"
className="w-full justify-start gap-2"
onClick={onDownloadSample}
>
<Download className="h-4 w-4" />
Зразок CSV
</Button>
<Button
variant="outline"
className="w-full justify-start gap-2 text-destructive hover:text-destructive"
onClick={onReset}
>
<Trash2 className="h-4 w-4" />
Очистити
</Button>
</div>
</div>
<Separator />
<div className="space-y-2">
<h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Тип графіка</h3>
<div className="flex flex-col gap-1">
{chartTypes.map((type) => (
<Button
key={type.id}
variant={chartType === type.id ? 'secondary' : 'ghost'}
size="sm"
className="w-full justify-start"
onClick={() => setChartType(type.id)}
>
{type.label}
</Button>
))}
</div>
</div>
<Separator />
<div className="space-y-2">
<h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Інструменти малювання</h3>
<div className="grid grid-cols-2 gap-1">
<TooltipProvider>
{tools.map((tool) => (
<Tooltip key={tool.id}>
<TooltipTrigger asChild>
<Button
variant={activeTool === tool.id ? 'secondary' : 'ghost'}
size="icon"
className="w-full h-9"
onClick={() => setActiveTool(activeTool === tool.id ? 'cursor' : tool.id)}
>
<tool.icon className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent>
<p>{tool.label}</p>
</TooltipContent>
</Tooltip>
))}
</TooltipProvider>
</div>
</div>
<Separator />
<div className="space-y-2">
<h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Навігація</h3>
<div className="space-y-2">
<div className="flex gap-2">
<input
type="datetime-local"
value={dateInput}
onChange={(e) => setDateInput(e.target.value)}
className="flex-1 h-9 rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
/>
<Button size="sm" onClick={handleNavigate}>
Перейти
</Button>
</div>
</div>
</div>
<Separator />
<div className="space-y-2">
<h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Налаштування</h3>
<Button
variant="outline"
size="sm"
className="w-full justify-start gap-2"
onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
>
{theme === 'dark' ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}
{theme === 'dark' ? 'Світла тема' : 'Темна тема'}
</Button>
</div>
</div>
<div className="p-4 border-t bg-muted/50">
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<Type className="h-3 w-3" />
{currentSymbol ? (
<span className="font-medium">{currentSymbol}</span>
) : (
<span>Немає даних</span>
)}
</div>
{symbolData && (
<div className="mt-2 grid grid-cols-2 gap-x-2 gap-y-1 text-xs text-muted-foreground">
<span>O: {symbolData.open?.toFixed(2)}</span>
<span>H: {symbolData.high?.toFixed(2)}</span>
<span>L: {symbolData.low?.toFixed(2)}</span>
<span>C: {symbolData.close?.toFixed(2)}</span>
</div>
)}
</div>
</div>
)
}
export default Sidebar