Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 1 year ago

Time Tracking Dashboard with ReactJS

react, accessibility
Amr•710
@amrmabdelazeem
A solution to the Time tracking dashboard challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


The almost perfect design was not planned. x_x

Since I stopped coding with React for a while I'm struggling a bit with hooks and components but that ain't something that would stop me though.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Santiago Moraga Caldera•710
    @Remy349
    Posted over 1 year ago

    Hi @amrmabdelazeem, many congratulations on completing the challenge, it is really amazing and the final design is great.

    I reviewed your React code and I want to give you a tip to refactor the code found in the App.jsx component. I cloned your repository and edited the code to change the logic you have when rendering the Activity.jsx component. Instead of doing those component renderings using the if else you have nested, I recommend this way:

    import React, { useState } from "react";
    import Heading from "./Heading";
    import Activity from "./Activity";
    import data from "../data.json";
    
    export default function App() {
      const [time, setTime] = useState("weekly");
    
      function handleTime(childTime) {
        setTime(childTime);
      }
    
      const getTimeframeData = (item, timeframe) => ({
        key: timeframe,
        current: item.timeframes[timeframe].current,
        previous: item.timeframes[timeframe].previous,
      });
    
      return (
        <div className="container">
          <Heading onHandle={handleTime} />
          {data.map((item, index) => {
            const timeframeData = getTimeframeData(item, time);
    
            return (
              <Activity
                key={index}
                id={index}
                title={item.title}
                current={timeframeData.current}
                previous={timeframeData.previous}
              />
            );
          })}
        </div>
      );
    }
    

    A little explanation:

    Function getTimeframeData:

    const getTimeframeData = (item, timeframe) => ({
        key: timeframe,
        current: item.timeframes[timeframe].current,
        previous: item.timeframes[timeframe].previous,
      });
    
    • This function takes two arguments: item (representing an element of the array data.json) and timeframe (representing the current time period).
    • Returns an object with the keys key, current and previous, which correspond to the specific properties of the time period within the item.

    Component Rendering:

    return (
        <div className="container">
          <Heading onHandle={handleTime} />
          {data.map((item, index) => {
            const timeframeData = getTimeframeData(item, time);
    
            return (
              <Activity
                key={index}
                id={index}
                title={item.title}
                current={timeframeData.current}
                previous={timeframeData.previous}
              />
            );
          })}
        </div>
      );
    
    • Then, a mapping is performed on the array data using the map method.
    • For each item element, getTimeframeData is called to obtain the data specific to the current time period (time) and an <Activity /> component is rendered with that data.

    In short, the code uses the time state to track the current time period and a getTimeframeData function to get the time period specific data for each activity in the data array. Then, the interface is rendered based on this data.

    CONGRATULATIONS ON COMPLETING THE CHALLENGE. I hope my advice will be of great help to you :)

    Marked as helpful

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 1st-party linked stylesheets, and styles within <style> tags.

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.

Oops! 😬

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

Log in with GitHub