bhargavi-potu / P5

PROJECT 5
0 stars 0 forks source link

Project 5: Single Page Applications [^1]

Scrum Team

Product Owner

Scrum Master

Developers

Setup

You should already have installed Node.js and the npm package manager on your system. If not, follow the installation instructions in Project 0 now.

Create a directory project5 and extract the contents of this repository into the directory. These files are the starter files for this assignment.

This assignment requires many node modules that contain the tools (e.g. Webpack, Babel, ESLint) needed to build a ReactJS web application as well as a simple Node.js web server (ExpressJS) to serve it to your browser. It also fetches Material-UI which contain the React components and style sheets we will be using. These modules can be fetched by running the following command in the project5 directory:

npm install

ReactJS and Material-UI are fetched into the node_modules subdirectory even though we will be loading it into the browser rather than Node.js.

Like the previous assignment, we can use npm to run the various tools we had it fetch. The following npm scripts are available in the package.json file:

Your solutions for all of the problems below should be implemented in the project5 directory. As was done with on the previous project you will need to run a web server we provide for you by running a command in your project5 directory:

node webServer.js

As in the last project, you can use the command:

node webServer.js & npm run build:w

to run the web server and webpack within a single command line window.

Problem 1: Create the Photo Sharing Application

As starter code for your PhotoApp we provide you a skeleton (photo-share.html which loads photoShare.jsx) that can be started using the URL "http://localhost:3000/photo-share.html". The skeleton:

For this problem, we will continue to use our magic models hack to provide the model data so we display a pre-entered set of information. As before, the models can be accessed using window.models. The schema of the model data is defined below.

Your assignment is to extend the skeleton into a working web app operating on the fake model data. Since the skeleton is already wired to either display components UserList, UserDetail, and UserPhotos with the appropriate parameters passed by React Router, most of the work will be implementing the stubbed out components. They should be filled in so that:

Besides these components, you need to update the TopBar component in components/topBar as follows:

The use of ReactRouter in the skeleton we provide allows for deep-linking to the different views of the application. Make sure the components you build do not break this capability. It should be possible to do a browser refresh on any view and have it come back as before. Our standard approach to building components handles deep-linking automatically. Care must be taken when doing things like sharing objects between components. A quick browser refresh test on each view will show when you broke something.

Although you don't need to spend a lot of time on the appearance of the app, it should be neat and understandable. The information layout should be clean (e.g., it should be clear which photo each comment applies to).

Photo App Model Data

For this problem we keep the magic DOM loaded model data we used in the previous project. The model consists of four types of objects: user, photo, comment, and SchemaInfo types.

Problem 2: Fetch model data from the web server

After doing Problem 1, our photo sharing app front-end is looking like a real web application. The big barrier to be considered real is the fakery we are doing with the model data loaded as JavaScript into the DOM. In this Problem we remove this hack and have the app fetch models from the web server as would typically be done in a real application.

The webServer.js given out with this project reads in the Models we were loading into the DOM in Problem 1 and makes them available using ExpressJS routes. The API exported by webServer.js uses HTTP GET requests to particular URLs to return the Models models. The HTTP response to these GET requests is encoded in JSON. The API is:

You can see the APIs in action by pointing your browser at above URLs. For example, the links "http://localhost:3000/test/info" and "http://localhost:3000/user/list" wiil return the JSON-encoded model data in the browser's window.

To convert your app to fetch models from the web server you should implement a FetchModel function in lib/fetchModelData.js. The function should be declared as follows:

/*
 * FetchModel - Fetch a model from the web server.
 *   url - string - The URL to issue the GET request.
 * Returns: a Promise that should be filled
 * with the response of the GET request parsed
 * as a JSON object and returned in the property
 * named "data" of an object.
 * If the requests has an error the promise should be
 * rejected with an object contain the properties:
 *    status:  The HTTP response status
 *    statusText:  The statusText from the xhr request
 */

Although there are many modules that would make implementing this function trivial, we want you to learn about the low-level details of AJAX. You may not use other libraries to implement FetchModel; you must write Javascript code that creates XMLHttpRequest DOM objects and responds to their events.

Your solution needs to be able to handle multiple outstanding FetchModel requests. To demonstrate your FetchModel routine works, your web application should work so that visiting http://localhost:3000/photo-share.html displays the version number returned by sending an AJAX request to the http://localhost:3000/test/info URL. The version number should be displayed in the TopBar component of your app.

After successfully implementing the FetchModel function in lib/fetchModelData.js, you should modify the code in

to use the FetchModel function to request the data from the server. There should be no accesses to window.models in your code and your app should work without the line in photo-share.html:

<script src="https://github.com/bhargavi-potu/P5/raw/main/modelData/photoApp.js"><script>

Style

These requirements will be met if your problem solutions have proper MVC decomposition. In addition, your code and components must be clean and readable, and your app must be at least "reasonably nice" in appearance and convenience.

Note that we are using Material-UI, React components that implement Google's Material Design. We have used Material-UI's Grid component to layout the Master-Detail pattern as described in class, and a App Bar header for you. Although you don't need to build a fully Material Design compatible app, you should use Material-UI components when possible.

In addition, remember to run ESLint before submitting. ESLint should raise no errors.

Extra Credit

The userPhotos component specifies that the display should include all of a user's photos along the photos' comments. This approach doesn't work well for users with a large numbers of photos. For extra credit you can implement a photo viewer that only shows one photo at a time (along with the photo's comments) and provides a mechanism to step forward or backward through the user's photos (i.e. a stepper).

In order to get extra credit on this assignment your solution must:

Warning: Doing this extra credit involves touching various pieces used in the non-extra credit part of the assignment. Adding new functionality guarded by a feature flag is common practice in web applications but has a risk in that if you break the non-extra credit part of the assignment you can fulfill less requirements overall. Take care.

Deliverables

Use the standard submission mechanism mechanism to submit.

Your respository should include the following updated files.

[^1]: Stanford Computer Science