<commit_before>import { remote } from "electron";
import fs from "fs";

import notificationSystem from "../notifications";
import { verifyFileContent } from "../utils";

const dialog = remote.require("dialog");

const getFileContent = (slidesStore) => JSON.stringify({
  content: {
    slides: slidesStore.serialize()
  }
});

const saveFile = (fileName, fileContent, fileStore) => {
  fs.writeFile(fileName, fileContent, (err) => {
    if (err) {
      notificationSystem.addNotification({
        message: "Error saving presentation",
        level: "error"
      });

      return;
    }

    notificationSystem.addNotification({
      message: "Save successful",
      level: "success"
    });

    fileStore.setFileName(fileName);
    fileStore.setIsDirty(false);
  });
};

export const fileActions = {
  save: (slidesStore, fileStore) => {
    if (fileStore.fileName) {
      saveFile(fileStore.fileName, getFileContent(slidesStore), fileStore);

      return;
    }

    dialog.showSaveDialog({
      filters: [{
        name: "json",
        extensions: ["json"]
      }]
    }, (fileName) => {
      if (fileName === undefined) {
        return;
      }

      const normalizedName = fileName.substr(-5) === ".json" ? fileName : `${fileName}.json`;

      saveFile(normalizedName, getFileContent(slidesStore), fileStore);
    });
  },
  open: (slidesStore, fileStore) => {
    dialog.showOpenDialog({
      filters: [{
        name: "json",
        extensions: ["json"]
      }]
    }, (fileNames) => {
      if (fileNames === undefined) return;
      const fileName = fileNames[0];

      // TODO: error handling
      fs.readFile(fileName, "utf-8", (err, data) => {
        if (err) {
          notificationSystem.addNotification({
            message: "Error opening presentation",
            level: "error"
          });
        }

        let fileContents;

        try {
          fileContents = JSON.parse(data);
        } catch (e) {
          notificationSystem.addNotification({
            message: "Error opening presentation",
            level: "error"
          });
        }

        verifyFileContent(fileContents, (schemaError) => {
          console.log(schemaError);
<commit_msg>remove unnecessary console<commit_after>import { remote } from "electron";
import fs from "fs";

import notificationSystem from "../notifications";
import { verifyFileContent } from "../utils";

const dialog = remote.require("dialog");

const getFileContent = (slidesStore) => JSON.stringify({
  content: {
    slides: slidesStore.serialize()
  }
});

const saveFile = (fileName, fileContent, fileStore) => {
  fs.writeFile(fileName, fileContent, (err) => {
    if (err) {
      notificationSystem.addNotification({
        message: "Error saving presentation",
        level: "error"
      });

      return;
    }

    notificationSystem.addNotification({
      message: "Save successful",
      level: "success"
    });

    fileStore.setFileName(fileName);
    fileStore.setIsDirty(false);
  });
};

export const fileActions = {
  save: (slidesStore, fileStore) => {
    if (fileStore.fileName) {
      saveFile(fileStore.fileName, getFileContent(slidesStore), fileStore);

      return;
    }

    dialog.showSaveDialog({
      filters: [{
        name: "json",
        extensions: ["json"]
      }]
    }, (fileName) => {
      if (fileName === undefined) {
        return;
      }

      const normalizedName = fileName.substr(-5) === ".json" ? fileName : `${fileName}.json`;

      saveFile(normalizedName, getFileContent(slidesStore), fileStore);
    });
  },
  open: (slidesStore, fileStore) => {
    dialog.showOpenDialog({
      filters: [{
        name: "json",
        extensions: ["json"]
      }]
    }, (fileNames) => {
      if (fileNames === undefined) return;
      const fileName = fileNames[0];

      // TODO: error handling
      fs.readFile(fileName, "utf-8", (err, data) => {
        if (err) {
          notificationSystem.addNotification({
            message: "Error opening presentation",
            level: "error"
          });
        }

        let fileContents;

        try {
          fileContents = JSON.parse(data);
        } catch (e) {
          notificationSystem.addNotification({
            message: "Error opening presentation",
            level: "error"
          });
        }

        verifyFileContent(fileContents, (schemaError) => {
{'fraction_non_alphanumeric': 0.13928083750568956, 'fraction_numerical': 0.0013654984069185253, 'mean_word_length': 2.4175738724727838, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '4300068', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1234, 'n_words': 269}