Skip to content

Commit 04aa0cc

Browse files
fix mobiel
1 parent 197342d commit 04aa0cc

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

src/components/Card.tsx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { useEffect, useState } from "react";
22
import { type Paper } from "@/interface";
33
import Image from "next/image";
4-
import { Eye, Download } from "lucide-react";
4+
import { Eye } from "lucide-react";
55
import {
66
extractBracketContent,
77
extractWithoutBracketContent,
88
} from "@/util/utils";
99
import { capsule } from "@/util/utils";
10-
import axios from "axios";
1110
import { useRouter } from "next/navigation";
1211
import Link from "next/link";
1312

@@ -27,31 +26,11 @@ const Card = ({
2726
setChecked(isSelected);
2827
}, [isSelected]);
2928

30-
const handleDownload = async (paper: Paper) => {
31-
const extension = paper.finalUrl.split(".").pop();
32-
const fileName = `${extractBracketContent(paper.subject)}-${paper.exam}-${paper.slot}-${paper.year}.${extension}`;
33-
await downloadFile(paper.finalUrl, fileName);
34-
};
35-
3629
function handleCheckboxChange() {
3730
setChecked(!checked);
3831
onSelect(paper, !checked);
3932
}
4033

41-
async function downloadFile(url: string, filename: string) {
42-
try {
43-
const response = await axios.get(url, { responseType: "blob" });
44-
const blob = new Blob([response.data]);
45-
const link = document.createElement("a");
46-
link.href = window.URL.createObjectURL(blob);
47-
link.download = filename;
48-
link.click();
49-
window.URL.revokeObjectURL(link.href);
50-
} catch (error) {
51-
console.error("Error downloading file:", error);
52-
}
53-
}
54-
5534
function handleOpen() {
5635
const storedPapers = JSON.parse(
5736
localStorage.getItem("clickedPapers") ?? "[]",
@@ -106,8 +85,18 @@ const Card = ({
10685
</div>
10786
<div className="flex gap-2">
10887
<Eye size={20} className="cursor-pointer" onClick={handleOpen} />
109-
<button onClick={() => handleDownload(paper)}>
110-
<Download size={20} />
88+
<button
89+
onClick={() => {
90+
const iframe = document.createElement("iframe");
91+
iframe.style.display = "none";
92+
iframe.src = paper.finalUrl;
93+
document.body.appendChild(iframe);
94+
setTimeout(() => {
95+
document.body.removeChild(iframe);
96+
}, 1000);
97+
}}
98+
>
99+
Download
111100
</button>
112101
</div>
113102
</div>

0 commit comments

Comments
 (0)