Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 2 months ago

Time Tracking Dashboard

P
joeabrahamian•140
@joeabrahamian
A solution to the Time tracking dashboard challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

I got my media queries better than how I had them last project. I would have used a for loop or forEach to loop through the data and adjust DOM elements.

What challenges did you encounter, and how did you overcome them?

Some unfamiliarity with fetch api, promises, and async/await. Did some research and was able to use them in this project.

What specific areas of your project would you like help with?

Iterating over my data with the different loops and updating the DOM that way. I manually did each element.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Gregor de Cillia•190
    @GregorDeCillia
    Posted about 2 months ago

    Hey, great work!

    Some quick words about the css: you could have made a 2-column and 3-column layout via additional breakpoints. It's not as hard as it sounds since the styling for the inividual cards would be the same as in the 4 column layout.

    Fetching and Iterating

    Getting started with iteration (loops) and the fetch api can be daunting. Your approach ended up using a lot of repetition on the HTML side. What I ended up doing instead was creating html strings and inserting them.

    const template = ({name, current, previous, unit, img, color}) => `
    <section class="card activity-card" style="background: ${color}">
      <img class="activity-img" src="images/icon-${img}.svg" alt="">
      <div class="card-top">
        <div class="activity-title">
          <h2>${name}</h2>
          <div class="activity-menu"></div>
        </div>
        <div class="activity-values">
          <div class="value-current">${current}hrs</div>
          <div class="value-previous">${unit} - ${previous}hrs</div>
        </div>
      </div>
    </section>`;
    

    This means that if you want to make changes to the HTML structure, you only need to do it in one place.

    But let's talk about extending your approach

    If you don't want to touch the HTML again, another thing you could do is to add functions to your code that return DOM nodes

    const qs = q => document.querySlector(q)
    const getCurrent = item => qs(`#current-${item}`)
    const getPrevious = item => qs(`#previous-${item}`)
    const getTitle = item => qs(`#${item}`)
    

    The dataset is an arry, so you can use many techniques to loop over them. I would recommend a for...of loop.

    let timeframe = "weekly"
    for (const {title, timeframes} of data) {
      const {current, previous} = timeframes[timeframe];
      console.log({title, current, previous})
    }
    

    Running this will show you that you iterate over the relevant data. The next step is modifying the DOM. For that I define another helper function toKebapCase(), which converts the titles from the data into a shape that is compatible with your ids.

    const toKebapCase = str => str.toLowerCase().replace(" ", "-");
    toKebapCase("Self Care")
    // "self-care"
    

    Combining those techniques allows you to define a function that upates the DOM. It is very similar to the update functions from your js file.

    const updateTime(timeframe = "weekly") {
      for (const {title, timeframes} of data) {
        const {current, previous} = timeframes[timeframe];
        const item = toKebapCase(title)
        getCurrent(item).innerText = current;
        getPrevious(item).innerText = previous;
        getTitle(item).innerText = title;
      }
    }
    

    Now you bind all this to click events

    qs("#daily-button").addEventListener("click", _ => updateTime("daily"));
    qs("#weekly-button").addEventListener("click", _ => updateTime("weekly"));
    qs("#monthly-button").addEventListener("click", _ => updateTime("monthly"));
    

    Summary

    I know this is a lot to take in. Take your time to understand what these elements do. One technique I used in the loop is called destructuring. It allows you to make js codes shorter and more expressive, especially with 2 dimensional data.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub