{"size": 3446, "ext": "js", "max_stars_repo_path": "apps/andi/assets/js/app.js", "max_stars_repo_name": "calebcarroll1/smartcitiesdata", "max_stars_repo_stars_event_min_datetime": "2019-09-20T23:54:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-20T14:23:32.000Z", "max_issues_repo_path": "apps/andi/assets/js/app.js", "max_issues_repo_name": "calebcarroll1/smartcitiesdata", "max_issues_repo_issues_event_min_datetime": "2019-08-15T18:15:07.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-18T20:55:31.000Z", "max_forks_repo_path": "apps/andi/assets/js/app.js", "max_forks_repo_name": "calebcarroll1/smartcitiesdata", "max_forks_repo_forks_event_min_datetime": "2019-11-12T16:43:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-25T16:23:16.000Z"}
{"max_stars_count": 26, "max_issues_count": 757, "max_forks_count": 9, "avg_line_length": 27.7903225806, "max_line_length": 103, "alphanum_fraction": 0.5885084156}
// We need to import the CSS so that webpack will load it.
// The MiniCssExtractPlugin is used to separate it out into
// its own CSS file.
import 'tippy.js/dist/tippy.css';
import normalize_css from 'normalize.css'
import scss from "../css/app.scss"

import tippy from 'tippy.js';

// webpack automatically bundles all modules in your
// entry points. Those entry points can be configured
// in "webpack.config.js".
//
// Import dependencies
//
import "phoenix_html"

// Import local files
//
// Local files can be imported directly using relative paths, for example:
// import socket from "./socket"
import { Socket } from 'phoenix'
import { LiveSocket } from 'phoenix_live_view'

let Hooks = {}

Hooks.showSnackbar = {
    updated() {
        let snackbar = document.getElementById("snackbar");
        snackbar.className += " show";
        setTimeout(function() { snackbar.className = snackbar.className.replace(" show", ""); }, 3000);
    }
}

Hooks.prettify = {
    mounted() {
        this.el.value =  prettifyJsonString(this.el.value);
    }
}

Hooks.readFile = {
    mounted() {
        this.el.addEventListener("change", e => {
            this.pushEvent("file_upload_started");
            var file = this.el.files[0];

            fileToText(this.el.files[0]).then(fileAsText => {
                this.pushEvent("file_upload", {
                    file: fileAsText,
                    fileType: file["type"],
                    fileSize: file["size"],
                    fileName: file["name"]
                });
            }, reason => {
                reason == "aborted" && this.pushEvent("file_upload_cancelled");
            });
        })
    }
}

Hooks.addTooltip = {
    mounted() {
        const element = this.el;
        const initialContent = element.dataset.tooltipContent;
        tippy(element, {
            content: initialContent,
            allowHTML: true,
            interactive: true,
            maxWidth: "none",
            onShow(instance) {
                const updatedContent = element.dataset.tooltipContent;
                instance.setContent(updatedContent);
            }
        });
    }
}

const prettifyJsonString = (str) => {
    try {
        var json = JSON.parse(str);
        var json_string = JSON.stringify(json, undefined, 4);
        return json_string;
    } catch (error) {
        return str;
    }
};

const fileToText = (file) => new Promise((resolve, reject) => {
    var fileInput = file["type"] == "text/csv" ? file.slice(0, 1500) : file
    var reader = new FileReader();
    var totalBytes = fileInput["size"];
    var CHUNK_SIZE = 1024;
    var offset = 0;
    var fileString = "";

    reader.onabort = () => reject("aborted");

    reader.onerror = error => reject(error);

    document.getElementById("reader-cancel").addEventListener("click", () => {
        reader.abort();
    })

    reader.onload = () => {
        fileString += reader.result;
        offset += CHUNK_SIZE;

        if(offset >= totalBytes) {
            resolve(fileString);
        } else {
            var slice = fileInput.slice(offset, offset + CHUNK_SIZE);
            reader.readAsText(slice);
        }
    }

    reader.readAsText(fileInput.slice(0, CHUNK_SIZE));
});


let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
let liveSocket = new LiveSocket('/live', Socket, {hooks: Hooks, params: {_csrf_token: csrfToken}})
liveSocket.connect()

