Skip to content

Commit

Permalink
codeError:
Browse files Browse the repository at this point in the history
  • Loading branch information
tikrack committed Feb 8, 2025
1 parent 30119b2 commit f1c5867
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
26 changes: 16 additions & 10 deletions src/components/config/SalamConfig.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,23 @@ const SalamConfig = () => {
},
};

window.downloadIframeHTML = () => {
let iframe = document.querySelector("iframe");
let iframeDocument =
iframe.contentDocument || iframe.contentWindow.document;
let htmlContent = iframeDocument.documentElement.outerHTML;
window.downloadIframeHTML = (isTrue) => {
if (isTrue === false) {
toast.error("کد دارای ارور است");
}

let blob = new Blob([htmlContent], { type: "text/html" });
let link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "output.html";
link.click();
if (isTrue === true) {
let iframe = document.querySelector("iframe");
let iframeDocument =
iframe.contentDocument || iframe.contentWindow.document;
let htmlContent = iframeDocument.documentElement.outerHTML;

let blob = new Blob([htmlContent], { type: "text/html" });
let link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "output.html";
link.click();
}
};
}, [location]);

Expand Down
7 changes: 4 additions & 3 deletions src/components/header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import SaveCode from "../shared/Feautres/SaveCode.jsx";
import Share from "./Share.jsx";
import Setting from "../shared/Setting.jsx";
import { useTranslation } from "react-i18next";
import TrueContext from "../../context/TrueContext.jsx";

const Header = () => {
const navigate = useNavigate();
const { login } = useContext(LoginContext);
const { t } = useTranslation();

const { isTrue } = useContext(TrueContext);
const [openSave, setOpenSave] = useState(false);
const [openSetting, setOpenSetting] = useState(false);
const params = useParams();
Expand All @@ -39,13 +40,13 @@ const Header = () => {
<DropdownItem
title={t("exportSalamFile")}
callback={() => {
handleSaveFile();
handleSaveFile(isTrue);
}}
/>
<DropdownItem
title={t("exportSite")}
callback={() => {
window.downloadIframeHTML();
window.downloadIframeHTML(isTrue);
}}
/>
<DropdownItem
Expand Down
28 changes: 18 additions & 10 deletions src/components/shared/Feautres/Features.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { toast } from "react-hot-toast";
import { useNavigate } from "react-router-dom";
import { useContext } from "react";
import TrueContext from "../../../context/TrueContext.jsx";

export const handleFileChange = (event) => {
const file = event.target.files[0];
Expand All @@ -25,16 +27,22 @@ export const openFilePicker = () => {
document.getElementById("fileInput").click();
};

export const handleSaveFile = () => {
const fileName = "myFile.salam";
const fileContent = localStorage.getItem("code") ?? "";
const blob = new Blob([fileContent], { type: "text/plain;charset=utf-8" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = fileName;
link.click();
URL.revokeObjectURL(url);
export const handleSaveFile = (isTrue) => {
if (isTrue === false) {
toast.error("کد دارای ارور است.");
}

if (isTrue === true) {
const fileName = "myFile.salam";
const fileContent = localStorage.getItem("code") ?? "";
const blob = new Blob([fileContent], { type: "text/plain;charset=utf-8" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = fileName;
link.click();
URL.revokeObjectURL(url);
}
};

export const changeTheme = () => {
Expand Down
2 changes: 2 additions & 0 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const resources = {
nameRequire: "Name Cannot Be Empty",
familyRequire: "Family Cannot Be Empty",
saved: "Save Successfully.",
codeError: "Your Code Have A Bug.",
},
},
fa: {
Expand Down Expand Up @@ -62,6 +63,7 @@ const resources = {
nameRequire: "نام نباید خالی باشد.",
familyRequire: "نام خانوادگی نباید خالی باشد.",
saved: "ذخیره شد.",
codeError: "کد دارای خروجی است.",
},
},
};
Expand Down

0 comments on commit f1c5867

Please sign in to comment.