{"size": 1781, "ext": "js", "max_stars_repo_path": "frontend/src/components/notifications/TaskNotification.js", "max_stars_repo_name": "nitoygo/nippols", "max_stars_repo_stars_event_min_datetime": "2018-03-30T09:55:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T06:56:45.000Z", "max_issues_repo_path": "frontend/src/components/notifications/TaskNotification.js", "max_issues_repo_name": "nitoygo/nippols", "max_issues_repo_issues_event_min_datetime": "2019-02-14T17:04:44.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-17T17:46:13.000Z", "max_forks_repo_path": "frontend/src/components/notifications/TaskNotification.js", "max_forks_repo_name": "nitoygo/nippols", "max_forks_repo_forks_event_min_datetime": "2019-02-22T06:16:53.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-22T06:16:53.000Z"}
{"max_stars_count": 4, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 21.4578313253, "max_line_length": 85, "alphanum_fraction": 0.5743964065}

import React from 'react';

import AlarmService from '../../_utilities/alarmService';

const tasks = ['Dummy Task 1', 'Dummy Task 2'];

class TaskNotification extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      ignore: true,
      title: '',
      dialogOpen: false,
      selectedValue: tasks[1]
    };

    //Get this value from user configuration next time

    //30 minutes
    //this.taskTimer = new AlarmService(this.showNotification.bind(this), 1800000);

    //1 minute
    //this.taskTimer = new AlarmService(this.showNotification.bind(this), 60000);

    //10 seconds
    this.taskTimer = new AlarmService(this.showNotification.bind(this), 15000);
  }

  startTaskPolling() {
    this.taskTimer.start();
  }

  showNotification() {
    const title = 'NIPPO Time Tracker Service';
    const body = 'Click here to change task';

    // Available options:
    // See https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification
    const options = {
      body: body,
      dir: 'ltr',
      icon: '/favicon.ico',
      tag: 'dummyTag',
      requireInteraction: true,
      actions: [
        {
          action: 'action 1',
          title: 'action 1',
        },
        {
          title: 'action 2',
          action: 'action 2',
        }
      ],
    };

    window.Notification.requestPermission(function (permission) {
      if (permission === 'granted') {
        if ('serviceWorker' in navigator) {
          navigator.serviceWorker.ready.then(registration => {
            registration.showNotification(
              title,
              options
            );
          });
        }
      }
    });
  }

  render() {

    return (
      <div>
      </div>
    )
  }
};

export default TaskNotification;
