From e63f0689ce12616a0f7bf8592f77120160fd46fd Mon Sep 17 00:00:00 2001 From: diego tonini Date: Tue, 30 Jan 2024 20:46:59 +0100 Subject: [PATCH] feat: add basic screen size selection + update readme --- README.md | 7 +++++ src/client/index.css | 14 ++++++++++ src/client/pages/Email.tsx | 43 +++++++++++++++++++++-------- src/create-example/create-config.ts | 2 +- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1b3cadd..ea5054f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ +

marilena

+

a tool to build emails with cool stuff like mjml and different template engine like handlebars or eta.js

+ +

+ version +

+ ## The problem We know emails are `VERY HARD` to develop from scratch. Even if there are tools like Maiject, SendPulse, MailerSend, Stripo.email etc (maybe with a good drag-n-drop UI) sometimes you find yourself in one of the following cases: diff --git a/src/client/index.css b/src/client/index.css index 44159ab..68cefde 100644 --- a/src/client/index.css +++ b/src/client/index.css @@ -34,3 +34,17 @@ body { right: 1rem; top: 1rem; } + +#email-frame { + transition: width 200ms ease-in-out; +} + +.email-frame-container, +.frame-settings { + display: flex; + justify-content: center; +} + +.frame-settings { + margin: 1rem 0; +} diff --git a/src/client/pages/Email.tsx b/src/client/pages/Email.tsx index 2979e47..682c0dd 100644 --- a/src/client/pages/Email.tsx +++ b/src/client/pages/Email.tsx @@ -6,13 +6,16 @@ import type { Params } from "../../routes/post-send-email.js"; import ReactModal from "react-modal"; import { SerializedConfig } from "src/routes/get-config.js"; -let socket: WebSocket; +// let socket: WebSocket; export const Email = () => { let { emailName, locale } = useParams(); - const formRef = useRef(null); + const frameRef = useRef(null); + const socketRef = useRef(); const [isModalOpen, setModalOpen] = useState(false); const [sendTo, setSendTo] = useState(""); const [fillFakeMetaData, setFillFakeMetaData] = useState(false); + const [screenMode, setScreenMode] = useState<"DEKSTOP" | "MOBILE">("DEKSTOP"); + const screenSize = screenMode === "DEKSTOP" ? 800 : 375; const { data: config } = useQuery("getConfig", () => fetch("/api/config").then((r) => r.json()), @@ -36,22 +39,25 @@ export const Email = () => { document.title = `${emailName} - ${locale}`; // setup socket - socket = new WebSocket(`ws://localhost:8080`); + socketRef.current = new WebSocket(`ws://localhost:${SERVER_PORT}`); - socket.addEventListener("open", (event) => { + socketRef.current.addEventListener("open", (event) => { console.log("socket open"); }); // Listen for messages - socket.addEventListener("message", (event) => { + socketRef.current.addEventListener("message", (event) => { const message = event.data; if (message === "need_refresh") { - formRef.current?.contentWindow?.location.reload(); + frameRef.current?.contentWindow?.location.reload(); } }); return () => { - if (socket.readyState === WebSocket.OPEN) { - socket.close(); + if ( + !!socketRef.current && + socketRef.current.readyState === WebSocket.OPEN + ) { + socketRef.current.close(); } }; }, []); @@ -69,6 +75,13 @@ export const Email = () => { } }, [config]); + useEffect(() => { + const iframe = frameRef.current; + if (iframe) { + iframe.style.width = `${screenSize}px`; + } + }, [screenSize]); + function sendEmail() { if (emailName && locale && config?.sendTestOptions?.to) { const params = { @@ -94,18 +107,27 @@ export const Email = () => { setFillFakeMetaData(e.target.checked); } + const setScreen = (screen: "DEKSTOP" | "MOBILE") => + function handleChangeFillFakeData() { + setScreenMode(screen); + }; + return (
+
+ + + {screenSize}px +
-
-