CSCI 344: Fall 2024

Advanced Web Technology

CSCI 344: Fall 2024

UNCA Logo

Assignments > HW3: Building a "Vanilla" JavaScript Client

Due on Mon, 11/11 @ 11:59PM. 50 Points.

Video Walkthroughs

The folder of videos can be found here. I’ve also linked them individually:

  1. from 11/1 lecture Set Up
  2. from 11/1 lecture Retrieving Posts
  3. from 11/1 lecture Rendering the Post (Part 1)
  4. New Rendering the Post (Part 2)
  5. New Rendering the Post (Part 3): Comments
  6. New Rendering the Post (Part 4): Buttons
  7. New Creating Bookmarks
  8. New Deleting Bookmarks

Collaboration and Code Sharing Policy: Read Carefully

For this homework, you are welcome to work in pairs (optional). Even if you collaborate with someone else, you must still submit your own HTML and CSS files on Moodle. If you collaborate, you’ll just list your partner in the comments section of Moodle.

For those of you who are collaborating, please do not (a) “free ride” on your teammates or (b) enable free riders. Everyone in your group should understand every line of code they submit.

1. Introduction

1.1. Overview

In this assignment, you will build a “data-driven” version of the interface you built in HW2 using JavaScript. Specifically, you will:

  1. Build a very simple HTML “skeleton,” and then write some “client-side” JavaScript to:
    • Query data from a server (using a REST API) and
    • Build DOM elements based on the data returned from the server.
  2. Ensure that your interface is accessible.

For this assignment, everything should be done by writing your own “vanilla” JavaScript. In HW4, we will rebuild this client using React so that you can get a sense of some of the pros and cons of using a JavaScript framework.

Working Demo

If you want to see a working demo of what Photo App will look like at the end of the course, take a look here:

https://photo-app-secured.herokuapp.com/

  • username: your first name (all lowercase)
  • password: password

Note that we will only be implementing a subset of these features for HW3.

1.2. Set Up

HW03 Starter Files

  1. Download the starter files, unzip them, and save them in your csci344/homework directory. Your hw03 structure should look like this:
     hw03
     ├── README.md
     ├── index.html
     ├── js
     │   ├── main.js
     │   └── utilities.js
     ├── package.json
     ├── public
     │   └── output.css
     ├── src
     │   └── input.css
     └── tailwind.config.js
    
  2. Open your entire csci344 folder in VS Code.
  3. On your terminal and navigate to your csci/homework/hw03 folder. Then run the following command:
      npm install
    

    This command will install your Tailwind dependencies and create a package-lock.json file and a node_modules directory. Please verify that this is the case.

  4. Run the following command from the terminal (from within your hw03 directory so that Tailwind continuously compiles your Tailwind stylesheet based on the changes you make in the HTML and CSS files:
      npm run build:tailwind
    
  5. You are now ready to begin your HW03. Please view your index.html file in live server to verify that it works.

1.3. Course REST API

For this assignment, you will be using Sarah’s version of the PhotoApp REST API, located here: https://photo-app-secured.herokuapp.com/. In Homework 5, you will actually be building this REST API, but for now, I’m giving you a working version that you can interact with as you build your Photo App browser client. Credentials:

Obviously this is not secure, but this is just a practice API so if it gets hacked, I can just rebuild it in one click :).

After logging in, you can view all of your available REST API endpoints by navigating to the API Docs: https://photo-app-secured.herokuapp.com/api. You’re welcome to click as many buttons as you want. I will periodically clear out and rebuild the data so you can’t mess anything up.

1.4. Authentication Notes

3. Your Tasks

Please complete the tasks listed below. You’re more than welcome to add more CSS & JS files as needed (though this is not necessary).

1. Page Initialization Tasks (20 Points)

The functionality in this section must be invoked when the page first loads (so that the user sees each of these panels right away).

Points Task Description Figure
2pt Right Panel: User Profile Inside of the right panel at the top, render an HTML representation of the current user's profile using data from the /api/profile endpoint. Figure 1
4pts Right Panel: Suggested Accounts Inside of the right panel (underneath the user profile), render an HTML representation of suggested user accounts using data from the /api/suggestions endpoint. Figure 2
4pts Stories Panel Render an HTML representation of stories from the user's network using data from the /api/stories endpoint. Figure 3
10pts Posts Panel Underneath the stories panel, render an HTML representation of the first 10 posts from the user's network using data from the /api/posts endpoint. Please ensure that the following rules are honored:
  • If there is more than one comment associated with the post, display a “view all n comments” button (replace n by the actual number of comments) and only show the most recent comment. Otherwise, display a single comment below the title of the post (if one exists).
  • If the current user has already liked the post, the heart icon should be red . Otherwise it should be hollow . You can check if the current user has liked the post by checking the post'scurrent_user_like_id data field. If the post has been liked by the current user, then this data field exists. Otherwise, the field is undefined.
  • If the current user has already bookmarked the post, the bookmark icon should be black . Otherwise it should be hollow . You can check if the current user has bookmarked the post by checking the post'scurrent_user_bookmark_id data field. If the post has been bookmarked by the current user, then this data field exists. Otherwise, then the field is undefined.
Figure 4

Note that the content from each box should be generated from the API data (no hard-coding).

Figure 1: User Profile
screen shot of the stories panel
Figure 2: Suggestions
screen shot of the stories panel
Figure 3: Stories
screen shot of the stories panel
Figure 4: Post
screen shot of the post panel

2. Create / Delete Data with Event Handlers (20 Points)

After implementing the read-only functionality, you will implement functionality that actually updates the data in your system as follows:

Points Task Description
5pts Like Post
  • When the user clicks the heart of "unliked" post, a POST request is issued to the /api/likes/ endpoint.
  • Verify that your code works by refreshing the screen and checking to see that the number of likes is updated.
5pts Unlike Post
  • When the user clicks the heart of "liked" post, a DELETE request is issued to the /api/likes/<id> endpoint.
  • Verify that your code works by refreshing the screen and checking to see that the number of likes is updated.
5pts Bookmark Post
  • When the user clicks the bookmark button of "unbookmarked" post, a POST request is issued to the /api/bookmarks/ endpoint.
  • Verify that your code works by refreshing the screen and checking to see that the post has been bookmarked.
5pts Unbookmark Post
  • When the user clicks the bookmark button of an "unbookmarked" post, a DELETE request is issued to the /api/bookmarks/<id> endpoint.
  • Verify that your code works by refreshing the screen and checking to see that the post has been unbookmarked.

3. Accessibility Features (6 points)

Accessibility can be tricky when you’re relying on the fetch API, because a screen reader doesn’t always know that content has changed on the page. In addition, you don’t want to be over-reliant on the mouse. Please take a look at the Accessibility Resources, and specifically the resources pertaining to aria roles and attributes.

Points Task Description
2pts Keyboard Navigation
  • Ensure that all of the buttons are tabbable
  • Ensure that all the event handlers can be triggered using the "spacebar" or "enter / return" keys.
  • Hint: if you use the HTML <button></button> element for all of your buttons, you get this functionality for free.
2pts Alt Text and Contrast
  • Ensure that all images have alt text
  • Ensure that HTML language attribute has been set and that all colors have sufficient contrast.
2pts Aria attributes Use the 'aria-label' attribute to indicate to the screen reader the purpose of the "like" and "bookmark" buttons (and any other button).

4. Commit Everything to GitHub (2 points)

Please create a link from your homepage to your completed homework 2 webpage (see Sarah’s homepage for an example). Then, commit and push all of your edits to GitHub and, paste a link to your GitHub Repository and to your GitHub pages in the Moodle submission.

4. What to Turn In

Rubric

Please review the requirements above and ensure you have met them. Specifically:

Points Category
20pts Page initialization
20pts Create / delete data features 
6pts Accessibility features 
2pts Successfully Deployed to GitHub + GitHub Pages and linked to your homepage
2pts Composition and CSS (the UI looks like the screenshots provided). Everything still has to look good and be responsive. 

Moodle Submission

When you’re done, please submit the following to the Moodle:

Extra Credit

If Helene hadn’t happened, these tasks would be required. Instead, I am making them extra credit. Give them a try if you have the bandwidth! The more you practice, the more you will retain!

Points Task Description
5pts Follow Account
  • When the user clicks the follow button of an "unfollowed" account, a POST request is issued to the /api/following endpoint.
  • If the POST response indicates success, redraw the button to indicate that you are now following the account.
Extra Credit #1
5pts Unfollow Account
  • When the user clicks the unfollow button of an "followed" account, a DELETE request is issued to the /api/following/<id> endpoint.
  • If the DELETE response indicates success, redraw the button to indicate that you are no longer following the account.
Extra Credit #1
8pts Add a Comment
  • When the user types a comment into the textbox and clicks the adjacent "post" button, a POST request is issued to the /api/comments endpoint.
  • If the POST response indicates success, requery for the relevant post (/api/posts/<id>) and redraw the post.
  • Ensure that the new comment is rendered to the screen and that the comment count increases to reflect the # of comments associated with the post.
Extra Credit #2
10pts Redraw the Post without refreshing the page If you can figure out how to redraw the post without refreshing the page, as seen on https://photo-app-secured.herokuapp.com/ Extra Credit #2
Extra Credit #1: Following and Unfollowing

Note that each button click is issuing a request to your API and redrawing the screen (console messages just used for demonstration purposes).

screen shot of the post panel
Extra Credit #2: Add Comment

Note that each button click is issuing a request to your API and redrawing the screen (console messages just used for demonstration purposes).

screen shot of the post panel