Large diffs are not rendered by default.

@@ -19,85 +19,7 @@ class ProfileViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let requestParameters = ["fields": "id, email, first_name, last_name"]

let userDetails = FBSDKGraphRequest(graphPath: "me", parameters: requestParameters)

userDetails.startWithCompletionHandler { (connection, result, error: NSError!) -> Void in

if(error != nil) {
print("\(error.localizedDescription)")
return
}

if(result != nil) {

let userId:String = result["id"] as! String
let userFirstName:String? = result["first_name"] as? String
let userLastName:String? = result["last_name"] as? String
let userEmail:String? = result["email"] as? String

print("\(userEmail)")

let myUser:PFUser = PFUser.currentUser()!

//save their firstname
if(userFirstName != nil) {
myUser.setObject(userFirstName!, forKey: "first_name")
}

//save their lastname
if(userLastName != nil) {
myUser.setObject(userLastName!, forKey: "last_name")
}

// Save email address
if(userEmail != nil)
{
myUser.setObject(userEmail!, forKey: "email")
}

//dispatch asynch task
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {


// Get Facebook profile picture
var userProfile = "https://graph.facebook.com/" + userId + "/picture?type=large"

let profilePictureUrl = NSURL(string: userProfile)

let profilePictureData = NSData(contentsOfURL: profilePictureUrl!)

if(profilePictureData != nil) {
let profileFileObject = PFFile(data: profilePictureData!)
myUser.setObject(profileFileObject!, forKey: "profile_picture")

}

myUser.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in

if(success) {
print("user details are updated brah!")
}

})
}

}

}
}

// func updateProfileInfo() {
// var profileQuery = PFQuery(className: "User")

// profileQuery.findObjectsInBackgroundWithBlock { (profileInfo, error: NSError?) -> Void in
// print(profileQuery)
// }

// }

@IBAction func signOutButtonTapped(sender: AnyObject) {
PFUser.logOutInBackgroundWithBlock { (error: NSError?) -> Void in
@@ -0,0 +1,26 @@
//
// ShopCell.swift
// Vader
//
// Created by James Kang on 12/30/15.
// Copyright © 2015 James Kang. All rights reserved.

import UIKit

//custom cell for shop cells
class ShopCell: UITableViewCell {

@IBOutlet weak var shopImage: UIImageView!
@IBOutlet weak var itemNameLabel: UILabel!
@IBOutlet weak var sellerNameLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!


override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}


}
@@ -0,0 +1,33 @@
//
// ShopDetailViewController.swift
// Vader
//
// Created by James Kang on 1/2/16.
// Copyright © 2016 James Kang. All rights reserved.
//
import UIKit

class ShopDetailViewController: UIViewController {

@IBOutlet weak var itemNameDetailLabel: UILabel!
@IBOutlet weak var sellerNameDetailLabel: UILabel!
@IBOutlet weak var priceDetailLabel: UILabel!
@IBOutlet weak var itemDescriptionDetailLabel: UILabel!
@IBOutlet weak var shopDetailImage: UIImageView!
@IBOutlet weak var sellerProfileDetailImage: UIImageView!

var itemName = ""

override func viewDidLoad() {
super.viewDidLoad()

self.itemNameDetailLabel.text = self.itemName

// Do any additional setup after loading the view.

}


}
@@ -7,14 +7,92 @@
//
import UIKit
import Parse

class ShopViewController: UIViewController {

class ShopViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

@IBOutlet weak var shopTableView: UITableView!

var shopPosts = [PFObject]()
var imageFile = [PFFile]()

override func viewDidLoad() {
super.viewDidLoad()

self.shopTableView.dataSource = self
self.shopTableView.delegate = self

}

override func viewDidAppear(animated: Bool) {
updateShopPost()
}

func updateShopPost() {

//trying to start query for username first_name
// let shopPostUsernameQuery = PFQuery(className: "User")
// shopPostUsernameQuery.orderByDescending("createdAt")
// shopPostUsernameQuery.findObjectsInBackgroundWithBlock { (shopPosts:[PFUser]?, error:NSError?) -> Void in
//
// if error == nil {
// self.shopPosts = shopPosts!
// self.shopTableView.reloadData()
//
//
// }
// }
// Do any additional setup after loading the view.
let shopPostQuery = PFQuery(className: "ShopPost")
//pic get attempt
shopPostQuery.orderByDescending("createdAt")
shopPostQuery.findObjectsInBackgroundWithBlock { (shopPosts:[PFObject]?, error:NSError?) -> Void in
if error == nil {
self.shopPosts = shopPosts!
self.shopTableView.reloadData()
}
}


}



func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.shopPosts.count
}
// updating what is in the cell from parse
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let shopCell = shopTableView.dequeueReusableCellWithIdentifier("shopCell") as! ShopCell
let shopPost = self.shopPosts[indexPath.row]

shopCell.itemNameLabel.text = shopPost["itemName"] as? String
shopCell.priceLabel.text = shopPost["itemPrice"] as? String
shopCell.sellerNameLabel.text = shopPost["first_name"] as? String

// shopCell.shopImage.image = shopPost["imageFile"] as? PFFile
//
let user = shopPost["user"] as! PFUser

user.fetchIfNeededInBackgroundWithBlock { (userDetails:PFObject?, error:NSError?) -> Void in
shopCell.sellerNameLabel.text = user["first_name"] as? String

}



return shopCell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
self.performSegueWithIdentifier("shopViewToShopDetailSegue", sender: nil)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// let shopDetailVC = segue.destinationViewController as! ShopDetailViewController
}

}
@@ -17,6 +17,12 @@ class ViewController: UIViewController {
// Do any additional setup after loading the view, typically from a nib.
}

override func viewDidAppear(animated: Bool) {
if PFUser.currentUser() != nil {
self.performSegueWithIdentifier("signInToShopSegue", sender: nil)
}
}

@IBAction func signInButtonTapped(sender: AnyObject) {

PFFacebookUtils.logInInBackgroundWithReadPermissions(["public_profile", "email", "user_friends"], block: { (user: PFUser?, error: NSError?) -> Void in
@@ -41,6 +47,74 @@ class ViewController: UIViewController {
if(FBSDKAccessToken.currentAccessToken() != nil) {

self.performSegueWithIdentifier("signInToShopSegue", sender: nil)
let requestParameters = ["fields": "id, email, first_name, last_name"]

let userDetails = FBSDKGraphRequest(graphPath: "me", parameters: requestParameters)

userDetails.startWithCompletionHandler { (connection, result, error: NSError!) -> Void in

if(error != nil) {
print("\(error.localizedDescription)")
return
}

if(result != nil) {

let userId:String = result["id"] as! String
let userFirstName:String? = result["first_name"] as? String
let userLastName:String? = result["last_name"] as? String
let userEmail:String? = result["email"] as? String

print("\(userEmail)")

let myUser:PFUser = PFUser.currentUser()!

//save their firstname
if(userFirstName != nil) {
myUser.setObject(userFirstName!, forKey: "first_name")
}

//save their lastname
if(userLastName != nil) {
myUser.setObject(userLastName!, forKey: "last_name")
}

// Save email address
if(userEmail != nil)
{
myUser.setObject(userEmail!, forKey: "email")
}

//dispatch asynch task
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {


// Get Facebook profile picture
var userProfile = "https://graph.facebook.com/" + userId + "/picture?type=large"

let profilePictureUrl = NSURL(string: userProfile)

let profilePictureData = NSData(contentsOfURL: profilePictureUrl!)

if(profilePictureData != nil) {
let profileFileObject = PFFile(data: profilePictureData!)
myUser.setObject(profileFileObject!, forKey: "profile_picture")

}

myUser.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in

if(success) {
print("user details are updated brah!")
}

})
}

}

}

// let profilePage = self.storyboard?.instantiateViewControllerWithIdentifier("ProfileViewController") as! ProfileViewController
//
// let profileNavigation = UINavigationController(rootViewController: profilePage)