<commit_before>/* global ga */

const choo = require('choo');
const http = require('xhr');
const find = require('lodash/find');
const logger = require('loglevel');
const queryString = require('query-string');
const store = require('./utils/localstorage.js');
const localization = require('./utils/localization');
const scrollIntoView = require('./utils/scrollIntoView.js');

const app = choo();
const appURL = 'https://5calls.org';
// const appURL = 'http://localhost:8090';

// use localStorage directly to set this value *before* bootstrapping the app.
const debug = (localStorage['org.5calls.debug'] === 'true');

if (debug) {
  // we don't need loglevel's built-in persistence; we do it ourselves above ^
  logger.setLevel(logger.levels.TRACE, false);
}

// get the stored zip location
let cachedAddress = '';
store.getAll('org.5calls.location', (location) => {
  if (location.length > 0) {
   cachedAddress = location[0]
  }
});

// get the stored geo location
let cachedGeo = '';
store.getAll('org.5calls.geolocation', (geo) => {
  if (geo.length > 0) {
    logger.debug("geo get", geo[0]);
    cachedGeo = geo[0]
  }
});

let cachedFetchingLocation = (cachedGeo === '') ? true : false;

// get the stored geo location
let cachedAllowBrowserGeo = true;
store.getAll('org.5calls.allow_geolocation', (allowGeo) => {
  if (allowGeo.length > 0) {
    logger.debug("allowGeo get", allowGeo[0]);
    cachedAllowBrowserGeo = allowGeo[0]
  }
});

let cachedLocationFetchType = (cachedAllowBrowserGeo) ? 'browserGeolocation' : 'ipAddress';

// get the time the geo was last fetched
let cachedGeoTime = '';
store.getAll('org.5calls.geolocation_time', (geo) => {
  if (geo.length > 0) {
    logger.debug("geo time get", geo[0]);
    cachedGeoTime = geo[0]
  }
});

let cachedCity = '';
store.getAll('org.5calls.geolocation_city', (city) => {
  if (city.length > 0) {
    logger.debug("city get", city[0]);
    cachedCity = city[0]
  }
});

cachedFetchingLocation  = (cachedCity !== '') ? true : cachedFetchingLocation;
cachedLocationFetchType = (cachedAddress !== '') ? 'address' : cachedLocationFetchType;

// get the stored completed issues
let completedIssues = [];
store.getAll('org.5calls.completed', (completed) => {
  completedIssues = completed == null ? [] : completed;
});

let cachedUserLocale = '';
store.getAll('org.5calls.userlocale', (userLocale) => {
  if (userLocale.length > 0) {
    logger.debug("user locale get", userLocale[0]);
    cachedUserLocale = userLocale[0];
  } else {
    cachedUserLocale = localization.getLocaleFromBrowserLanguage(navigator.language || navigator.userLanguage);
    store.add('org.5calls.userlocale', cachedUserLocale, () => {});
  }
});

// get stored user stats
const defaultStats = {
  all: [],
  contacted: 0,
  vm: 0,
  unavailable: 0,
};
let localStats = defaultStats;
store.getAll('org.5calls.userStats', (stats) => {
  if (stats.length > 0) {
    localStats = stats[0];
  } else {
    let impactLink = document.querySelector('#impact__link');
    impactLink.classList.add('hidden');
  }
});

app.model({
  state: {
    // remote data
    issues: [],
    activeIssues: [],
    inactiveIssues: [],
    totalCalls: 0,
    splitDistrict: false,

    // manual input address
    address: cachedAddress,
<commit_msg>Removed the early call to hide the footer link which might not exist yet (#294)<commit_after>/* global ga */

const choo = require('choo');
const http = require('xhr');
const find = require('lodash/find');
const logger = require('loglevel');
const queryString = require('query-string');
const store = require('./utils/localstorage.js');
const localization = require('./utils/localization');
const scrollIntoView = require('./utils/scrollIntoView.js');

const app = choo();
const appURL = 'https://5calls.org';
// const appURL = 'http://localhost:8090';

// use localStorage directly to set this value *before* bootstrapping the app.
const debug = (localStorage['org.5calls.debug'] === 'true');

if (debug) {
  // we don't need loglevel's built-in persistence; we do it ourselves above ^
  logger.setLevel(logger.levels.TRACE, false);
}

// get the stored zip location
let cachedAddress = '';
store.getAll('org.5calls.location', (location) => {
  if (location.length > 0) {
   cachedAddress = location[0]
  }
});

// get the stored geo location
let cachedGeo = '';
store.getAll('org.5calls.geolocation', (geo) => {
  if (geo.length > 0) {
    logger.debug("geo get", geo[0]);
    cachedGeo = geo[0]
  }
});

let cachedFetchingLocation = (cachedGeo === '') ? true : false;

// get the stored geo location
let cachedAllowBrowserGeo = true;
store.getAll('org.5calls.allow_geolocation', (allowGeo) => {
  if (allowGeo.length > 0) {
    logger.debug("allowGeo get", allowGeo[0]);
    cachedAllowBrowserGeo = allowGeo[0]
  }
});

let cachedLocationFetchType = (cachedAllowBrowserGeo) ? 'browserGeolocation' : 'ipAddress';

// get the time the geo was last fetched
let cachedGeoTime = '';
store.getAll('org.5calls.geolocation_time', (geo) => {
  if (geo.length > 0) {
    logger.debug("geo time get", geo[0]);
    cachedGeoTime = geo[0]
  }
});

let cachedCity = '';
store.getAll('org.5calls.geolocation_city', (city) => {
  if (city.length > 0) {
    logger.debug("city get", city[0]);
    cachedCity = city[0]
  }
});

cachedFetchingLocation  = (cachedCity !== '') ? true : cachedFetchingLocation;
cachedLocationFetchType = (cachedAddress !== '') ? 'address' : cachedLocationFetchType;

// get the stored completed issues
let completedIssues = [];
store.getAll('org.5calls.completed', (completed) => {
  completedIssues = completed == null ? [] : completed;
});

let cachedUserLocale = '';
store.getAll('org.5calls.userlocale', (userLocale) => {
  if (userLocale.length > 0) {
    logger.debug("user locale get", userLocale[0]);
    cachedUserLocale = userLocale[0];
  } else {
    cachedUserLocale = localization.getLocaleFromBrowserLanguage(navigator.language || navigator.userLanguage);
    store.add('org.5calls.userlocale', cachedUserLocale, () => {});
  }
});

// get stored user stats
const defaultStats = {
  all: [],
  contacted: 0,
  vm: 0,
  unavailable: 0,
};
let localStats = defaultStats;
store.getAll('org.5calls.userStats', (stats) => {
  if (stats.length > 0) {
    localStats = stats[0];
  }
});

app.model({
  state: {
    // remote data
    issues: [],
    activeIssues: [],
    inactiveIssues: [],
    totalCalls: 0,
    splitDistrict: false,

    // manual input address
    address: cachedAddress,

{'fraction_non_alphanumeric': 0.16334722865524162, 'fraction_numerical': 0.012197004786166435, 'mean_word_length': 4.141269841269842, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 2, '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': '2082969', 'n_tokens_mistral': 2135, 'n_tokens_neox': 2098, 'n_words': 493}