<commit_before>/**
 * Helper functions for loading and saving graphs to/from local storage
 */

/**
 * takes a graph object & graph name, stringifies, and saves to local storage
 * in "saved" object with unique key of date string
 */
export const saveGraphToLocal = (graph, name, preview) => {
  let savedGraphs = localStorage.getItem('gifsmos-saved-graphs');
  if (!savedGraphs) {
    savedGraphs = {
      saved: {}
    };
  } else {
    savedGraphs = JSON.parse(savedGraphs);
  }
  const newGraph = {
    name,
    graph,
    preview
  };
  let timeStamp = new Date().toString();
  timeStamp = timeStamp.slice(0, timeStamp.indexOf('(') - 1);
  savedGraphs.saved[timeStamp] = newGraph;
  localStorage.setItem('gifsmos-saved-graphs', JSON.stringify(savedGraphs));
};

/**
 * takes a date string and retrieves the graph object from local storage
 * returns graph object
 */

export const getGraphFromLocal = dateString => {
  console.log(typeof dateString);

  let savedGraphs = JSON.parse(localStorage.getItem('gifsmos-saved-graphs'));
  return savedGraphs.saved[dateString].graph;
};

/**
 * returns an array of objects with a name and dateStrings or
 * null if none saved
 */
export const getSavedGraphsList = () => {
  let savedGraphs = JSON.parse(localStorage.getItem('gifsmos-saved-graphs'));

  return savedGraphs
    ? Object.entries(savedGraphs.saved).map(([date, obj]) => [
        date,
        obj.name,
        obj.preview<commit_msg>change local storage helpers to return previous frames to update store on load<commit_after>/**
 * Helper functions for loading and saving graphs to/from local storage
 */

/**
 * takes a graph object & graph name, stringifies, and saves to local storage
 * in "saved" object with unique key of date string
 */
export const saveGraphToLocal = (graph, name, preview, frames, frameIDs) => {
  let savedGraphs = localStorage.getItem('gifsmos-saved-graphs');
  if (!savedGraphs) {
    savedGraphs = {
      saved: {}
    };
  } else {
    savedGraphs = JSON.parse(savedGraphs);
  }
  const newGraph = {
    name,
    graph,
    preview,
    frames,
    frameIDs
  };
  let timeStamp = new Date().toString();
  timeStamp = timeStamp.slice(0, timeStamp.indexOf('(') - 1);
  savedGraphs.saved[timeStamp] = newGraph;
  localStorage.setItem('gifsmos-saved-graphs', JSON.stringify(savedGraphs));
};

/**
 * takes a date string and retrieves the graph object from local storage
 * returns graph object
 */

export const getGraphFromLocal = dateString => {
  let savedGraphs = JSON.parse(localStorage.getItem('gifsmos-saved-graphs'));
  return savedGraphs.saved[dateString];
};

/**
 * returns an array of objects with a name and dateStrings or
 * null if none saved
 */
export const getSavedGraphsList = () => {
  let savedGraphs = JSON.parse(localStorage.getItem('gifsmos-saved-graphs'));

  return savedGraphs
    ? Object.entries(savedGraphs.saved).map(([date, obj]) => [
        date,
        obj.name,
        obj.preview
{'fraction_non_alphanumeric': 0.12187711006076975, 'fraction_numerical': 0.0013504388926401081, 'mean_word_length': 3.6442006269592477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1058003', 'n_tokens_mistral': 905, 'n_tokens_neox': 897, 'n_words': 251}