<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ayseboogie</title>
    <description>The latest articles on DEV Community by ayseboogie (@ayseboogie).</description>
    <link>https://dev.to/ayseboogie</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F137421%2F2f37b009-ff1f-42b4-8d76-9616568b1b48.jpeg</url>
      <title>DEV Community: ayseboogie</title>
      <link>https://dev.to/ayseboogie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayseboogie"/>
    <language>en</language>
    <item>
      <title>Setting up SendInBlue in a Typescript project with a Prismic CMS</title>
      <dc:creator>ayseboogie</dc:creator>
      <pubDate>Thu, 30 Mar 2023 02:13:28 +0000</pubDate>
      <link>https://dev.to/ayseboogie/setting-up-sendinblue-in-a-typescript-project-with-a-prismic-cms-db5</link>
      <guid>https://dev.to/ayseboogie/setting-up-sendinblue-in-a-typescript-project-with-a-prismic-cms-db5</guid>
      <description>&lt;p&gt;Adding a contact form and subscribe button to a Prismic project in order to send transactional emails and add to your contact list on SendInBlue's platform&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/KY_FX3qiG3g"&gt;
&lt;/iframe&gt;
&lt;br&gt;
the repo is: &lt;a href="https://github.com/ayseboogie/prismic-ts" rel="noopener noreferrer"&gt;https://github.com/ayseboogie/prismic-ts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dev.to post that led me to figuring it out: &lt;a href="https://dev.to/pavel_polivka/how-to-create-simple-email-form-in-your-nodejs-website-3end"&gt;https://dev.to/pavel_polivka/how-to-create-simple-email-form-in-your-nodejs-website-3end&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Adding Algolia to a NextJS Typescript Prismic project</title>
      <dc:creator>ayseboogie</dc:creator>
      <pubDate>Wed, 29 Mar 2023 16:48:36 +0000</pubDate>
      <link>https://dev.to/ayseboogie/adding-algolia-to-a-nextjs-typescript-prismic-project-2c3c</link>
      <guid>https://dev.to/ayseboogie/adding-algolia-to-a-nextjs-typescript-prismic-project-2c3c</guid>
      <description>&lt;p&gt;Adding Algolia search functionality to a NextJS Typescript project with a Prismic CMS. This shows adding a search to a list of posts on the site.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Aa35WWNOEBk"&gt;
&lt;/iframe&gt;
&lt;br&gt;
the repo is: &lt;a href="https://github.com/ayseboogie/prismic-ts" rel="noopener noreferrer"&gt;https://github.com/ayseboogie/prismic-ts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Algolia Secured API keys in React page: &lt;a href="https://www.algolia.com/doc/guides/building-search-ui/going-further/api-keys-security/react/" rel="noopener noreferrer"&gt;https://www.algolia.com/doc/guides/building-search-ui/going-further/api-keys-security/react/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating a NextJS Typescript project using a Prismic CMS</title>
      <dc:creator>ayseboogie</dc:creator>
      <pubDate>Wed, 29 Mar 2023 16:38:43 +0000</pubDate>
      <link>https://dev.to/ayseboogie/creating-a-nextjs-typescript-project-using-a-prismic-cms-lh4</link>
      <guid>https://dev.to/ayseboogie/creating-a-nextjs-typescript-project-using-a-prismic-cms-lh4</guid>
      <description>&lt;p&gt;Prismic's documentation is good, but I could not find a typescript starter tutorial..so I made one.&lt;/p&gt;

&lt;p&gt;I set my project up using Tailwind and Prettier, show dynamic routing, and how to set up Page Previews and Slice Screenshots.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/C-hZXjP7sC0"&gt;
&lt;/iframe&gt;
&lt;br&gt;
the repo is: &lt;a href="https://github.com/ayseboogie/prismic-ts" rel="noopener noreferrer"&gt;https://github.com/ayseboogie/prismic-ts&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building a code editor within NextJS</title>
      <dc:creator>ayseboogie</dc:creator>
      <pubDate>Sat, 15 Jan 2022 04:56:30 +0000</pubDate>
      <link>https://dev.to/ayseboogie/building-a-code-editor-within-nextjs-3nnc</link>
      <guid>https://dev.to/ayseboogie/building-a-code-editor-within-nextjs-3nnc</guid>
      <description>&lt;p&gt;I've found examples of building a code editor within React, but the npm packages that are used throw a window / navigator not found in NextJS. This is how I got around that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create App
&lt;/h2&gt;

&lt;p&gt;First create your app&lt;br&gt;
&lt;code&gt;npx create-next-app@latest&lt;/code&gt;&lt;br&gt;
 then I am going to &lt;a href="https://tailwindcss.com/docs/guides/nextjs" rel="noopener noreferrer"&gt;install Tailwind&lt;/a&gt;&lt;br&gt;
run &lt;code&gt;npm run dev&lt;/code&gt; and bam! Let's set up our folder structure. Create a components folder in the root directory and add 4 files: &lt;code&gt;editor.js&lt;/code&gt;, &lt;code&gt;editorApp.js&lt;/code&gt;, &lt;code&gt;editor.module.css&lt;/code&gt;, and &lt;code&gt;useLocalStorage.js&lt;/code&gt;.&lt;br&gt;
Sweet, we are ready to build this editor.&lt;/p&gt;
&lt;h2&gt;
  
  
  editor.module.css
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media (min-width: 500px) {
    .topPane {
        display: flex;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Skeleton
&lt;/h2&gt;

&lt;p&gt;Let's start by adding to our &lt;code&gt;editor.js&lt;/code&gt; (you'll need to install the classnames module)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Editor = () =&amp;gt; {
    return(
        &amp;lt;div&amp;gt;Editor&amp;lt;/div&amp;gt;
    )
}

export default Editor;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then we'll import that into our &lt;code&gt;editorApp.js&lt;/code&gt; (3 times for html, css, and js)&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Editor from "./editor";
import * as style from "./editor.module.css";
import cn from "classnames";

const EditorApp = () =&amp;gt; {
    return (
        &amp;lt;&amp;gt;
        &amp;lt;div className={cn("bg-zinc-500", style.topPane)}&amp;gt;
             &amp;lt;Editor /&amp;gt;
             &amp;lt;Editor /&amp;gt;
             &amp;lt;Editor /&amp;gt;
         &amp;lt;/div&amp;gt;
            &amp;lt;div style={{ height: "68vh" }}&amp;gt;
                &amp;lt;iframe
                title="output"
                sandbox="allow-scripts"
                frameBorder="0"
                height="100%"
                width="100%" /&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/&amp;gt;
    )
};

export default EditorApp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And then we can rip out all the boiler code in &lt;code&gt;index.js&lt;/code&gt; and import our editorApp&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import CodeEditor from "../components/editorApp";

export default function Home() {
  return (
    &amp;lt;CodeEditor /&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You should see Editor 3 times on your screen. Cool.&lt;/p&gt;
&lt;h2&gt;
  
  
  Editor.js
&lt;/h2&gt;

&lt;p&gt;We need to install &lt;a href="https://www.npmjs.com/package/react-codemirror2-react-17" rel="noopener noreferrer"&gt;codemirror&lt;/a&gt;, so run &lt;code&gt;npm install react-codemirror2-react-17 codemirror --save&lt;/code&gt;&lt;br&gt;
Let's import the styles for codeMirror and our theme. You can test different themes &lt;a href="https://codemirror.net/demo/theme.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;, and we will also import the codemirror editor.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "codemirror/lib/codemirror.css";
import "codemirror/theme/tomorrow-night-bright.css";
import { Controlled as ControlledEditor } from "react-codemirror2-react-17";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We have to import the languages differently as to not throw a ReferenceError of navigator is not defined.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let languageLoaded = false;
if (typeof window !== "undefined" &amp;amp;&amp;amp; typeof window.navigator !== "undefined") {
    require("codemirror/mode/xml/xml");
    require("codemirror/mode/css/css");
    require("codemirror/mode/javascript/javascript");
    languageLoaded = true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We are going to add create our editor now, with a title and body. This includes our props and &lt;code&gt;handleChange&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "codemirror/lib/codemirror.css";
import "codemirror/theme/tomorrow-night-bright.css";
import { Controlled as ControlledEditor } from "react-codemirror2-react-17";

let languageLoaded = false;
if (typeof window !== "undefined" &amp;amp;&amp;amp; typeof window.navigator !== "undefined") {
    require("codemirror/mode/xml/xml");
    require("codemirror/mode/css/css");
    require("codemirror/mode/javascript/javascript");
    languageLoaded = true;
}

const Editor = (props) =&amp;gt; {
    const { language, editorTitle, value, onChange, className } = props;

    function handleChange(editor, data, value) {
        onChange(value);
    }

    return(
        &amp;lt;div className={className}&amp;gt;
            &amp;lt;div className="flex justify-between text-white rounded-t-lg py-2 pr-2 pl-4 bg-zinc-700"&amp;gt;
                {editorTitle}
            &amp;lt;/div&amp;gt;
            &amp;lt;ControlledEditor
                onBeforeChange={handleChange}
                value={value}
                className="grow rounded-b-lg overflow-hidden text-left"
                options={{
                    lineWrapping: true,
                    lint: true,
                    mode: language,
                    theme: "tomorrow-night-bright",
                    lineNumbers: true,
                }}
            /&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export default Editor;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  editorApp.js
&lt;/h2&gt;

&lt;p&gt;We need to fill out our &lt;code&gt;&amp;lt;Editor /&amp;gt;&lt;/code&gt; now. Add a &lt;br&gt;
&lt;code&gt;const [html, setHtml] = useState('');&lt;/code&gt; (import useState)&lt;br&gt;
and for the first editor&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;Editor
   language="xml"
   editorTitle="HTML"
   value={html}
   onChange={setHtml}
   /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Copy this pattern for css and javascript.&lt;br&gt;
Then we are going to add a useEffect to set the iframe srcDoc.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [srcDoc, setSrcDoc] = useState("");

useEffect(() =&amp;gt; {
    const timeout = setTimeout(() =&amp;gt; {
      setSrcDoc(`
        &amp;lt;html lang="en"&amp;gt;
          &amp;lt;body&amp;gt;${html}&amp;lt;/body&amp;gt;
          &amp;lt;style&amp;gt;${css}&amp;lt;/style&amp;gt;
          &amp;lt;script&amp;gt;${js}&amp;lt;/script&amp;gt;
        &amp;lt;/html&amp;gt;
      `);
    }, 200);

    return () =&amp;gt; clearTimeout(timeout);
  }, [html, css, js]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;and add the srcDoc prop as srcDoc to the iframe. You should have&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from "react";
import Editor from "./editor";
import * as style from "./editor.module.css";
import cn from "classnames";

const EditorApp = () =&amp;gt; {
  const [html, setHtml] = useState("");
  const [css, setCss] = useState("");
  const [js, setJs] = useState("");
  const [srcDoc, setSrcDoc] = useState("");

  useEffect(() =&amp;gt; {
    const timeout = setTimeout(() =&amp;gt; {
      setSrcDoc(`
        &amp;lt;html lang="en"&amp;gt;
          &amp;lt;body&amp;gt;${html}&amp;lt;/body&amp;gt;
          &amp;lt;style&amp;gt;${css}&amp;lt;/style&amp;gt;
          &amp;lt;script&amp;gt;${js}&amp;lt;/script&amp;gt;
        &amp;lt;/html&amp;gt;
      `);
    }, 200);

    return () =&amp;gt; clearTimeout(timeout);
  }, [html, css, js]);

  return (
    &amp;lt;&amp;gt;
      &amp;lt;div className={cn("bg-zinc-500", style.topPane)}&amp;gt;
        &amp;lt;Editor
          className="px-2 py-3 md:w-1/3 md:pl-3 md:pr-2"
          language="xml"
          editorTitle="HTML"
          value={html}
          onChange={setHtml}
        /&amp;gt;
        &amp;lt;Editor
          className="px-2 py-3 md:w-1/3 md:px-2"
          language="css"
          editorTitle="CSS"
          value={css}
          onChange={setCss}
        /&amp;gt;
        &amp;lt;Editor
          className="px-2 py-3 md:w-1/3 md:pl-1 md:pr-3"
          language="javascript"
          editorTitle="JS"
          value={js}
          onChange={setJs}
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div style={{ height: "68vh" }}&amp;gt;
        &amp;lt;iframe
          srcDoc={srcDoc}
          title="output"
          sandbox="allow-scripts"
          frameBorder="0"
          height="100%"
          width="100%"
        /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/&amp;gt;
  );
};

export default EditorApp;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You should now be able to type in the the editors and see your results displayed.&lt;/p&gt;
&lt;h2&gt;
  
  
  useLocalStorage.js
&lt;/h2&gt;

&lt;p&gt;Last step.&lt;br&gt;
In this component, we use &lt;code&gt;localStorage&lt;/code&gt;, which will either throw a &lt;code&gt;localStorage is not defined&lt;/code&gt; or &lt;code&gt;window is not defined&lt;/code&gt; in NextJS.&lt;a href="https://nextjs.org/docs/basic-features/pages" rel="noopener noreferrer"&gt;NextJS pre-renders&lt;/a&gt; every page which results in Static Site Generation or Server Side Rendering. &lt;code&gt;localStorage&lt;/code&gt; is a property of the window object which is available on the client side / browser.&lt;br&gt;
To get around this, we first have to check if the window is defined.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useEffect, useState } from "react";

function getStorageValue(key, initialValue) {
  if (typeof window !== "undefined") {
    const savedValue = localStorage.getItem(key);
    return savedValue !== null ? JSON.parse(savedValue) : initialValue;
  }
}

export const useLocalStorage = (key, initialValue) =&amp;gt; {
  const [value, setValue] = useState(() =&amp;gt; {
    return getStorageValue(key, initialValue);
  });

  useEffect(() =&amp;gt; {
    localStorage.setItem(key, JSON.stringify(value));
  }, [key, value]);

  return [value, setValue];
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Import and replace useState in &lt;code&gt;editorApp.js&lt;/code&gt; for your html, css, and js with useLocalStorage&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const [html, setHtml] = useLocalStorage("html", "");
  const [css, setCss] = useLocalStorage("css", "");
  const [js, setJs] = useLocalStorage("js", "");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Boom
&lt;/h2&gt;

&lt;p&gt;You should now have a working codeEditor. If you want to prefill any section with code, just put your code in the empty "" ex. &lt;code&gt;const [html, setHtml] = useLocalStorage("html", "&amp;lt;div&amp;gt;foo&amp;lt;/div&amp;gt;");&lt;/code&gt;. Keep in mind that localStorage is being saved so you may need to clear your browsing data one to many times.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ayseboogie" rel="noopener noreferrer"&gt;
        ayseboogie
      &lt;/a&gt; / &lt;a href="https://github.com/ayseboogie/next-code-editor" rel="noopener noreferrer"&gt;
        next-code-editor
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/29460915/149678119-5755d756-1ef1-46cd-983c-f504daad065c.png"&gt;&lt;img width="1626" alt="nextCodeEditor" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F29460915%2F149678119-5755d756-1ef1-46cd-983c-f504daad065c.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Getting Started&lt;/h2&gt;

&lt;/div&gt;

&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;npm run dev
&lt;span class="pl-c"&gt;&lt;span class="pl-c"&gt;#&lt;/span&gt; or&lt;/span&gt;
yarn dev&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Open &lt;a href="http://localhost:3000" rel="nofollow noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; with your browser to see the result.&lt;/p&gt;
&lt;/div&gt;

  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/ayseboogie/next-code-editor" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;This is my first post, I hope it was easy to follow and helps someone out :-)&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
