Homework 5:

Table of Contents

Overview

The Challenge

Create a simple calendar application that allows a user to save events for each hour of the day. This app will run in the browser and feature dynamically updated HTML and CSS powered by jQuery.

The starter code uses the Moment.js (Links to an external site.) library to work with date and time, but feel free to use a different JavaScript solution to handle this functionality since Moment.js is considered a "legacy" project. Learn more about some alternative solutions in the Moment.js project status page.

IMPORTANT

Make sure to clone the starter code repository and make your own repository with the starter code. Do not fork the starter code repository!

Before you start, clone the starter code.

User Story

AS AN employee with a busy schedule
I WANT to add important events to a daily planner
SO THAT I can manage my time effectively

Acceptance Criteria

GIVEN I am using a daily planner to create a schedule
WHEN I open the planner
THEN the current day is displayed at the top of the calendar
WHEN I scroll down
THEN I am presented with time blocks for standard business hours
WHEN I view the time blocks for that day
THEN each time block is color-coded to indicate whether it is in the past, present, or future
WHEN I click into a time block
THEN I can enter an event
WHEN I click the save button for that time block
THEN the text for that event is saved in local storage
WHEN I refresh the page
THEN the saved events persist

Screenshot

Links

My Process

Built With

  • Semantic HTML5 Markup
  • CSS
  • JavaScript
  • jQuery
  • Moment.js
  • Bootstrap
  • Font Awesome

What I Learned

During this assignment, I learned how to loop through the various description textareas in order to save content in them using the saveBtn button.

// When the save button is clicked, store the data in localstorage.
$(".saveBtn").on("click", function () {

    // Set the key and value for input.
    let keyName = $(this).siblings(".description").attr("id");
    console.log(keyName);
    let valueName = $(this).siblings(".description").val();

    // Call the storeEvent function with fresh user input.
    storeEvent(keyName, valueName);
});

I also get more experience storing items to localStorage, then pulling them from localStorage for display.

// Store events in local storage.
function storeEvent(keyName, valueName) {
    let eventDesc = JSON.parse(localStorage.getItem("eventDesc"));

    if (eventDesc === null) {
        eventDesc = {};
    }

    eventDesc[keyName] = valueName;
    localStorage.setItem("eventDesc", JSON.stringify(eventDesc));
    displayEvent();
};

// Display events on the work day scheduler.
function displayEvent() {
    let eventDesc = JSON.parse(localStorage.getItem("eventDesc"));

    if (eventDesc === null) {
        return;
    }

    let textArea = $(".description");

    for (let i = 0; i < textArea.length; i++) {
        let hour = $(textArea[i]).attr("id");

        if (eventDesc[hour]) {
            $(textArea[i]).val(eventDesc[hour]);
        };
    };
};

Continued Development

I struggled in this particular exercise with pulling data that was stored in localStorage and displaying them on the page. I'd like to do more of this in the future to solidify my understanding of this and similar processes.

Useful Resources

Author

Acknowledgments

  • Fellow Bootcampers:
    • Nifer Kilakila
    • Ivy Chang
    • Nolan Spence
    • Michael Barrett
    • Kevin Muehlbauer
  • Bobbi Tarkany (Tutor)
  • AskBCS Slack Channel