|
1 | 1 | import { useState } from 'react';
|
2 |
| -import ProjectCard from '../ProjectCard/ProjectCard'; |
3 | 2 | import './_ProjectsSection.scss';
|
4 | 3 | import { getJSON } from '/src/utils/projects/tarjetasAssets';
|
5 | 4 | import Project from '../Project/Project';
|
6 | 5 | import { useEffect } from 'react';
|
| 6 | +import Loader from '../Loader/Loader'; |
7 | 7 |
|
8 | 8 | export default function ProjectsSection() {
|
9 | 9 | const [category, setCategory] = useState('web');
|
10 |
| - const [project, setProject] = useState({}); |
11 | 10 | const [tarjetasAssets, setTarjetasAssets] = useState({});
|
| 11 | + const [isLoading, setIsLoading] = useState(true); |
12 | 12 |
|
13 | 13 | useEffect(() => {
|
14 |
| - getJSON('/assets/json/tarjetaAssets.json').then(assets => |
15 |
| - setTarjetasAssets(assets) |
16 |
| - ); |
| 14 | + setIsLoading(true); |
| 15 | + getJSON('/assets/json/tarjetaAssets.json').then(assets => { |
| 16 | + setTarjetasAssets(assets); |
| 17 | + setTimeout(() => setIsLoading(false), 500); |
| 18 | + }); |
17 | 19 | }, []);
|
18 | 20 |
|
19 |
| - const categoryEntries = Object.entries(tarjetasAssets).filter( |
20 |
| - ([, v]) => v.category === category |
21 |
| - ); |
| 21 | + const categoryEntries = e => |
| 22 | + Object.entries(tarjetasAssets).filter(([, v]) => v.category === e); |
22 | 23 |
|
23 | 24 | const handleSetCategory = e => {
|
24 | 25 | const category = e.target.id;
|
@@ -50,8 +51,24 @@ export default function ProjectsSection() {
|
50 | 51 | </li>
|
51 | 52 | </ul>
|
52 | 53 |
|
53 |
| - <div id={`trabajos-${category}`} className="trabajos-container"> |
54 |
| - {categoryEntries.map(([key, value]) => ( |
| 54 | + {isLoading && <Loader />} |
| 55 | + |
| 56 | + <div |
| 57 | + className="trabajos-container" |
| 58 | + style={{ display: !isLoading && category === 'web' ? 'grid' : 'none' }} |
| 59 | + > |
| 60 | + {categoryEntries('web').map(([key, value]) => ( |
| 61 | + <Project key={key} name={key} project={value} /> |
| 62 | + ))} |
| 63 | + </div> |
| 64 | + |
| 65 | + <div |
| 66 | + className="trabajos-container" |
| 67 | + style={{ |
| 68 | + display: !isLoading && category === 'movil' ? 'grid' : 'none' |
| 69 | + }} |
| 70 | + > |
| 71 | + {categoryEntries('movil').map(([key, value]) => ( |
55 | 72 | <Project key={key} name={key} project={value} />
|
56 | 73 | ))}
|
57 | 74 | </div>
|
|
0 commit comments