<reponame>IllusionOfControl/todoist-clone<filename>frontend/src/helpers/index.js<gh_stars>0import { collatedTasks } from '../constants';

export const getTitle = (projects, key) =>
  projects.find(project => project.id === key);

export const getCollatedTitle = (projects, key) =>
  projects.find(project => project.key === key);

export const collatedTasksExist = selectedProject =>
  collatedTasks.find(task => task.key === selectedProject);

export const generatePushId = (() => {
  const PUSH_CHARS =
    'ngw6fo1pu3tjgnp9jnlp7vnwvfqb9yn7';

  const lastRandChars = [];

  return function() {
    let now = new Date().getTime();

    const timeStampChars = new Array(8);
    for (var i = 7; i >= 0; i--) {
      timeStampChars[i] = PUSH_CHARS.charAt(now % 64);
      now = Math.floor(now / 64);
    }

    let id = timeStampChars.join('');

    for (i = 0; i < 12; i++) {
      id += PUSH_CHARS.charAt(lastRandChars[i]);
    }

    return id;
  };
})();
