Skip to content

Commit

Permalink
Merge pull request #49 from philippetedajo/fix
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
philippetedajo authored Jul 10, 2021
2 parents 6ef5754 + 2669dc5 commit 9d2b352
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 75 deletions.
5 changes: 3 additions & 2 deletions _types/editorTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface LanguagePropsInterface {
title: string;
monacoLanguage: string;
data: string;
transformer: string;
}

export interface IObjectKeys {
Expand All @@ -17,5 +18,5 @@ export interface EditorValueInterface {
name: string;
description: string;
public: boolean;
languages: LanguagesInterface;
tabs: LanguagesInterface;
}
151 changes: 101 additions & 50 deletions constants/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ export const treeTemplates = {
description: "By codetree",
public: true,
iconSrc: "/icons/vanilla.svg",
languages: {
tabs: {
javascript: {
title: "Js/Jsx",
monacoLanguage: "javascript",
data: ``,
transformer: "javascript",
},
css: {
html: {
title: "Html",
monacoLanguage: "html",
data: ``,
transformer: "css",
},
html: {
css: {
title: "Css",
monacoLanguage: "css",
data: ``,
transformer: "html",
},
},
},
Expand All @@ -24,50 +27,37 @@ export const treeTemplates = {
description: "By codetree",
public: true,
iconSrc: "/icons/vanilla.svg",
languages: {
tabs: {
javascript: {
data: `import gsap from "gsap"
var tl = gsap.timeline({ repeat: -1 });
tl.to("h1", 30, { backgroundPosition: "-960px 0" });
title: "Js/Jsx",
monacoLanguage: "javascript",
data: `document.getElementById("app").innerHTML = \`
<h1>Vanilla</h1>
<div>
Bare minimal javascript template
</div>
\`;
`,
transformer: "js",
},
html: {
data: `<div class="wrapper">
<h1 class="title">Codetree<h1>
</div> `,
transformer: "html",
title: "Html",
monacoLanguage: "html",
data: `<div id="app"></div>`,
},
css: {
css: {
title: "Css",
monacoLanguage: "css",
data: `body {
background-color: #1d1d1d;
margin: 0;
padding: 0;
font-family: sans-serif;
}
.wrapper {
#app {
display: flex;
height: 100vh;
flex-direction: column;
justify-content: center;
align-items: center;
}
h1 {
max-width: 75%;
font-size: 100px;
text-align: center;
font-family: "Montserrat", sans-serif;
color: #540032;
}
.title {
background-image: url(https://cdn.pixabay.com/photo/2017/07/03/20/17/abstract-2468874_960_720.jpg);
background-attachment: fixed;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
}`,
transformer: "css",
`,
},
},
},
Expand All @@ -76,8 +66,10 @@ h1 {
description: "By codetree",
public: true,
iconSrc: "/icons/p5-dot-js.svg",
languages: {
tabs: {
javascript: {
title: "Js/Jsx",
monacoLanguage: "javascript",
data: `import p5 from "p5";
let sketch = function (p) {
Expand All @@ -94,9 +86,15 @@ let sketch = function (p) {
new p5(sketch, window.document.getElementById("container"));
`,
transformer: "javascript",
},
html: {
title: "Html",
monacoLanguage: "html",
data: ``,
},
css: {
title: "Css",
monacoLanguage: "css",
data: `body {
margin: 0px;
font-family: sans-serif;
Expand All @@ -105,11 +103,6 @@ canvas {
margin: 0px;
}
`,
transformer: "css",
},
html: {
data: ``,
transformer: "html",
},
},
},
Expand All @@ -118,8 +111,10 @@ canvas {
description: "By codetree",
public: true,
iconSrc: "/icons/reactjs.svg",
languages: {
tabs: {
javascript: {
title: "Js/Jsx",
monacoLanguage: "javascript",
data: `import React, { useState } from "react";
import ReactDOM from "react-dom";
Expand All @@ -140,19 +135,75 @@ function App() {
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
`,
transformer: "javascript",
},
html: {
title: "Html",
monacoLanguage: "html",
data: ``,
},
css: {
title: "Css",
monacoLanguage: "css",
data: `.App {
font-family: sans-serif;
text-align: center;
}
`,
transformer: "css",
},
},
},
_gsap: {
name: "Gsap",
description: "By codetree",
public: true,
iconSrc: "/icons/gsap-greensock.svg",
tabs: {
javascript: {
title: "Js/Jsx",
monacoLanguage: "javascript",
data: `import gsap from "gsap"
var tl = gsap.timeline({ repeat: -1 });
tl.to("h1", 30, { backgroundPosition: "-960px 0" });
`,
},
html: {
data: ``,
transformer: "html",
title: "Html",
monacoLanguage: "html",
data: `<div class="wrapper">
<h1 class="title">Codetree<h1>
</div> `,
},
css: {
title: "Css",
monacoLanguage: "css",
data: `body {
background-color: #1d1d1d;
margin: 0;
padding: 0;
}
.wrapper {
display: flex;
height: 100vh;
justify-content: center;
align-items: center;
}
h1 {
max-width: 75%;
font-size: 100px;
text-align: center;
font-family: "Montserrat", sans-serif;
color: #540032;
}
.title {
background-image: url(https://cdn.pixabay.com/photo/2017/07/03/20/17/abstract-2468874_960_720.jpg);
background-attachment: fixed;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
}`,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions public/icons/gsap-greensock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/typescript.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion store/features/editorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const editorSlice = createSlice({
state.editorValue = payload;
},
update_editor_code: (state: InitialStateType, { payload }) => {
state.editorValue.languages[payload.type].data = payload.content;
state.editorValue.tabs[payload.type].data = payload.content;
},
update_logs: (state: InitialStateType, { payload }) => {
state.logs = [...state.logs, payload];
Expand Down
18 changes: 10 additions & 8 deletions ui/EditorInput.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React from "react";
import Tabs, { TabPane } from "rc-tabs";
import { Monaco } from "./Monaco";
import { useAppSelector } from "../store/hook";
import { editor_state } from "../store/features/editorSlice";

export const EditorInput = () => {
const data = [
{ title: "Js", lang: "javascript" },
{ title: "Html", lang: "html" },
{ title: "Css", lang: "css" },
];
const { editorValue } = useAppSelector(editor_state);

const tabPane = data.map((item) => (
<TabPane tab={<div>{item.title}</div>} key={item.lang}>
<Monaco language={item.lang} />
const dataToMap = Object.entries(editorValue.tabs);

console.log(dataToMap);

const tabPane = dataToMap.map((item, key) => (
<TabPane tab={<div>{item[1].title}</div>} key={key}>
<Monaco tab={item[0]} monacoLanguage={item[1].monacoLanguage} />
</TabPane>
));

Expand Down
13 changes: 5 additions & 8 deletions ui/IFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ export const IFrame = () => {
const iframe = useRef<any>();
const dispatch = useAppDispatch();
const {
editorValue: { languages },
editorValue: { tabs },
} = useAppSelector(editor_state);

const { output, isCompiling } = useAppSelector(compiler_state);

const htmlFrameContent = createIframeContent(
languages.css.data,
languages.html.data
);
const htmlFrameContent = createIframeContent(tabs.css.data, tabs.html.data);

useEffect(() => {
//=== incoming message
Expand All @@ -38,15 +35,15 @@ export const IFrame = () => {
};

//=== outgoing massage
if (languages.javascript.data) {
if (tabs.javascript.data) {
iframe.current.srcdoc = htmlFrameContent;

setTimeout(async () => {
dispatch(getCompileCode(languages.javascript.data));
dispatch(getCompileCode(tabs.javascript.data));
iframe?.current?.contentWindow?.postMessage(output.code, "*");
}, 50);
}
}, [dispatch, languages, htmlFrameContent, output]);
}, [dispatch, tabs, htmlFrameContent, output]);

return (
<div>
Expand Down
14 changes: 8 additions & 6 deletions ui/Monaco.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import React, { useEffect } from "react";
import MonacoEditor, { EditorProps } from "@monaco-editor/react";
import MonacoEditor from "@monaco-editor/react";
import { useMonaco } from "../hooks";
import { useAppDispatch, useAppSelector } from "../store/hook";
import {
editor_state,
update_editor_code,
} from "../store/features/editorSlice";

export const Monaco = ({ language }: EditorProps) => {
type MonacoType = { monacoLanguage: string | undefined; tab: string };

export const Monaco = ({ monacoLanguage, tab }: MonacoType) => {
const dispatch = useAppDispatch();
const { monacoInputValue, options } = useAppSelector(editor_state);
const { onChange, onMount, code } = useMonaco();

useEffect(() => {
if (code && code?.length >= 1)
dispatch(update_editor_code({ type: language, content: code }));
}, [code, dispatch, language]);
dispatch(update_editor_code({ type: tab, content: code }));
}, [code, dispatch, tab]);

return (
<MonacoEditor
onChange={onChange}
onMount={onMount}
language={language}
language={monacoLanguage}
theme="vs-dark"
options={options}
className="h-full"
// @ts-ignore
value={monacoInputValue.languages[language].data}
value={monacoInputValue.tabs[tab].data}
/>
);
};

1 comment on commit 9d2b352

@vercel
Copy link

@vercel vercel bot commented on 9d2b352 Jul 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.