-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExplore.jsx
More file actions
233 lines (212 loc) · 7.65 KB
/
Explore.jsx
File metadata and controls
233 lines (212 loc) · 7.65 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
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
// src/pages/public/Shop.jsx
import React, { useState, useEffect, useCallback } from "react";
import { Link } from "react-router-dom";
import { artists as artistsAPI } from "../../api";
import "../../styles/Explore.css";
const Explore = () => {
const [artists, setArtists] = useState([]);
const [filteredArtists, setFilteredArtists] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState("");
const [searchQuery, setSearchQuery] = useState("");
const [filterSpecialization, setFilterSpecialization] = useState("all");
const filterArtists = useCallback(() => {
let filtered = [...artists];
if (searchQuery.trim()) {
const query = searchQuery.toLowerCase();
filtered = filtered.filter(artist => {
const name = artist.userId?.name?.toLowerCase() || "";
const specialization = artist.specialization?.toLowerCase() || "";
const bio = artist.bio?.toLowerCase() || "";
return name.includes(query) ||
specialization.includes(query) ||
bio.includes(query);
});
}
if (filterSpecialization !== "all") {
const specQuery = filterSpecialization.toLowerCase();
filtered = filtered.filter(artist =>
artist.specialization?.toLowerCase().includes(specQuery)
);
}
setFilteredArtists(filtered);
}, [artists, searchQuery, filterSpecialization]);
const fetchArtists = async () => {
try {
setLoading(true);
setError("");
const data = await artistsAPI.getAll();
setArtists(data);
setFilteredArtists(data);
} catch (err) {
console.error("Failed to fetch artists:", err);
setError("Failed to load artists. Please try again later.");
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchArtists();
}, []);
useEffect(() => {
filterArtists();
}, [filterArtists]);
const getSpecializations = () => {
const specs = new Set();
artists.forEach(artist => {
if (artist.specialization) {
specs.add(artist.specialization);
}
});
return Array.from(specs).sort();
};
if (loading) {
return (
<div className="explore-container">
<div className="loading-spinner">
<div className="spinner"></div>
<p>Loading artists...</p>
</div>
</div>
);
}
if (error) {
return (
<div className="explore-container">
<div className="error-container">
<p style={{ color: "red" }}>{error}</p>
<button onClick={fetchArtists} className="retry-btn">
Retry
</button>
</div>
</div>
);
}
return (
<div className="explore-container">
<div className="explore-header">
<h1>Explore Artists</h1>
<p className="explore-subtitle">Discover talented artists and their unique creations</p>
</div>
<div className="search-filter-section">
<div className="search-bar">
<svg
className="search-icon"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
aria-hidden="true"
>
<circle cx="11" cy="11" r="8"></circle>
<path d="m21 21-4.35-4.35"></path>
</svg>
<input
type="search"
placeholder="Search artists by name, specialization, or style..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="search-input"
aria-label="Search artists"
/>
{searchQuery && (
<button
className="clear-search"
onClick={() => setSearchQuery("")}
aria-label="Clear search"
>
✕
</button>
)}
</div>
<div className="filter-dropdown">
<label htmlFor="spec-filter">Filter by Specialization:</label>
<select
id="spec-filter"
value={filterSpecialization}
onChange={(e) => setFilterSpecialization(e.target.value)}
>
<option value="all">All Specializations</option>
{getSpecializations().map((spec, idx) => (
<option key={idx} value={spec}>{spec}</option>
))}
</select>
</div>
</div>
<div className="results-info">
<p aria-live="polite">
{filteredArtists.length === 0
? "No artists found matching your criteria."
: `Showing ${filteredArtists.length} ${filteredArtists.length === 1 ? 'artist' : 'artists'}`
}
</p>
</div>
<div className="explore-grid">
{filteredArtists.length === 0 ? (
<div className="no-results">
<div className="no-results-icon" aria-hidden="true">🔍</div>
<h3>No artists found</h3>
<p>Try adjusting your search or filters.</p>
<button
onClick={() => {
setSearchQuery("");
setFilterSpecialization("all");
}}
className="reset-btn"
>
Reset Filters
</button>
</div>
) : (
filteredArtists.map((artist) => {
const artistName = artist.userId?.name || "Artist";
const profileImage = artist.portfolioImages?.[0] || "https://cdn-icons-png.flaticon.com/512/149/149071.png";
return (
<Link
key={artist._id}
to={`/artist/${artist._id}`}
state={{ artist }}
className="explore-card"
aria-label={`View profile of ${artistName}`}
>
<div className="card-image-container">
<img
src={profileImage}
alt={`${artistName} portfolio preview`}
className="explore-avatar"
loading="lazy"
/>
<div className="card-overlay">
<span className="view-profile-text">View Profile →</span>
</div>
</div>
<div className="card-content">
<h3>{artistName}</h3>
<p className="specialization-badge">{artist.specialization || "Creative Artist"}</p>
{artist.bio && (
<p className="artist-bio">
{artist.bio.length > 80 ? `${artist.bio.substring(0, 80)}...` : artist.bio}
</p>
)}
{artist.portfolioImages?.length > 0 && (
<div className="portfolio-count">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
<circle cx="8.5" cy="8.5" r="1.5"></circle>
<polyline points="21 15 16 10 5 21"></polyline>
</svg>
{artist.portfolioImages.length} {artist.portfolioImages.length === 1 ? 'work' : 'works'}
</div>
)}
</div>
</Link>
);
})
)}
</div>
</div>
);
};
export default Explore;