<commit_before>import { warningNotification } from "../actions/notifications";
import { charonAPIAddress } from "./globals";
import { NEW_NARRATIVE, NEW_POST } from "../actions/types";

// eslint-disable-next-line
export const getNarrative = (dispatch, datapath) => {
  const errorHandler = (e) => {
    // dispatch(warningNotification({message: "Failed to get narrative from server"}));
    console.error("Failed to get narrative from server");
    console.error(e);
  };
  const xmlHttp = new XMLHttpRequest();
  xmlHttp.onload = () => {
    if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
      dispatch({
        type: NEW_NARRATIVE,
        blocks: JSON.parse(xmlHttp.responseText)
      });
    } else {
      errorHandler(xmlHttp);
    }
  };
  xmlHttp.onerror = errorHandler;
  const name = datapath.replace(/^\//, '').replace(/\//, '_');
  xmlHttp.open("get", `${charonAPIAddress}request=narrative&name=${name}`, true);
  xmlHttp.send(null);
};


export const getPost = (name) => (dispatch) => {
  console.log("fetching", name)
  const errorHandler = (e) => {
    dispatch(warningNotification({
      message: "Failed to get post from server",
      details: name
    }));
    console.error(e);
  };
  const xmlHttp = new XMLHttpRequest();
  xmlHttp.onload = () => {
    if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
      dispatch({
        type: NEW_POST,
        html: xmlHttp.responseText,
        name: name
      });
    } else {
      errorHandler(xmlHttp);
    }
  };
  xmlHttp.onerror = errorHandler;
  xmlHttp.open("get", `${charonAPIAddress}request=post&path=${name}`, true);
  xmlHttp.send(null);
}
<commit_msg>posts use URL pushState<commit_after>import { warningNotification } from "../actions/notifications";
import { charonAPIAddress } from "./globals";
import { NEW_NARRATIVE, NEW_POST } from "../actions/types";

// eslint-disable-next-line
export const getNarrative = (dispatch, datapath) => {
  const errorHandler = (e) => {
    // dispatch(warningNotification({message: "Failed to get narrative from server"}));
    console.error("Failed to get narrative from server");
    console.error(e);
  };
  const xmlHttp = new XMLHttpRequest();
  xmlHttp.onload = () => {
    if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
      dispatch({
        type: NEW_NARRATIVE,
        blocks: JSON.parse(xmlHttp.responseText)
      });
    } else {
      errorHandler(xmlHttp);
    }
  };
  xmlHttp.onerror = errorHandler;
  const name = datapath.replace(/^\//, '').replace(/\//, '_');
  xmlHttp.open("get", `${charonAPIAddress}request=narrative&name=${name}`, true);
  xmlHttp.send(null);
};


export const getPost = (name) => (dispatch) => {
  console.log("fetching", name)
  const errorHandler = (e) => {
    dispatch(warningNotification({
      message: "Failed to get post from server",
      details: name
    }));
    console.error(e);
  };
  const xmlHttp = new XMLHttpRequest();
  xmlHttp.onload = () => {
    if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
      dispatch({
        type: NEW_POST,
        html: xmlHttp.responseText,
        name: name,
        pushState: true
      });
    } else {
      errorHandler(xmlHttp);
    }
  };
  xmlHttp.onerror = errorHandler;
  xmlHttp.open("get", `${charonAPIAddress}request=post&path=${name}`, true);
  xmlHttp.send(null);
}

{'fraction_non_alphanumeric': 0.1657194137002692, 'fraction_numerical': 0.004786120251271313, 'mean_word_length': 3.232911392405063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 36}, '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': '6239327', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1051, 'n_words': 223}