|
1 | | -// @ts-nocheck |
2 | | -import styles from "./FileExplorer.module.css"; |
3 | | -// import { IEditorState } from "../../utils/types"; |
| 1 | +import { FC, useContext } from "react"; |
4 | 2 | import { MdDeleteForever } from "react-icons/md";
|
5 | 3 | import { AiOutlineFileAdd } from "react-icons/ai";
|
6 | | -import { FC, useContext } from "react"; |
7 | 4 | import { AppContext } from "../context";
|
| 5 | +import styles from "./FileExplorer.module.css"; |
8 | 6 |
|
9 | 7 | const FileExplorer: FC = () => {
|
10 | 8 | const { username, editorState, setEditorState, code, setCode, io } =
|
11 | 9 | useContext(AppContext);
|
12 | | -// console.log("FE Page", { editorState, setEditorState, code, setCode }); |
13 | | - const handleActive = (e: React.MouseEventHandler<HTMLDivElement>) => { |
14 | | - const filename = e.target.innerText; |
| 10 | + |
| 11 | + const handleActive = (e: React.MouseEvent<HTMLDivElement>) => { |
| 12 | + const filename = (e.targetasHTMLDivElement).innerText; |
15 | 13 | if (e.isTrusted) {
|
16 | | - const args = { activeTab: filename }; |
| 14 | + const args: any = { activeTab: filename }; |
17 | 15 | if (!editorState.tabs.includes(filename)) {
|
18 | 16 | args.tabs = [...editorState.tabs, filename];
|
19 | 17 | }
|
20 | 18 | setEditorState((prev) => ({ ...prev, ...args }));
|
21 | 19 | }
|
22 | 20 | };
|
23 | 21 |
|
24 | | - const handlDeleteFile = (e) => { |
| 22 | + const handlDeleteFile = (e: React.MouseEvent<HTMLDivElement>) => { |
25 | 23 | e.stopPropagation();
|
26 | | - console.log("del file", e); |
27 | | - const filename = e.target.parentElement.innerText; |
| 24 | + const filename = (e.target as HTMLDivElement).parentElement!.innerText; |
28 | 25 | if (e.isTrusted && window.confirm(`Delete file ${filename}?`) === true) {
|
29 | | - const args = {}; |
| 26 | + const args: any = {}; |
30 | 27 | args.tabs = [...editorState.tabs.filter((tab) => tab !== filename)];
|
31 | 28 | args.files = [...editorState.files.filter((file) => file !== filename)];
|
32 | 29 | args.activeTab = args.tabs[0] === undefined ? "" : args.tabs[0];
|
33 | 30 | const newCode = code;
|
34 | 31 | delete newCode[filename];
|
35 | 32 | console.log("nc>", newCode, filename);
|
36 | 33 | setCode({ ...newCode });
|
37 | | - // console.log(args.tabs, filename); |
38 | | - // console.log({ ...editorState, ...args }); |
39 | | - |
40 | 34 | setEditorState((prev) => ({ ...prev, ...args }));
|
41 | | - |
42 | | - // emit code and editor state to backend |
43 | | - io.current.emit("delete_file", username, filename); |
| 35 | + io.current?.emit("delete_file", username, filename); |
44 | 36 | }
|
45 | 37 | };
|
46 | 38 |
|
47 | | - const handleFileCreate = (e) => { |
48 | | - console.log("create file"); |
| 39 | + const handleFileCreate = (e: React.MouseEvent<HTMLDivElement>) => { |
49 | 40 | if (e.isTrusted) {
|
50 | 41 | const filename = prompt("Enter filename");
|
51 | | - console.log("fn>>>", filename, typeof filename); |
52 | 42 | if (!filename) return;
|
53 | | - const args = {}; |
| 43 | + const args: any = {}; |
54 | 44 | args.tabs = [...editorState.tabs, filename];
|
55 | 45 | args.files = [...editorState.files, filename];
|
56 | 46 | args.activeTab = filename;
|
57 | 47 | const newCode = code;
|
58 | 48 | newCode[filename] = "";
|
59 | | - // console.log("nc>", newCode, filename); |
60 | 49 | setCode({ ...newCode });
|
61 | | - // console.log(args.tabs, filename); |
62 | | - // console.log({ ...editorState, ...args }); |
63 | | - |
64 | 50 | setEditorState((prev) => ({ ...prev, ...args }));
|
65 | | - |
66 | | - // emit code and editor state to backend |
67 | | - io.current.emit("create_file", username, filename); |
| 51 | + io.current?.emit("create_file", username, filename); |
68 | 52 | }
|
69 | 53 | };
|
| 54 | + |
70 | 55 | return (
|
71 | 56 | <div className={styles.explorer__container}>
|
72 | 57 | <div className={styles.explorer__bar}>
|
|
0 commit comments