Skip to content

Commit

Permalink
feat(import): add import file feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamadreza1388 committed Jan 6, 2025
1 parent 45f5cab commit b1fb933
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/components/editor/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useEffect, useState} from "react";
import "../../scripts/codemirror.js"
import EditorService from "../../services/EditorService.js";
import { Rnd } from "react-rnd";
import {useLocation} from "react-router-dom";

const salamAdd = () => {
const script = document.createElement('script');
Expand All @@ -16,8 +17,14 @@ const salamAdd = () => {
const Editor = () => {
const [size, setSize] = useState({ width: 300, height: 200 });
const [position, setPosition] = useState({ x: 50, y: 50 });
const location = useLocation()

useEffect(() => {
const editor = document.querySelector("#editor");
if (editor) {
editor.innerHTML = "";
}

// salamAdd();
EditorService(() => {
return [{
Expand All @@ -31,7 +38,7 @@ const Editor = () => {
}, (updateText) => {
// SalamService(updateText);
})
}, [])
}, [location])

return (<>
<main
Expand Down
13 changes: 10 additions & 3 deletions src/components/header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ import Dropdown from "../shared/dropdown/Dropdown.jsx";
import DropdownItem from "../shared/dropdown/DropdownItem.jsx";
import {useState} from "react";
import {toast} from "react-toastify";
import {useNavigate} from "react-router-dom";

const Header = () => {
const [fileContent, setFileContent] = useState("");
const navigate = useNavigate()

// Read File
const handleFileChange = (event) => {
const file = event.target.files[0];
if (file) {
if (file.name.endsWith(".salam")) {
const reader = new FileReader();
reader.onload = (e) => {
setFileContent(e.target.result);
toast.success("فایل وارد شد" , {
toast.success("فایل وارد شد", {
position: "bottom-right",
})
localStorage.setItem("code", e.target.result);
navigate("/")
};
reader.readAsText(file);
} else {
toast.error("فرمت فایل وارد شده اشتباه است." , {
toast.error("فرمت فایل وارد شده اشتباه است.", {
position: "bottom-right",
})
}
}
};

const openFilePicker = () => {
document.getElementById("fileInput").click();
};

// Export file


return (<>
<header
Expand All @@ -38,6 +44,7 @@ const Header = () => {
<DropdownItem title={"باز کردن فایل"} callback={() => {
openFilePicker()
}}/>
{/*<hr className={"opacity-100 bg-gray-300 my-2 h-[1px] border-0"}/>*/}
</Dropdown>
</header>
<input
Expand Down

0 comments on commit b1fb933

Please sign in to comment.