Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracker for time spent working #79

Open
isabelle926 opened this issue Apr 18, 2024 · 0 comments
Open

Tracker for time spent working #79

isabelle926 opened this issue Apr 18, 2024 · 0 comments
Assignees

Comments

@isabelle926
Copy link
Collaborator

isabelle926 commented Apr 18, 2024

Time Tracking Dashboard

Users will be able to input the time that they spend studying, coding, or exercising for each day as well as the total number of hours they spent performing those activities in the past week and month.

Note: only frontend is currently finished

Example code for exercise category:
 <div class="time__trackers">
          <div class="daily">
            <label for="exerciseDaily">Daily:</label>
            <input type="number" id="exerciseDaily" min="0" step="1">
            <button onclick="updateHours('exerciseDaily')">Update</button>
          </div>

          <div class="weekly">
            <p class="time__tracked">0hrs</p>
          </div>

          <div class="monthly">
            <p class="time__tracked">0hrs</p>
          </div>
        </div>
Example code for calculating total hours:
function updateHours(id) {
        const input = document.getElementById(id);
        const value = input.value;
        const category = id.replace(/[0-9]/g, '');

        const dailyTracker = document.querySelector(`.${category} .daily .time__tracked`);
        dailyTracker.textContent = `${value}hr`;

        const pastDays = [3, 4, 5, 6, 7, 8, 9];
        const dailyHours = parseFloat(value);

        const weeklyHours = pastDays.reduce((total, day) => {
        return total + (dailyHours * 1.5);
        }, dailyHours);

        const monthlyHours = pastDays.reduce((total, day) => {
        return total + (dailyHours * 1.2);
        }, dailyHours);

        fetch('/saveHours', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            category,
            daily: dailyHours,
            weekly: weeklyHours,
            monthly: monthlyHours
        }),
        })
        .then(response => response.json())
        .then(data => {
        if (data.success) {
            console.log('Hours saved successfully');
        } else {
            console.error('Failed to save hours');
        }
        })
        .catch(error => {
        console.error('Error saving hours:', error);
        });
    }
@isabelle926 isabelle926 self-assigned this Apr 18, 2024
@isabelle926 isabelle926 converted this from a draft issue Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant