<?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: Charles-Eugene Loubao</title>
    <description>The latest articles on DEV Community by Charles-Eugene Loubao (@charleswritescode).</description>
    <link>https://dev.to/charleswritescode</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%2F87674%2F2bf9023a-83f8-403e-a701-dda38a8489ce.jpg</url>
      <title>DEV Community: Charles-Eugene Loubao</title>
      <link>https://dev.to/charleswritescode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/charleswritescode"/>
    <language>en</language>
    <item>
      <title>How to display a route as a modal in Vue.js</title>
      <dc:creator>Charles-Eugene Loubao</dc:creator>
      <pubDate>Mon, 07 Oct 2019 17:59:24 +0000</pubDate>
      <link>https://dev.to/charleswritescode/how-to-display-a-route-as-a-modal-in-vue-js-iid</link>
      <guid>https://dev.to/charleswritescode/how-to-display-a-route-as-a-modal-in-vue-js-iid</guid>
      <description>&lt;p&gt;Hello everyone!&lt;/p&gt;

&lt;p&gt;In this tutorial we are going to learn how to display a Vue route as a modal, similar to image links on Dribble.com or Google contacts. This format is very useful when you want to show information to the user without redirecting them to another page&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fscreenshot4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fscreenshot4.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This tutorial assumes you are familiar with Vue.js. &lt;/p&gt;

&lt;p&gt;First lets create a basic vue project with vue-router&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vue-create $folder&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;For this project I also installed faker.js to create dummy data for our contact list&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save faker&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Then I created the following files&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;src/db.js (Mock database)&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import faker from 'faker'

const contacts = {}

for (let index = 0; index &amp;lt; 10; index++) {
    const id = "user_" + index
    contacts[id] = {
        id,
        name: `${faker.name.firstName()}  ${faker.name.lastName()}`,
        jobTitle: faker.name.jobTitle(),
        email: faker.internet.email(),
        phone: faker.phone.phoneNumber(),
    }
}

export default {
    contacts
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;src/views/Contacts.vue (Contact list)&lt;/em&gt;&lt;/strong&gt;&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;template&amp;gt;
  &amp;lt;div class="contacts"&amp;gt;
    &amp;lt;h2&amp;gt;Contacts&amp;lt;/h2&amp;gt;
    &amp;lt;div class="contact-list"&amp;gt;
      &amp;lt;router-link
        tag="div"
        class="item"
        :to="`/contacts/${contact.id}`"
        v-for="contact in contacts"
        :key="contact.id"
      &amp;gt;
        &amp;lt;strong&amp;gt;{{contact.name}}&amp;lt;/strong&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;span&amp;gt;{{contact.jobTitle}}&amp;lt;/span&amp;gt;
      &amp;lt;/router-link&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
import db from "@/db.js";
export default {
  computed: {
    contacts() {
      return Object.values(db.contacts);
    }
  }
};
&amp;lt;/script&amp;gt;

&amp;lt;style lang="scss" scoped&amp;gt;
.contact-list {
    .item {
        &amp;amp;:not(:last-child) {
            margin-bottom: 8px;
        }
        padding: 16px;
        border-radius: 4px;
        border: solid 1px #e2e2e2;
    }
}
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;src/views/ContactInfo.vue&lt;/em&gt;&lt;/strong&gt;&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;template&amp;gt;
  &amp;lt;div class="contact-info"&amp;gt;
    &amp;lt;router-link to="../"&amp;gt;X&amp;lt;/router-link&amp;gt;
    &amp;lt;h3&amp;gt;{{contact.name}}&amp;lt;/h3&amp;gt;

    &amp;lt;h4&amp;gt;Job Title&amp;lt;/h4&amp;gt;
    &amp;lt;span&amp;gt;{{contact.jobTitle}}&amp;lt;/span&amp;gt;
    3
    &amp;lt;h4&amp;gt;Email&amp;lt;/h4&amp;gt;
    &amp;lt;span&amp;gt;{{contact.email}}&amp;lt;/span&amp;gt;

    &amp;lt;h4&amp;gt;Phone&amp;lt;/h4&amp;gt;
    &amp;lt;span&amp;gt;{{contact.phone}}&amp;lt;/span&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
import db from "@/db.js";
export default {
  props: ["contactId"],
  data() {
    return {
      contact: ""
    };
  },
  created() {
    this.contact = db.contacts[this.contactId];
  }
};
&amp;lt;/script&amp;gt;

&amp;lt;style lang="scss" scoped&amp;gt;
.contact-info {
    padding: 16px;
}
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also modified the &lt;code&gt;src/router.js&lt;/code&gt; file to add a route for &lt;code&gt;/contacts&lt;/code&gt; that points to the Contacts.vue component. I am also redirecting the root path to &lt;code&gt;/contacts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fimg1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fimg1.png" alt="Changes to router.js" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After making these changes we get this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fscreenshot1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fscreenshot1.png" alt="Result" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we click on a user the route will display a blank screen. To fix this we need to add a route for the ContactInfo component. We need to create the route as a child of the &lt;code&gt;/contacts&lt;/code&gt; route. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;src/router.js&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ContactInfo from './views/ContactInfo.vue'
...
{
      path: '/contacts',
      component: Contacts,

      // ADDED
      children: [
        {
          path: ':contactId',
          component: ContactInfo,
          props: true
        }
      ]
    },
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we need to add a &lt;code&gt;router-view&lt;/code&gt; component to &lt;code&gt;Contacts.vue&lt;/code&gt;&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;div class="contacts"&amp;gt;
  ...
  ...
    &amp;lt;router-view&amp;gt;&amp;lt;/router-view&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now click a Contact and you will see this at the bottom of the screen:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fscreenshot2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fscreenshot2.png" alt="Result" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is not exactly what we want. We need to make the router-view show as a modal. We have to make a few changes&lt;/p&gt;

&lt;p&gt;Go to &lt;code&gt;Contacts.vue&lt;/code&gt; and replace &lt;code&gt;&amp;lt;router-view&amp;gt;&amp;lt;/router-view&amp;gt;&lt;/code&gt; with this&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;div v-if="showModal" class="modal-route"&amp;gt;
      &amp;lt;div class="modal-content"&amp;gt;
        &amp;lt;router-view&amp;gt;&amp;lt;/router-view&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are moving router-view inside a "Modal" wrapper which will only be display when the &lt;code&gt;showModal&lt;/code&gt; property is set to true&lt;/p&gt;

&lt;p&gt;Then add this to &lt;code&gt;style&lt;/code&gt; section&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.modal-route {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba($color: #000000, $alpha: 0.5);
  .modal-content {
    width: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally in the &lt;code&gt;script&lt;/code&gt; section, we add watcher for the $route property and create a &lt;code&gt;showModal&lt;/code&gt; property inside our data. &lt;code&gt;showModal&lt;/code&gt; is set to false to prevent the modal from being displayed when we first load the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
 watch: {
    $route(newVal, oldVal) {
      this.showModal = newVal.meta &amp;amp;&amp;amp; newVal.meta.showModal;
    }
  },
  data() {
    return {
      showModal: false
    }
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every Vue component has a &lt;code&gt;$route&lt;/code&gt; property that contains information about the current route. (More information on the &lt;code&gt;$route&lt;/code&gt; object &lt;a href="https://router.vuejs.org/api/#the-route-object" rel="noopener noreferrer"&gt;Here&lt;/a&gt;). By watching the &lt;code&gt;$route&lt;/code&gt; property we can be notified when the current route changed.&lt;/p&gt;

&lt;p&gt;Next open &lt;code&gt;src/router.js&lt;/code&gt; and add a &lt;code&gt;meta&lt;/code&gt; property to the /contacts/:contactId route&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
component: Contacts,
children: [
  {
    path: ':contactId',
    component: ContactInfo,
    props: true
    meta: {
      showModal: true
    }
  },
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Vue.js the &lt;code&gt;meta&lt;/code&gt; property is used to pass additional information to the route. &lt;code&gt;meta&lt;/code&gt; is not to be mistaken with the &lt;code&gt;props&lt;/code&gt; property. More info on &lt;code&gt;meta&lt;/code&gt; &lt;a href="https://router.vuejs.org/guide/advanced/meta.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now click on a contact and you should see the modal&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fscreenshot3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fcharleswritescode%2Fvue-samples-modal-route%2Fraw%2Fmaster%2Ftutorial%2Fscreenshot3.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The new route is now /contacts/user_0 and the contact info is displayed in the same page.&lt;/p&gt;

&lt;p&gt;If you refresh the page you will see that the modal is not displayed even thought the route points to &lt;code&gt;/contacts/:contactId&lt;/code&gt; The &lt;code&gt;router-view&lt;/code&gt; modal is only displayed when &lt;code&gt;showModal&lt;/code&gt; is set to true. The problem is that Vue does not call a watcher by default when a component is created and since &lt;code&gt;showModal&lt;/code&gt; is set to false when the component is rendered, the modal is not visible. To fix this we need to refactor our &lt;code&gt;$route&lt;/code&gt; watcher like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;src/Contacts.vue&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$route: {
      immediate: true,
      handler: function(newVal, oldVal) {
        this.showModal = newVal.meta &amp;amp;&amp;amp; newVal.meta.showModal;
      }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;handler&lt;/code&gt; property is the function that is executed when a changes occurs to the property we are watching. &lt;code&gt;immediate:true&lt;/code&gt; tells Vue to check the watched property &lt;code&gt;$route&lt;/code&gt; when the component is created. More info on watched &lt;a href="https://vuejs.org/v2/guide/computed.html#Watchers" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now refresh the page and the modal should be displayed properly.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this tutorial. The full source code is available on &lt;a href="https://github.com/charleswritescode/vue-samples-modal-route" rel="noopener noreferrer"&gt;Github&lt;/a&gt; ! And a demo is a working demo is available at &lt;a href="http://friendly-brain.surge.sh" rel="noopener noreferrer"&gt;http://friendly-brain.surge.sh&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>My First JQuery Only App : Tic Tac Toe Emoji!</title>
      <dc:creator>Charles-Eugene Loubao</dc:creator>
      <pubDate>Fri, 05 Apr 2019 16:32:37 +0000</pubDate>
      <link>https://dev.to/charleswritescode/my-first-jquery-only-app-tic-tac-toe-emoji-1fgf</link>
      <guid>https://dev.to/charleswritescode/my-first-jquery-only-app-tic-tac-toe-emoji-1fgf</guid>
      <description>&lt;p&gt;Hi everyone !! &lt;/p&gt;

&lt;p&gt;My name is Charles and I am so excited because this is my first post on Dev.to! I have been looking for something to write about for millenniums and finally I have something!!&lt;/p&gt;

&lt;p&gt;A little bit about me, I am a 23 years old programmer originally from &lt;strong&gt;Cote D'Ivoire, Africa&lt;/strong&gt; who came to the United States in 2015 to pursue an Associate's Degree in Computer Information Systems. I have graduated May 2018 and have been working at Delaware Tech Community College (my school) for about 2 years now as the Computer Information Systems tutor.&lt;/p&gt;

&lt;p&gt;Now let's talk about the good stuff: &lt;strong&gt;Tic Tac Toe&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This project came into existence because I have been trying to build something with Jquery but was too scared to start (why ? you tell me). I've been working on my skills as a programmer for the past 5 years first learning Android but in the past year I have decided to sharpen my skills in frontend and backend development.  My first experience with web development was with Vue and I fell in love with it from the beginning. I always shy away from Jquery because it looked intimidating but I knew I had to learn how to make web apps without a 'framework'. Frameworks come and go but HTML, JS and CSS won't and Jquery being the go to library for vanilla JavaScript won't either.&lt;/p&gt;

&lt;p&gt;That's why I decided to build something simple that doesn't require too much work but will help me get better working with Jquery&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F9cur7e8ou7dzbe8dckww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F9cur7e8ou7dzbe8dckww.png" alt="demo image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a basic Tic Tac Toe app that I built yesterday night. We are using the laughing emoji for player 1 and the angry emoji for player 2. The first player to get a row wins&lt;/p&gt;

&lt;p&gt;I am planning making it look better with CSS and reorganize some of the code but for now it works for me.&lt;/p&gt;

&lt;p&gt;The project is available on &lt;a href="https://github.com/charleswritescode/tic-tac-toe-emoji" rel="noopener noreferrer"&gt;Github&lt;/a&gt; and a live version is available &lt;a href="https://tic-tac-toe-emoji.surge.sh/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to look at it and give me some feedback :)&lt;/p&gt;

&lt;p&gt;Thank you and have fun playing :)&lt;/p&gt;

</description>
      <category>jquery</category>
      <category>html</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
