LD-Uninstaller/src/pages/TreemapView.tsx

127 lines
5.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useEffect } from 'react';
import { useAppStore } from '../store/useAppStore';
import { HardDrive, RefreshCw, Layers } from 'lucide-react';
export const TreemapView: React.FC = () => {
const { partitions, treemapItems, isLoadingTreemap, loadTreemap, startLeftoverScan, apps } = useAppStore();
useEffect(() => {
loadTreemap();
}, []);
const formatBytes = (bytes: number) => {
const gb = bytes / (1024 * 1024 * 1024);
return `${gb.toFixed(1)} GB`;
};
const handleBlockClick = (name: string) => {
const matchedApp = apps.find((a) => a.display_name === name);
if (matchedApp) {
startLeftoverScan(matchedApp);
}
};
return (
<div className="flex-1 flex flex-col h-full overflow-hidden bg-ld-bg pt-10">
{/* Üst Başlık & Disk Bölümleri */}
<div className="p-4 border-b border-ld-border bg-ld-surface/80 flex items-center justify-between">
<div>
<h2 className="text-xs font-semibold text-slate-100 flex items-center gap-2">
<Layers className="w-4 h-4 text-sky-400" />
Disk Alanı & Squarified Treemap Görselleştirmesi
</h2>
<p className="text-[11px] text-slate-500">Uygulamaların diskte kapladığı alanı görsel olarak inceleyin.</p>
</div>
<button
onClick={() => loadTreemap()}
disabled={isLoadingTreemap}
className="flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-ld-card border border-ld-border text-slate-300 hover:text-white hover:bg-white/5 transition-colors"
>
<RefreshCw className={`w-3.5 h-3.5 ${isLoadingTreemap ? 'animate-spin text-sky-400' : ''}`} />
Yenile
</button>
</div>
<div className="p-4 flex-1 overflow-y-auto space-y-4">
{/* Sürücü Kartları */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
{partitions.map((part) => {
const usedPct = part.total_bytes > 0 ? (part.used_bytes / part.total_bytes) * 100 : 0;
return (
<div key={part.mount_point} className="p-3.5 rounded-xl bg-ld-surface border border-ld-border">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-2">
<HardDrive className="w-4 h-4 text-sky-400" />
<span className="font-semibold text-xs text-slate-200">
Sürücü {part.mount_point} ({part.file_system || 'NTFS'})
</span>
</div>
<span className="text-[11px] font-mono text-slate-400">{usedPct.toFixed(0)}%</span>
</div>
{/* İlerleme Çubuğu */}
<div className="w-full bg-slate-800 rounded-full h-2 overflow-hidden mb-2">
<div
className={`h-full rounded-full transition-all duration-500 ${
usedPct > 90 ? 'bg-rose-500' : usedPct > 75 ? 'bg-amber-400' : 'bg-sky-500'
}`}
style={{ width: `${usedPct}%` }}
/>
</div>
<div className="flex justify-between text-[10px] text-slate-400 font-mono">
<span>Kullanılan: {formatBytes(part.used_bytes)}</span>
<span>Boş: {formatBytes(part.free_bytes)}</span>
<span>Toplam: {formatBytes(part.total_bytes)}</span>
</div>
</div>
);
})}
</div>
{/* Squarified Treemap Alanı */}
<div className="p-4 rounded-xl bg-ld-surface border border-ld-border flex flex-col space-y-3">
<div className="flex items-center justify-between text-xs text-slate-300">
<span className="font-medium">Uygulama Boyut Dağılımı</span>
<span className="text-[11px] text-slate-500">Tıklayarak doğrudan kalıntı taramasını başlatın</span>
</div>
{isLoadingTreemap ? (
<div className="h-80 flex flex-col items-center justify-center space-y-2">
<RefreshCw className="w-6 h-6 text-sky-400 animate-spin" />
<p className="text-xs text-slate-400">Harita oluşturuluyor...</p>
</div>
) : treemapItems.length === 0 ? (
<div className="h-80 flex items-center justify-center text-xs text-slate-500">
Boyut bilgisi olan uygulama bulunamadı.
</div>
) : (
<div className="flex flex-wrap gap-1.5 h-96 p-2 rounded-lg bg-ld-card/50 border border-ld-border/50 overflow-hidden">
{treemapItems.slice(0, 36).map((item) => {
const totalValue = treemapItems.reduce((acc, i) => acc + i.value, 0);
const pct = totalValue > 0 ? (item.value / totalValue) * 100 : 2;
const flexGrow = Math.max(1, Math.round(pct * 2));
return (
<div
key={item.id}
onClick={() => handleBlockClick(item.name)}
style={{
flexGrow,
backgroundColor: item.color,
minWidth: '80px',
minHeight: '60px',
}}
title={`${item.name} (${item.formatted_size}) - Kalıntı taramak için tıklayın`}
className="rounded-md p-2 flex flex-col justify-between cursor-pointer transition-transform hover:scale-[1.02] hover:shadow-lg shadow-black/40 text-slate-950 font-semibold select-none overflow-hidden"
>
<span className="text-xs truncate block">{item.name}</span>
<span className="text-[10px] font-mono opacity-80 block">{item.formatted_size}</span>
</div>
);
})}
</div>
)}
</div>
</div>
</div>
);
};