fix: download image
This commit is contained in:
parent
8a34ce408e
commit
4496b4d907
@ -14,6 +14,7 @@ import { selectors } from "@/store";
|
|||||||
import { getRandomArbitrary } from "@/services/random-value";
|
import { getRandomArbitrary } from "@/services/random-value";
|
||||||
import Title from "../Title";
|
import Title from "../Title";
|
||||||
import { UserDailyForecast } from "@/api/resources/UserDailyForecasts";
|
import { UserDailyForecast } from "@/api/resources/UserDailyForecasts";
|
||||||
|
import { download } from "@/services/download";
|
||||||
|
|
||||||
const buttonTextFormatter = (text: string): JSX.Element => {
|
const buttonTextFormatter = (text: string): JSX.Element => {
|
||||||
const sentences = text.split(".");
|
const sentences = text.split(".");
|
||||||
@ -83,6 +84,11 @@ function HomePage(): JSX.Element {
|
|||||||
// isPending
|
// isPending
|
||||||
} = useApiCall<UserDailyForecast>(dailyForecastData);
|
} = useApiCall<UserDailyForecast>(dailyForecastData);
|
||||||
|
|
||||||
|
const downloadImg = () => {
|
||||||
|
if( !asset ) return;
|
||||||
|
download(asset.url.replace('http://', 'https://'), 'image.png');
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
className={`${styles.page} page`}
|
className={`${styles.page} page`}
|
||||||
@ -100,8 +106,8 @@ function HomePage(): JSX.Element {
|
|||||||
{aura && <EnergyValues values={aura.stats} />}
|
{aura && <EnergyValues values={aura.stats} />}
|
||||||
</div>
|
</div>
|
||||||
</BlurringSubstrate>
|
</BlurringSubstrate>
|
||||||
<div className={styles["header__save"]}>
|
<div className={styles["header__save"]} onClick={downloadImg}>
|
||||||
<a href={asset?.url.replace('http://', 'https://')} download></a>
|
{/* <a href={asset?.url.replace('http://', 'https://')} download></a> */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
|
|||||||
18
src/services/download/index.ts
Normal file
18
src/services/download/index.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
export const download = (url: string, name: string) => {
|
||||||
|
if (!url) {
|
||||||
|
throw new Error("Resource URL not provided! You need to provide one");
|
||||||
|
}
|
||||||
|
fetch(url)
|
||||||
|
.then((response) => response.blob())
|
||||||
|
.then((blob) => {
|
||||||
|
const blobURL = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = blobURL;
|
||||||
|
a.style.cssText = "display: none";
|
||||||
|
|
||||||
|
if (name && name.length) a.download = name;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
})
|
||||||
|
.catch((e) => console.error(e));
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user