|
@@ -1,16 +1,42 @@
|
|
|
import { useEffect } from "react";
|
|
|
import { connect } from "react-redux";
|
|
|
-import { actionSnippetById } from "../actions/actionSnippetById";
|
|
|
+import { actionSnippetById } from "./../actions/actionSnippetById";
|
|
|
import { useState } from "react";
|
|
|
import { Editor } from "../components/Editor";
|
|
|
-import { actionSnippetAdd } from "../actions/actionSnippetAdd";
|
|
|
+import "../components/EditorsPage.css";
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
|
+// const [editors, setEditors] = useState(datas);
|
|
|
+// const [title, setTitle] = useState("");
|
|
|
+// const [description, setDescription] = useState("");
|
|
|
+// const [srcDoc, setSrcDoc] = useState("");
|
|
|
+// const [theme, setTheme] = useState();
|
|
|
+// const [font, setFont] = useState();
|
|
|
+
|
|
|
+// useEffect(() => {
|
|
|
+// const timeout = setTimeout(() => {
|
|
|
+// let html, css, javascript;
|
|
|
+// editors.forEach((e) => {
|
|
|
+// if (e.type === "html") html = e.text;
|
|
|
+// if (e.type === "css") css = e.text;
|
|
|
+// if (e.type === "javascript") javascript = e.text;
|
|
|
+// });
|
|
|
+// setSrcDoc(`
|
|
|
+// <html>
|
|
|
+// <body>${html}</body>
|
|
|
+// <style>${css}</style>
|
|
|
+// <script>${javascript}</script>
|
|
|
+// </html>
|
|
|
+// `);
|
|
|
+// }, 250);
|
|
|
+
|
|
|
+// return () => clearTimeout(timeout);
|
|
|
+// }, [editors]);
|
|
|
+
|
|
|
const ProjectSnippet = ({
|
|
|
- onSave,
|
|
|
getSnippet,
|
|
|
match: {
|
|
|
- params: { id },
|
|
|
+ params: { _id },
|
|
|
},
|
|
|
titleText,
|
|
|
descriptionText,
|
|
@@ -18,130 +44,101 @@ const ProjectSnippet = ({
|
|
|
nameText,
|
|
|
}) => {
|
|
|
useEffect(() => {
|
|
|
- getSnippet(id);
|
|
|
- }, []);
|
|
|
- const [files, setFiles] = useState([]);
|
|
|
- const [name, setName] = useState("");
|
|
|
+ getSnippet(_id);
|
|
|
+ }, [_id, getSnippet]);
|
|
|
+ const [editors, setEditors] = useState([]);
|
|
|
const [title, setTitle] = useState("");
|
|
|
const [description, setDescription] = useState("");
|
|
|
useEffect(() => {
|
|
|
- setFiles(filesArr);
|
|
|
+ setEditors(filesArr);
|
|
|
setTitle(titleText);
|
|
|
setDescription(descriptionText);
|
|
|
}, [filesArr, titleText, descriptionText]);
|
|
|
const [srcDoc, setSrcDoc] = useState("");
|
|
|
- const html = files?.filter((el) => {
|
|
|
- return el?.type === "html";
|
|
|
+ const html = editors?.filter((e) => {
|
|
|
+ return e?.type === "html";
|
|
|
})[0]?.text;
|
|
|
- const css = files?.filter((el) => {
|
|
|
- return el?.type === "css";
|
|
|
+ const css = editors?.filter((e) => {
|
|
|
+ return e?.type === "css";
|
|
|
})[0]?.text;
|
|
|
- const js = files?.filter((el) => {
|
|
|
- return el?.type === "javascript";
|
|
|
+ const javascript = editors?.filter((e) => {
|
|
|
+ return e?.type === "javascript";
|
|
|
})[0]?.text;
|
|
|
- console.log(js);
|
|
|
+ console.log(javascript);
|
|
|
useEffect(() => {
|
|
|
const timeout = setTimeout(() => {
|
|
|
setSrcDoc(`
|
|
|
- <html>
|
|
|
- <body>${html || ""}</body>
|
|
|
- <style>${css}</style>
|
|
|
- <script>${js}</script>
|
|
|
- </html>
|
|
|
- `);
|
|
|
+ <html>
|
|
|
+ <body>${html}</body>
|
|
|
+ <style>${css}</style>
|
|
|
+ <script>${javascript}</script>
|
|
|
+ </html>
|
|
|
+ `);
|
|
|
}, 250);
|
|
|
|
|
|
return () => clearTimeout(timeout);
|
|
|
- }, [html, css, js]);
|
|
|
+ }, [html, css, javascript]);
|
|
|
return (
|
|
|
<div>
|
|
|
+ <div>
|
|
|
+ <Link to="/search">
|
|
|
+ <button
|
|
|
+ className="btn_search"
|
|
|
+ style={{ margin: 10, marginBottom: 50 }}
|
|
|
+ >
|
|
|
+ Back to search
|
|
|
+ </button>
|
|
|
+ </Link>
|
|
|
+ </div>
|
|
|
<br />
|
|
|
- {files?.map((data, index) => (
|
|
|
+ {editors?.map((data, index) => (
|
|
|
<>
|
|
|
<Editor
|
|
|
- onDelete={() => setFiles(files?.filter((item) => item !== data))}
|
|
|
+ onDelete={() =>
|
|
|
+ setEditors(editors?.filter((item) => item !== data))
|
|
|
+ }
|
|
|
data={data}
|
|
|
onChange={({ type, name, text }) =>
|
|
|
- setFiles([
|
|
|
- ...files.slice(0, index),
|
|
|
+ setEditors([
|
|
|
+ ...editors.slice(0, index),
|
|
|
{ type, name, text },
|
|
|
- ...files.slice(index + 1),
|
|
|
+ ...editors.slice(index, 1),
|
|
|
])
|
|
|
}
|
|
|
/>
|
|
|
</>
|
|
|
))}
|
|
|
<br />
|
|
|
- <div
|
|
|
- style={{
|
|
|
- alignItems: "center",
|
|
|
- textAlign: "center",
|
|
|
- marginBottom: "10px",
|
|
|
- }}
|
|
|
- >
|
|
|
+ <div>
|
|
|
<div>
|
|
|
- <button
|
|
|
- className="btn btn-primary"
|
|
|
- onClick={() => setFiles([...files, { type: "html" }])}
|
|
|
- key={files}
|
|
|
- >
|
|
|
- Add editor
|
|
|
- </button>
|
|
|
<iframe
|
|
|
+ className="pane"
|
|
|
srcDoc={srcDoc}
|
|
|
title="output"
|
|
|
sandbox="allow-scripts"
|
|
|
frameBorder="0"
|
|
|
+ style={{ marginTop: 20 }}
|
|
|
width="95%"
|
|
|
height="95%"
|
|
|
- style={{
|
|
|
- marginTop: "10px",
|
|
|
- border: "1px solid #F0FFFF",
|
|
|
- boxShadow: "0px 5px 10px 2px rgba(34, 60, 80, 0.2)",
|
|
|
- }}
|
|
|
/>
|
|
|
- <div>
|
|
|
- <Link to="/projects">
|
|
|
- <button className="btn btn-outline-info border-info mt-3">
|
|
|
- All projects
|
|
|
- </button>
|
|
|
- </Link>
|
|
|
- </div>
|
|
|
</div>
|
|
|
- <div className="input-group mb-3 mt-5 ml-auto mr-auto w-25">
|
|
|
- <div className="input-group-prepend">
|
|
|
- <span className="input-group-text" id="basic-addon1">
|
|
|
- Name of your project
|
|
|
- </span>
|
|
|
- </div>
|
|
|
+ <div>
|
|
|
+ <p className="text">Name of your project: </p>
|
|
|
<input
|
|
|
+ className="input_title"
|
|
|
+ placeholder="Name of your project"
|
|
|
value={title}
|
|
|
onChange={(e) => setTitle(e.target.value)}
|
|
|
- type="text"
|
|
|
- className="form-control"
|
|
|
- placeholder="Name of project"
|
|
|
- aria-label="Name of project"
|
|
|
- aria-describedby="basic-addon1"
|
|
|
/>
|
|
|
</div>
|
|
|
- <div className="input-group ml-auto mr-auto w-50">
|
|
|
- <div className="input-group-prepend">
|
|
|
- <span className="input-group-text ">Description</span>
|
|
|
- </div>
|
|
|
- <textarea
|
|
|
- value={description}
|
|
|
- onChange={(e) => setDescription(e.target.value)}
|
|
|
- className="form-control "
|
|
|
- aria-label="With textarea"
|
|
|
- placeholder="Your description"
|
|
|
- ></textarea>
|
|
|
- </div>
|
|
|
- <button
|
|
|
- className="btn btn-success float-right mr-5 mb-5"
|
|
|
- onClick={() => onSave(title, description, files, id)}
|
|
|
- >
|
|
|
- Save project
|
|
|
- </button>
|
|
|
+ <p className="text">Description: </p>
|
|
|
+ <textarea
|
|
|
+ className="text_desc"
|
|
|
+ placeholder="Description"
|
|
|
+ value={description}
|
|
|
+ onChange={(e) => setDescription(e.target.value)}
|
|
|
+ style={{ marginBottom: 50 }}
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|
|
@@ -150,15 +147,12 @@ const ProjectSnippet = ({
|
|
|
const ConnectedProject = connect(
|
|
|
(state) => ({
|
|
|
titleText:
|
|
|
- state?.promise?.findSnippetById?.payload?.data?.SnippetFind?.[0]?.title,
|
|
|
+ state?.p?.findSnippetById?.payload?.data?.SnippetFind?.[0]?.title,
|
|
|
descriptionText:
|
|
|
- state?.promise?.findSnippetById?.payload?.data?.SnippetFind?.[0]
|
|
|
- ?.description,
|
|
|
- nameText:
|
|
|
- state?.promise?.findSnippetById?.payload?.data?.SnippetFind?.[0]?.name,
|
|
|
- filesArr:
|
|
|
- state?.promise?.findSnippetById?.payload?.data?.SnippetFind?.[0]?.files,
|
|
|
+ state?.p?.findSnippetById?.payload?.data?.SnippetFind?.[0]?.description,
|
|
|
+ nameText: state?.p?.findSnippetById?.payload?.data?.SnippetFind?.[0]?.name,
|
|
|
+ filesArr: state?.p?.findSnippetById?.payload?.data?.SnippetFind?.[0]?.files,
|
|
|
}),
|
|
|
- { getSnippet: actionSnippetById, onSave: actionSnippetAdd }
|
|
|
+ { getSnippet: actionSnippetById }
|
|
|
)(ProjectSnippet);
|
|
|
export default ConnectedProject;
|