The Only Way Out of Coding Bootcamp is Through React and Redux

The final project for Flatiron’s Online Web Development Bootcamp is a React Redux project with a Rails backend. This project cumulates all of what we have learned in the course – Ruby, JS, HTML, CSS, AJAX, React, Rails, and Redux. React and Redux was tough for me to grasp. In addition to Flatiron’s curriculum I used Stephen Grider’s course on React and Redux: https://www.udemy.com/react-redux/. Stephen uses diagrams and analogies to help explain concepts, I highly recommend this course as he walks through building several projects from scratch.

The app that I built is called Daily Code Log in which you can document your daily coding progress. As a self proclaimed code newbie, I realize how important it is to document learnings, especially being aware of what you don’t know. Over time, as you seek out answers to your own questions, you will look back on answered questions and realize how much knowledge you’ve accumulated.

Now that I am on the other side, here are a few quick tips and pointers if you are thinking about tackling a similar project.

Map Out Requirements and a Schedule

The task at hand seemed daunting, so I decided to break the project into smaller parts. Here is my 9 day plan:

Saturday: Map project out- define relationships amongst objects and be clear about the question “What is the point of my app?”

Sunday: Create seed data, setup Rails backend of project.

Monday: Create entire (mockup) UI of project.

Tuesday: Hookup fetch get requests to fetch internal API data.

Wednesday: Hookup fetch post requests so API endpoint could be updated.

Thursday: Set up React routes.

Friday: Final touches/ squash bugs.

Saturday: Record video walkthrough of App/ write blog post on learnings.

Sunday: …Submit project!!!!

Setting a goal for myself each day was very helpful because each morning I knew exactly what I wanted to get accomplished. If I met my goal earlier in the day, I would move on to my next goal.

Use Semantic UI

I used Semantic UI for the web design of my app. Instead of a template, Semantic UI has many different elements- think buttons, cards, icons- that you can use in your app. Semantic gives you the different building blocks, but ultimately the final product can look original and custom made. In order to reference Semantic UI within your application you simply have to import the following link into the client/public/index.html within the <head> tag:

<link rel="stylesheet" href="<https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css>">

I then used some CSS to reposition and style the elements further.

Here are some screenshots of the simple design of the app:

Form to create a Code Log
Display of all Code Logs

More Than One Way to do the Same Thing…

The trickiest part of the project for me was submitting forms to update my internal API endpoint. Doing a quick google search, most people suggested I use https://redux-form.com/, but my instructor helped me post data to my API without Redux Form. Instead, we used vanilla javascript. In the form’s handleOnSubmit function, we called on an action call addLog which made a post request to the API endpoint:

export const addLog = (log) => {
  return dispatch => {
    return fetch('/logs', {
      method: "POST",
      headers: {'Content-Type':'application/json'},
      body: JSON.stringify({log})
    }).then(resp => resp.json())
      .then(log => dispatch({type: "ADD_LOG", log}))
  }
}

The reducer, “ADD_LOG”, then adds the form’s data to the Redux store.

I’m looking forward to diving into Redux Form but it was worthwhile to learn the vanillas JS way. Now, when I learn Redux Form, I’ll have a solid idea of what Redux Form is doing behind the scenes.

I did it!

I am very proud of the way the project turned out. I have used the app daily to track my coding progress, and once I add authentication, I hope others use the app for their learning benefit as well.

P.S. Here’s a walkthrough of my project!

What is a Framework?

While I was learning Javascript on my own, I began exposing myself to all the resources I could. Using FreeCodeCamp as my guide, I browsed the internet for other supplemental resources to add context to what I was learning. Eventually, I began reading about Javascript frameworks “Learn Angular vs. Vue”, I couldn’t wrap my head around what a framework actually was. I was under the impression that frameworks would make learning how to code “easier”.

Fast forward 2.5 months into my coding bootcamp, and I am learning the ropes of Rails. So, now that I’ve learned and built a project using a framework, how would I define a framework to a total code newbie? Frameworks, and in this case Rails, didn’t make learning how to code any easier, but it did lay out a lot of groundwork so I could hit the ground running with building my web application. Frameworks use abstraction (high level code) in order to provide a foundation to build off of. For example, typing rails new unicorn creates a directory which provides a standard layout of how to organize the files within your application named unicorn. Also, Rails comes with generators in which you can create tables from the command line, instead of having to create a file in your text editor and write out the code in the file in order to create a table. Not to mention, the infamous scaffold generator, which creates CRUD functions for a model by typing out one line in the command line!

In short, you can think of a framework as a piece of software built because someone identified that there was similar code/ patterns that had to get built out each time a new application is built. In the context of Rails, David Heinemeier Hansson put in the legwork in order to make it more efficient for other developers to build an application. There’s even extensive and fantastic documentation to demonstrate how to use the framework https://guides.rubyonrails.org/.

I remember bringing this topic of “What is a framework?” up with one of my instructors. I first told him what my initial idea of a framework was— training wheels, since frameworks do a lot of the work for you. However, this setup is not trivial. It’s important to understand Ruby well before jumping into Rails, so you are able to understand and have context with the magic (really abstraction) of Rails. My instructor opposed my analogy, and instead, he said think of using frameworks as standing on the shoulders of giants. Well said.

Back to the Drawing (White) Board

The project I built using Ruby on Rails is a private group class tracker for a yoga studio.

Sounds like a mouthful, I know, but I noticed that the yoga studio I work for has a niche problem. Local organizations such as universities, non-profits, corporations etc. request for a yoga teacher to come onsite to teach a class. Most of the time, these requests are inconsistent. For example, an organization will want a class for their “Wellness Week” which only happens a couple of times per year. Since requests are inconsistent, the same client will have a different teacher each time. The teacher assigned for this offsite class has no idea what kind of class to plan. What kind of practice do the participants want? What is the space like? It would be nice if they could take a look at the class plan from the previous class, that was perhaps taught by a different teacher! That’s where my web application comes into play!

My enthusiasm for my idea fueled the creation of the project, however this was the toughest project yet. Here’s what I learned:

The importance of having a clear vision for your project before you get started.

I had to restart my project twice! I had to restart my project because both times my domain was not clearly defined from the get-go, which made building complicated (lesson learned!). However, each iteration of my project led to my final product, which I’m very proud of. While I shared with my friends and family about my tribulations, I compared my process to something they were familiar with, writing a thesis paper.

The first step is to clearly construct a thesis statement, in coding world this would be constructing our domain models and defining relationships. The thesis statement steers the ship as you’re writing the paper. Similarly, your models and relationships can create the backbone of your Ruby on Rails application. If you write a thesis paper without properly researching a topic, as you’re writing, you may have a change of heart with your beloved thesis statement. Now that you’re reading additional sources and are really diving into the topic, perhaps you want to change your stance. So you go back to the drawing board and rewrite a thesis statement that better represents your positioning now that you have new information. You have to start your paper all over again. Similarly, as I began to bring my project to life, I realized there was a better way to represent my project— different from the models and relationships than what I had set up. Since I wanted to change the infrastructure of my project, I had to restart my project.

Knowing when to let go if a certain idea isn’t working out.

It’s tough to abandon a project after spending a lot of time on it. I spent 4 days on my first iteration, knowing most of the time that I wanted to restart it and take it in a different direction. I was so resistant to restarting, but once I took action and restarted, I felt a surge of momentum because I knew it was aligned with my vision. To make myself feel better about my situation, I thought about how artists record entire albums that never get released and fall to the wayside. Authors write novels that never get published. Although these pieces never make it to the public, I bet these creative pursuits influenced other pieces that eventually did reach a broader audience. Similarly, my failed projects influenced the success of the final version of my project.

Get to know the gems you’re using.

Since I restarted my project twice, I can now set up Devise and enable Omniauth using Facebook with confidence. This was my first time using both Devise and Facebook Omniauth. Typically when I use a gem for the first time I find a blog or video to guide me through step by step. The downside of this method is that I blindly follow step my step without internalizing or completely understanding what’s happening. For this project I was able to set up Devise and enable Facebook’s Omniauth three times, so now it’s solidified in my brain. It got me thinking, that for future projects when I’m using a new gem I should make sure I really know what the gem is doing, so when if I run into a bug I’m better equipped to resolve the issue.

Nested resource show page

A feature of the app I was excited to implement was to view the history of classes by client. This would help the user zoom in on which templates to research and take ideas from.

Each class would be represented by a link that would then take the user to a nested resource show page, which would have all the available information about the class.

The code behind this feature was fairly simple, yet important to break down.

<p>History of Classes:</p>
<% @client.yoga_classes.each do |yoga_class| %>
  <%= link_to yoga_class.title, client_yoga_class_path(@client, yoga_class)%>
<% end %>

In my client model I defined the relationship that a client has_many yoga_classes. This then gave me access to call on an instance of a client and a list of their associated yoga_class objects which are assorted in an array. Then, I called an iteration on each yoga_class to create a link for the specific yoga_class. With link_to, the first part of the link is what the name of the link is, and the second piece is the path the link takes. So, I named each link the title of the yoga_class. Then, I used the route helper (route helpers are a piece of magic given by Rails) client_yoga_class_path(@client, yoga_class) so that a specific class would be nested underneath the client. @client was the first argument of the path because the helper needs to know which client_id will have all of its associated yoga_classes listed. Then, the url needs to know which yoga_class to route to based on the yoga_class id attribute. This helper is constructing the following template of the url: /clients/:client_id/yoga_classes/:id. As you can see in the screenshot above, the yoga_class has a client_id of 5 and an id of 4.

Just getting started….

Building the private group class tracker application taught me A LOT. I have a lot of ideas about what kind of future implementations I want to build for the app- like duplicating a template, since there should be a template representing each time a teacher taught a yoga class. Also, I’m looking forward to learning JavaScript and React to enhance the UI of my application. This is just the beginning!