Skip to content

Commit c4fc3f4

Browse files
committed
add image downloading spinner
1 parent 5e92009 commit c4fc3f4

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/components/FindFace/FindFace.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656

5757
.filter-none {
5858
box-shadow: 0 0 0 3px #72bf64 inset;
59-
border-radius: 50%;
6059
}
6160
.filter-blur {
6261
backdrop-filter: blur(20px);

src/components/FindFace/FindFace.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React, { useState, useEffect, useCallback } from 'react';
2+
import Spinner from '../Spinner/Spinner.js';
23
import './FindFace.css';
34

45
const FindFace = ({ imageUrl, onUserDataChange, user }) => {
56
const [faceAreas, setFaceAreas] = useState([]);
67
const [filterType, setFilterType] = useState('none');
8+
const [isDownloading, setIsDownloading] = useState(false);
79

810
const getFaceAreas = useCallback((data) => {
911
if (!data.outputs[0].data.regions) {
@@ -68,6 +70,8 @@ const FindFace = ({ imageUrl, onUserDataChange, user }) => {
6870
}, [fetchFaceData]);
6971

7072
const handleDownload = () => {
73+
setIsDownloading(true);
74+
7175
const img = new Image();
7276
const proxyUrl = 'https://cors-anywhere-api-liwc.onrender.com/proxy?url=';
7377
const proxiedImageUrl = proxyUrl + imageUrl;
@@ -142,11 +146,13 @@ const FindFace = ({ imageUrl, onUserDataChange, user }) => {
142146
link.href = URL.createObjectURL(blob);
143147
link.download = 'filtered_image.png';
144148
link.click();
149+
setIsDownloading(false);
145150
}, 'image/png');
146151
};
147152

148153
img.onerror = () => {
149154
console.error('Failed to load image for processing.');
155+
setIsDownloading(false);
150156
};
151157
};
152158

@@ -165,9 +171,18 @@ const FindFace = ({ imageUrl, onUserDataChange, user }) => {
165171
</button>
166172
))}
167173
</div>
168-
<button onClick={handleDownload} className="mb-5 download-controls">
169-
{'Download Image'}
170-
</button>
174+
<div className="relative mb-5">
175+
<button
176+
onClick={handleDownload}
177+
disabled={isDownloading}
178+
className="download-controls flex items-center"
179+
>
180+
{'Download Image'}
181+
</button>
182+
{isDownloading && (
183+
<Spinner className="absolute -right-2 top-5 translate-x-full -translate-y-1/2" />
184+
)}
185+
</div>
171186
<div className="relative">
172187
<img
173188
src={imageUrl}

src/components/Spinner/Spinner.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
display: flex;
33
align-items: center;
44
justify-content: center;
5-
margin-top: 20px;
65
}
76
/* loader styles inside %PUBLIC_URL%/loader.css */

src/components/Spinner/Spinner.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import React from 'react';
22

33
import './Spinner.css';
44

5-
const Spinner = () => {
5+
const Spinner = ({ className }) => {
66
return (
7-
<div className="spinner-container">
7+
<div
8+
className={
9+
className ? `spinner-container ${className}` : 'spinner-container'
10+
}
11+
>
812
<div className="loader"></div>
913
</div>
1014
);

0 commit comments

Comments
 (0)