forked from gmonchain/Cryptoicons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
149 lines (133 loc) · 5.11 KB
/
Copy pathindex.tsx
File metadata and controls
149 lines (133 loc) · 5.11 KB
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
import { useState, useMemo } from 'react';
import { SearchBar } from '../components/SearchBar';
import { Stats } from '../components/Stats';
import { IconCard } from '../components/IconCard';
import { PreviewModal } from '../components/PreviewModal';
import { ToastContainer } from '../components/Toast';
import { useCryptoIcons } from '../hooks/useCryptoIcons';
import { useToast } from '../hooks/useToast';
import { CryptoIcon } from '../types';
import { Loader2 } from 'lucide-react';
export default function HomePage() {
const { icons, loading, error } = useCryptoIcons();
const { toasts, addToast, removeToast } = useToast();
const [searchQuery, setSearchQuery] = useState('');
const [selectedIcon, setSelectedIcon] = useState<CryptoIcon | null>(null);
const [isModalOpen, setIsModalOpen] = useState(false);
const filteredIcons = useMemo(() => {
if (!searchQuery.trim()) return icons;
const query = searchQuery.toLowerCase();
return icons.filter(icon =>
icon.displayName.toLowerCase().includes(query) ||
icon.name.toLowerCase().includes(query) ||
icon.symbol?.toLowerCase().includes(query)
);
}, [icons, searchQuery]);
const handleCopy = async (content: string, name: string) => {
await navigator.clipboard.writeText(content);
addToast(`${name} SVG copied to clipboard!`, 'success');
};
const handleDownload = (icon: CryptoIcon) => {
const link = document.createElement('a');
link.href = icon.path;
link.download = icon.fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
addToast(`${icon.displayName} downloaded!`, 'success');
};
const handlePreview = (icon: CryptoIcon) => {
setSelectedIcon(icon);
setIsModalOpen(true);
};
const handleCloseModal = () => {
setIsModalOpen(false);
setSelectedIcon(null);
};
if (loading) {
return (
<div className="min-h-screen bg-gradient-to-br from-indigo-50 via-white to-purple-50 flex items-center justify-center">
<div className="text-center">
<Loader2 className="w-12 h-12 text-indigo-600 animate-spin mx-auto mb-4" />
<p className="text-gray-600 text-lg">Loading crypto icons...</p>
</div>
</div>
);
}
if (error) {
return (
<div className="min-h-screen bg-gradient-to-br from-indigo-50 via-white to-purple-50 flex items-center justify-center">
<div className="text-center max-w-md">
<div className="bg-red-100 rounded-full p-3 w-16 h-16 mx-auto mb-4 flex items-center justify-center">
<span className="text-red-600 text-2xl">⚠️</span>
</div>
<h2 className="text-xl font-semibold text-gray-900 mb-2">Error Loading Icons</h2>
<p className="text-gray-600">{error}</p>
</div>
</div>
);
}
return (
<div className="min-h-screen bg-gradient-to-br from-indigo-50 via-white to-purple-50">
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
{/* Search Bar */}
<div className="max-w-2xl mx-auto mb-8">
<SearchBar
value={searchQuery}
onChange={setSearchQuery}
placeholder="Search crypto icons by name or symbol..."
/>
</div>
{/* Stats */}
<Stats
totalIcons={icons.length}
filteredIcons={filteredIcons.length}
isFiltered={!!searchQuery.trim()}
/>
{/* Results Info */}
{searchQuery.trim() && (
<div className="mb-6">
<p className="text-gray-600">
{filteredIcons.length > 0
? `Found ${filteredIcons.length} icon${filteredIcons.length === 1 ? '' : 's'} matching "${searchQuery}"`
: `No icons found matching "${searchQuery}"`
}
</p>
</div>
)}
{/* Icons Grid */}
{filteredIcons.length > 0 ? (
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-6">
{filteredIcons.map((icon) => (
<IconCard
key={icon.name}
icon={icon}
onCopy={handleCopy}
onDownload={handleDownload}
onPreview={handlePreview}
/>
))}
</div>
) : searchQuery.trim() ? (
<div className="text-center py-12">
<div className="bg-gray-100 rounded-full p-4 w-20 h-20 mx-auto mb-4 flex items-center justify-center">
<span className="text-gray-400 text-2xl">🔍</span>
</div>
<h3 className="text-lg font-semibold text-gray-900 mb-2">No icons found</h3>
<p className="text-gray-600">Try searching with different keywords or check the spelling.</p>
</div>
) : null}
</main>
{/* Preview Modal */}
<PreviewModal
icon={selectedIcon}
isOpen={isModalOpen}
onClose={handleCloseModal}
onCopy={handleCopy}
onDownload={handleDownload}
/>
{/* Toast Notifications */}
<ToastContainer toasts={toasts} onClose={removeToast} />
</div>
);
}