<commit_before>var dialogsModule = require("ui/dialogs");
var observableModule = require("data/observable");

var socialShare = require("nativescript-social-share");
var swipeDelete = require("../../shared/utils/ios-swipe-delete");
var GroceryListViewModel = require("../../shared/view-models/grocery-list-view-model");

var page;
var groceryList = new GroceryListViewModel([]);
var pageData = new observableModule.Observable({
	grocery: "",
	groceryList: groceryList
});

exports.loaded = function(args) {
	page = args.object;

	if (page.ios) {
		var listView = page.getViewById("groceryList");
		swipeDelete.enable(listView, function(index) {
			performDelete(index);
		});
	}

	page.bindingContext = pageData;

	groceryList.empty();

	pageData.set("isLoading", true);
	groceryList.load().then(function() {
		pageData.set("isLoading", false);

		// Fade in the ListView over 1 second
		page.getViewById("groceryList").animate({
			opacity: 1,
			duration: 1000
		});
	});
};

exports.add = function() {
	// Check for empty submission
	if (pageData.get("grocery").trim() !== "") {
		pageData.set("isLoading", true);
		page.getViewById("grocery").dismissSoftInput();
		groceryList.add(pageData.get("grocery"))
			.catch(function(error) {
				console.log(error);
				dialogsModule.alert({
					message: "An error occurred while adding an item to your list.",
					okButtonText: "OK"
				});
			})
			.then(function() {
				pageData.set("isLoading", false);
			});

		// Clear the textfield
		pageData.set("grocery", "");
	} else {
		dialogsModule.alert({
			message: "Enter a grocery item",
			okButtonText: "OK"
		});
	}
};

exports.share = function() {
	var list = [];
	for (var i = 0, size = groceryList.length; i < size ; i++) {
		list.push(groceryList.getItem(i).name);
	}
	var listString = list.join(", ").trim();
	socialShare.shareText(listString);
};

function performDelete(index) {
	pageData.set("isLoading", true);
	groceryList.delete(index)
		.then(function() {
			pageData.set("isLoading", false);
		})
		.catch(function() {
			pageData.set("isLoading", false);
		});
}

exports.delete = function(args) {
	var item = args.view.bindingContext;
	performDelete(groceryList.indexOf(item));
};<commit_msg>Handle errors from groceries being deleted<commit_after>var dialogsModule = require("ui/dialogs");
var observableModule = require("data/observable");

var socialShare = require("nativescript-social-share");
var swipeDelete = require("../../shared/utils/ios-swipe-delete");
var GroceryListViewModel = require("../../shared/view-models/grocery-list-view-model");

var page;
var groceryList = new GroceryListViewModel([]);
var pageData = new observableModule.Observable({
	grocery: "",
	groceryList: groceryList
});

exports.loaded = function(args) {
	page = args.object;

	if (page.ios) {
		var listView = page.getViewById("groceryList");
		swipeDelete.enable(listView, function(index) {
			performDelete(index);
		});
	}

	page.bindingContext = pageData;

	groceryList.empty();

	pageData.set("isLoading", true);
	groceryList.load().then(function() {
		pageData.set("isLoading", false);

		// Fade in the ListView over 1 second
		page.getViewById("groceryList").animate({
			opacity: 1,
			duration: 1000
		});
	});
};

exports.add = function() {
	// Check for empty submission
	if (pageData.get("grocery").trim() !== "") {
		pageData.set("isLoading", true);
		page.getViewById("grocery").dismissSoftInput();
		groceryList.add(pageData.get("grocery"))
			.catch(function(error) {
				console.log(error);
				dialogsModule.alert({
					message: "An error occurred while adding an item to your list.",
					okButtonText: "OK"
				});
			})
			.then(function() {
				pageData.set("isLoading", false);
			});

		// Clear the textfield
		pageData.set("grocery", "");
	} else {
		dialogsModule.alert({
			message: "Enter a grocery item",
			okButtonText: "OK"
		});
	}
};

exports.share = function() {
	var list = [];
	for (var i = 0, size = groceryList.length; i < size ; i++) {
		list.push(groceryList.getItem(i).name);
	}
	var listString = list.join(", ").trim();
	socialShare.shareText(listString);
};

function performDelete(index) {
	pageData.set("isLoading", true);
	groceryList.delete(index)
		.catch(function(error) {
			console.log(error);
			dialogsModule.alert({
				message: "An error occurred while adding an item to your list.",
				okButtonText: "OK"
			});
		})
		.then(function() {
			pageData.set("isLoading", false);
		});
}

exports.delete = function(args) {
	var item = args.view.bindingContext;
	performDelete(groceryList.indexOf(item));
};
{'fraction_non_alphanumeric': 0.17009632224168125, 'fraction_numerical': 0.003064798598949212, 'mean_word_length': 4.275981524249422, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5486587', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1492, 'n_words': 298}