<commit_before>$(document).ready(function() {
    var userEtag = '';
    var currentUser = {};
    var userSavedSymptomObject = {};
    var drugSelected = [];
    var currentUserID = '107580231397808901546';
    var currentUserImg;
    var currentUserName = "Sign in to load your data!"
        // firebas congfig and cached functions
    var config = {
        apiKey: "<KEY>",
        authDomain: "my-awesome-project-2b194.firebaseapp.com",
        databaseURL: "https://my-awesome-project-2b194.firebaseio.com",
        storageBucket: "my-awesome-project-2b194.appspot.com",
        messagingSenderId: "901877515687"
    };
    firebase.initializeApp(config);

    var database = firebase.database();
    var databaseRef = database.ref();
    var userList = database.ref('users/');

    var isDrugPanelOpen = false;
    var isSympPanelOpen = false;

    var googleMapsKey = '<KEY>';

    getGeoTags();

    if (localStorage.getItem('userLogon')) {
        console.log('Current User Detected');
        currentUserID = localStorage.getItem('userLogon');
    } else {
        currentUserID = "Default";
    }


    var getUser = function(userID) {
        database.ref('/users/' + userID).once('value').then(function(snapshot) {
            currentUser = snapshot.val();
            // console.log(currentUser);
            if (!currentUser) {
                writeUserData(userID, currentUserName, currentUserImg, drugSelected, userSavedSymptomObject);
                location.reload(true);
                $('#username').text('Hey ' + currentUserName + '! Thanks for joining MedMagnet!');
                $('#profileImg').attr('src', currentUserImg);
            } else {
                // console.log('Works');
                currentUserName = currentUser.username;
                currentUserImg = currentUser.profile_picture;
                drugSelected = JSON.parse(currentUser.drugList);
                userSavedSymptomObject = JSON.parse(currentUser.symptomsList);
                writeUserData(userID, currentUserName, currentUserImg, drugSelected, userSavedSymptomObject);
                if (currentUserName === "") {
                    $('#username').text('Welcome back ' + currentUserName + '!');
                } else {
                    $('#username').text(currentUserName);
                }


                if (currentUserImg) {
                    $('#profileImg').attr('src', currentUserImg);
                }
                renderDrugList(drugSelected);
            }
        });
    };


    var delete_cookie = function(name) {
        document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
    };

    var signout = function() {
        hello('google').logout()
        localStorage.removeItem('hello');
        localStorage.removeItem('userLogon');
        delete_cookie('NID');
        document.location.href = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=http://dangnabit.github.io/Med_Magnet/index.html";
    };




    var signin = function() {
        hello('google').login(function(){
            console.log('window.reload');
            setTimeout(function(){ window.location.reload() }, 1500);
        });

    };

    // Hello init, contains browers secret
    hello.init({
        google: "901877515687-0d07o7leoihhv3ina4bqcv40ab347q86.apps.googleusercontent.com"
    }, {
        redirect_uri: 'https://lmcfinn.github.io/Med_Magnet/index.html'
    });

    hello.on('auth.login', function(auth) {
        // Call user information, for the given network
        hello(auth.network).api('me').then(function(r) {

            // Inject it into the container
            var googSession = hello('google').getAuthResponse()
            var googAccessToken = googSession.access_token
            var googExpires = googSession.expires
            currentUserID = r.id;
            currentUserImg = r.thumbnail;
            currentUserName = r.name;
            $('#username').text('Welcome back ' + currentUserName + '!');
            $('#profileImg').attr('src', currentUserImg);
            $('#signOut').removeClass('hidden');

            console.log(currentUserID);
            localStorage.setItem('userLogon', currentUserID);
            getuser(currentUserID);
            writeUserData(currentUserID, currentUserName, currentUserImg, drugSelected, userSavedSymptomObject);

        });
    });

    // writes user data to firebase
    var writeUserData = function(userId, name, imageUrl, drugs, symptoms) {
        if (userId !== 'Default') {

            firebase.database().ref('users/' + userId).update({
                username: name,
                profile_picture: imageUrl,
                drugList: JSON.stringify(drugs),
                symptomsList: JSON.stringify(symptoms)
            });
            localStorage.setItem('userLogon', userId);
        }
    }
    $('#signIn').on('click', function() {
        signin();
    })

    $('#signOut').on('click', function() {
        signout();
    })


    var setDrugtoProfile = function(drugs) {
        writeUserData(currentUserID, currentUserName, currentUserImg, drugs, userSavedSymptomObject);<commit_msg>Window reload as callback inside .then<commit_after>$(document).ready(function() {
    var userEtag = '';
    var currentUser = {};
    var userSavedSymptomObject = {};
    var drugSelected = [];
    var currentUserID = '107580231397808901546';
    var currentUserImg;
    var currentUserName = "Sign in to load your data!"
        // firebas congfig and cached functions
    var config = {
        apiKey: "<KEY>",
        authDomain: "my-awesome-project-2b194.firebaseapp.com",
        databaseURL: "https://my-awesome-project-2b194.firebaseio.com",
        storageBucket: "my-awesome-project-2b194.appspot.com",
        messagingSenderId: "901877515687"
    };
    firebase.initializeApp(config);

    var database = firebase.database();
    var databaseRef = database.ref();
    var userList = database.ref('users/');

    var isDrugPanelOpen = false;
    var isSympPanelOpen = false;

    var googleMapsKey = '<KEY>';

    getGeoTags();

    if (localStorage.getItem('userLogon')) {
        console.log('Current User Detected');
        currentUserID = localStorage.getItem('userLogon');
    } else {
        currentUserID = "Default";
    }


    var getUser = function(userID) {
        database.ref('/users/' + userID).once('value').then(function(snapshot) {
            currentUser = snapshot.val();
            // console.log(currentUser);
            if (!currentUser) {
                writeUserData(userID, currentUserName, currentUserImg, drugSelected, userSavedSymptomObject);
                location.reload(true);
                $('#username').text('Hey ' + currentUserName + '! Thanks for joining MedMagnet!');
                $('#profileImg').attr('src', currentUserImg);
            } else {
                // console.log('Works');
                currentUserName = currentUser.username;
                currentUserImg = currentUser.profile_picture;
                drugSelected = JSON.parse(currentUser.drugList);
                userSavedSymptomObject = JSON.parse(currentUser.symptomsList);
                writeUserData(userID, currentUserName, currentUserImg, drugSelected, userSavedSymptomObject);
                if (currentUserName === "") {
                    $('#username').text('Welcome back ' + currentUserName + '!');
                } else {
                    $('#username').text(currentUserName);
                }


                if (currentUserImg) {
                    $('#profileImg').attr('src', currentUserImg);
                }
                renderDrugList(drugSelected);
            }
        });
    };


    var delete_cookie = function(name) {
        document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
    };

    var signout = function() {
        hello('google').logout()
        localStorage.removeItem('hello');
        localStorage.removeItem('userLogon');
        delete_cookie('NID');
        document.location.href = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=http://dangnabit.github.io/Med_Magnet/index.html";
    };




    var signin = function() {
        hello('google').login().then(function(){
            hello('google').login(function(){
            window.location.reload();
        });
        });

    };

    // Hello init, contains browers secret
    hello.init({
        google: "901877515687-0d07o7leoihhv3ina4bqcv40ab347q86.apps.googleusercontent.com"
    }, {
        redirect_uri: 'https://lmcfinn.github.io/Med_Magnet/index.html'
    });

    hello.on('auth.login', function(auth) {
        // Call user information, for the given network
        hello(auth.network).api('me').then(function(r) {

            // Inject it into the container
            var googSession = hello('google').getAuthResponse()
            var googAccessToken = googSession.access_token
            var googExpires = googSession.expires
            currentUserID = r.id;
            currentUserImg = r.thumbnail;
            currentUserName = r.name;
            $('#username').text('Welcome back ' + currentUserName + '!');
            $('#profileImg').attr('src', currentUserImg);
            $('#signOut').removeClass('hidden');

            console.log(currentUserID);
            localStorage.setItem('userLogon', currentUserID);
            getuser(currentUserID);
            writeUserData(currentUserID, currentUserName, currentUserImg, drugSelected, userSavedSymptomObject);
        });
    });

    // writes user data to firebase
    var writeUserData = function(userId, name, imageUrl, drugs, symptoms) {
        if (userId !== 'Default') {

            firebase.database().ref('users/' + userId).update({
                username: name,
                profile_picture: imageUrl,
                drugList: JSON.stringify(drugs),
                symptomsList: JSON.stringify(symptoms)
            });
            localStorage.setItem('userLogon', userId);
        }
    }
    $('#signIn').on('click', function() {
        signin();
    })

    $('#signOut').on('click', function() {
        signout();
    })


    var setDrugtoProfile = function(drugs) {
        writeUserData(currentUserID, currentUserName, currentUserImg, drugs, userSavedSymptomObject);
{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.01616161616161616, 'mean_word_length': 2.289873417721519, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, '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': '887802', 'n_tokens_mistral': 3044, 'n_tokens_neox': 2863, 'n_words': 490}