FelixAlvarado / 360px

16 stars 0 forks source link

README

This site is a clone of 500px.com. While logged in, and one can view other people's photos on their feed, follow other users, and upload pictures of their own. Ruby on Rails was used for the back end, and React was used for the front end.

360px

Technologies

Key Features

Home and Discover Feeds

Text

    get '/feed', to: 'feeds#home', controller: 'feeds'
    get '/fresh', to: 'feeds#fresh', controller: 'feeds'
  def get_home_feed
    followings = self.followings
    pictures = []
    followings.each do |follow|
      user = User.find(follow.leader_id)
      pictures += user.pictures
    end
    if pictures.length < 30
      other_pictures = Picture.all.sort {|a,b| b.created_at <=> a.created_at}
      count = 0
      other_pictures.each do |picture|
        unless count == 3 || picture.uploader_id === self.id || pictures.include?(picture)
          pictures.push(picture)
          count += 1
        end

      end
    end
    pictures.sort {|a,b| b.created_at <=> a.created_at}.take(30)
  end

On the front end, html elements are rendered based on if the current user is following the user who posted the picture:

Followings

Follow demo

I really enjoyed implementing this in my website. It was fun planning out and and going through the steps these step. While the backend for implementing follows was faily simple, more logic was required in the front end.

export const findFollow = (follows, currentUserId, profileUserId) => {
  const followArr = Object.values(follows);
  for (var i = 0; i < followArr.length; i++) {
    const follow = followArr[i];
    if (follow.follower_id === currentUserId && follow.leader_id === profileUserId) {
      return follow;
    }
  }
  return null;
};
  updateFollow(){
    const {deleteFollow, createFollow, follow, user, currentUser, createNotification} = this.props;
    if (follow){
      deleteFollow(follow.id);
    } else {
      createFollow({leader_id: user.id, follower_id: currentUser.id});
      createNotification({initiator_id: currentUser.id, user_id: user.id});
    }
  }

A notification is also created so the new followee will receive a notification letting them know that they received a new follower.

Things to Note

In the near future, I plan on coming back to this project and adding new features. These include: