Skip to content

Commit 45b0bf6

Browse files
adds base code.
1 parent d911cc1 commit 45b0bf6

File tree

8 files changed

+668
-166
lines changed

8 files changed

+668
-166
lines changed

README.md

Lines changed: 38 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,46 @@
1-
# Advanced Web Applications Sprint Challenge
1+
# Composing Stateful Logic - Dark Mode
22

3-
**Read these instructions carefully. Understand exactly what is expected _before_ starting this Sprint Challenge.**
3+
This project allows you to practice the concepts and techniques learned in this module and apply them in a concrete project. This module explored Form management in React. You learned what stateful logic is, how to build custom hooks, and how to compose multiple hooks together. In your project you will demonstrate proficiency of these subjects and principles by creating an application using each of these.
44

5-
This challenge allows you to practice the concepts and techniques learned over the past sprint and apply them in a concrete project. This sprint explored **advanced web applications**. During this sprint, you studied **React testing, client-side auth, HTTP methods, and Vercel**.
65

7-
In your challenge this week, you will demonstrate your mastery of these skills by creating **a login page** and **basic CRUD application.**
8-
9-
This is an individual assessment. All work must be your own. All projects will be submitted to codegrade for automated review. You will also be given feedback by code reviewers the Monday (Wednesday for PT) after challenge submissions. For more information on the review process [click here.](https://www.notion.so/lambdaschool/How-to-View-Feedback-in-CodeGrade-c5147cee220c4044a25de28bcb6bb54a)
10-
11-
You are not allowed to collaborate during the sprint challenge. However, you are encouraged to follow the twenty-minute rule and seek support by dropping a :wave: in your help channel when needed.
6+
## Objectives
7+
- Build custom hooks that extend stateful logic
8+
- Build custom hooks that work with persistent data
9+
- Compose hooks together
1210

1311
## Introduction
12+
In this project you'll take this crypto currency tracker app and build two custom hooks that, when composed together, will allow users to set and persist a dark mode preference.
1413

15-
In this project you will create a login page and request a token from the server that you'll use to send all other requests to the server. You will then be able to fetch the article data array, update data, and delete data, and watch the fun happen!
14+
***Make sure to complete your tasks one at a time and complete test each task before proceding forward.***
1615

1716
## Instructions
18-
19-
### Task 1: Project Setup
20-
21-
* [ ] Fork and clone this repository.
22-
* [ ] Implement the project with the `<firstName-lastName>` branch, committing changes regularly.
23-
* [ ] Push commits: git push origin `<firstName-lastName>`.
24-
* [ ] **RUN** `npm install` to install your dependencies.
25-
* [ ] **RUN** `npm start` to start your application backend and frontend.
26-
* [ ] **RUN** `npm test` to start your application's test runner.
27-
28-
### Task 2: CodeGrade Setup
29-
30-
* [ ] Open the assignment in Canvas and click on the "Set up git" option.
31-
* [ ] Follow instructions to set up Codegrade's Webhook and Deploy Key, making sure your deployment is set to your `<firstName-lastName>`. **Make sure to add in `?branch=<firstname-lastname>` at the end of your webhook payload URL.**
32-
* [ ] Push your first commit: `git commit --allow-empty -m "first commit" && git push`
33-
* [ ] Check to see that Codegrade has accepted your git submission.
34-
35-
### Task 3: Project Requirements
36-
37-
Your finished project must include all of the following requirements.
38-
39-
**See reference materials at the bottom of the this document for API Reference Details.**
40-
41-
#### Login Authentication
42-
> *Build a login form to authenticate your users along with all the components and utilities needed to support authentication.*
43-
44-
* [ ] In `Login.js`, build all UI and state functionality needed to capture a username and password. On a successful login, redirect user to the `View.js` component.
45-
* [ ] **Make sure that the input for your username and password includes the id="username" and id="password" attributes. Codegrade autotests will fail without them.**
46-
* [ ] **Make sure that the submit button to your login form includes the id="submit" attribute.**
47-
* [ ] In `Login.js`, add a p tag that will hold an error state if occurs. Add in all state functionality needed to support error display.
48-
* [ ] **Make sure your error p tag has an id="error" attribute attached. Codegrade autotests will fail without them.**
49-
* [ ] Construct an http request that retrieves an auth token from the server when the username `Lambda` and the password `School` is passed into the request. Complete successful login auth flow and redirect to `View.js.`
50-
* [ ] Display an appropriate error message when login is not successful.
51-
52-
#### Route Authentication
53-
> *Build the needed utilities to restrict access to private routes.*
54-
* [ ] Build a `PrivateRoute` component within the components folder.
55-
* [ ] Use the `PrivateRoute` component to build a route rendering `View.js` to the path `/view`.
56-
* [ ] Use the `PrivateRoute` component to build a route rendering `Logout.js` to the path `/logout`.
57-
58-
#### Request Authentication
59-
> *Complete the requests needed to execute all CRUD functions.*
60-
* [ ] Build a `axiosWithAuth` module within the utils folder to create an instance of axios with the authentication header.
61-
* [ ] Complete the `services/articleService.js` module. It should make an authenticated call to retrieve and return all articles from the server.
62-
63-
* [ ] In `View.js`, when the component mounts, use `articleService` to make an http request and add all articles to state.
64-
65-
* [ ] In `View.js`, complete `handleDelete` so that a http request is made that deletes the article with the included id. After successfully deleting the article on the api, update local state to reflect these changes.
66-
67-
* [ ] In `EditForm.js`, make a http request to get the article with the id `editId`. Save the result in state.
68-
69-
* [ ] In `View.js`, complete `handleEdit` so that a http request is made that updates the passed in article. Set the editing state to false when the request is complete. After successfully deleting the article on the api, update local state to reflect these changes.
70-
71-
72-
#### Logout Authentication
73-
> *Add in the http requests needed to logout of the application.*
74-
75-
* [ ] In `Logout.js`, execute a http request to logout on mount. When the request is complete, the user's security token should be removed and the browser should redirect to the login page.
76-
77-
#### Advanced Testing
78-
> *Add the following tests within Article.test.js.*
79-
* [ ] Build a test that shows the `Article` component, given the correct props, can render without errors.
80-
* [ ] Build a test that shows that when a correctly formatted article is passed into the `Article` component, the correct headline, author, summary and body are displayed.
81-
* [ ] The `Article` component should display "Associated Press" when an author attribute is not avalible. Build a test that verifies that that is true.
82-
* [ ] Build a test that show that when the deleteButton is pressed on an Article, the handleDelete functional property is executed.
83-
84-
> *Add the following tests within View.test.js.*
85-
* [ ] Build a test that shows the `View` component can render zero articles without errors. Make sure the mock service called made when View mounts.
86-
* [ ] Build a test that shows the `View` component can render three articles without errors. Make sure the mock service called made when View mounts.
87-
88-
**Notes:**
89-
* You are welcome to create additional files but **do not move or rename existing files** or folders.
90-
* Do not change your `package.json` file except to install additional libraries.
91-
* In your solution, it is essential that you follow best practices and produce clean and professional results.
92-
* Schedule time to review, refine, and assess your work and perform basic professional polishing including spell-checking and grammar-checking on your work.
93-
* It is better to submit a challenge that meets MVP than one that attempts too much and does not.
94-
95-
### Reference Materials
96-
97-
#### API Documentation
98-
* **[POST]** * to `http://localhost:5000/api/login`: returns a the current authenication information of the user. Pass in the following credentials as the `body` of the request: `{ username: 'Lambda', password: 'School' }` for a successful login.
99-
100-
* **[POST]** * to `http://localhost:5000/api/logout`: returns the expired authentication information of the user.
101-
102-
* **[GET]** to `http://localhost:5000/api/articles`: returns the all posts currently available. **This endpoint can only be accessed by an authenticated user.**
103-
104-
* **[POST]** to `http://localhost:5000/api/articles`: creates a article object. Returns all available articles. Pass the article as the `body` of the request. **This endpoint can only be accessed by an authenticated user.**
105-
106-
* **[PUT]** to `http://localhost:5000/api/articles/:id`: updates the article using the `id` passed as part of the URL. Returns all available articles. Send the updated article object as the `body` of the request. **This endpoint can only be accessed by an authenticated user.**
107-
108-
* **[DELETE]** to `http://localhost:5000/api/articles/:id`: removes the article with the `id` referenced. Returns all available articles. **This endpoint can only be accessed by an authenticated user.**
109-
110-
#### Article Data Structure
111-
```
112-
{
113-
id: 'aMqwd', //unique article id
114-
headline: "headline", //title of article
115-
createdOn: '2021-08-09T18:02:38-04:00
116-
', //timestamp of when article was added
117-
summary: "summary", //short summary statement of article
118-
body: "" //paragraph of article text
119-
}
120-
```
121-
122-
## Submission format
123-
* [ ] Submit via Codegrade by commiting and pushing any new changes.
124-
* [ ] Check codegrade for automated feedback.
125-
* [ ] Check codegrade on Monday following the Sprint Challenge for reviewer feedback. For more information on how to access and read your feedback, check [here](https://www.notion.so/lambdaschool/How-to-View-Feedback-in-CodeGrade-c5147cee220c4044a25de28bcb6bb54a)
126-
* [ ] Any changes pushed to your <firstName-lastName> branch will resubmited to codegrade if pushed before the sprint challenge deadline. Changes after the deadline will not be reviewed.
127-
128-
## Interview Questions
129-
130-
Be prepared to demonstrate your understanding of this week's concepts by answering questions on the following topics. Add your answers to the questions within `interview_answers.md` file. These will not be counted as a part of your sprint score but will be helpful for preparing you for your endorsement interview, and enhancing overall understanding.
131-
132-
1. Explain what a token is used for.
133-
2. What steps can you take in your web apps to keep your data secure?
134-
3. Describe how web servers work.
135-
4. Which HTTP methods can be mapped to the CRUD acronym that we use when interfacing with APIs/Servers.
17+
### Task 1: Project Set Up
18+
* [ ] Create a forked copy of this project.
19+
* [ ] Clone your OWN version of the repository in your terminal
20+
* [ ] cd into the project base directory `cd web-module-project-custom-hook`
21+
* [ ] Download project dependencies by running `npm install`
22+
* [ ] Start up the app using `npm start`
23+
24+
### Task 2: Project Requirements
25+
#### Build a useDarkMode hook
26+
* [ ] Create a new folder called `hooks.`
27+
* [ ] Create a file called `useDarkMode.js`.
28+
* [ ] Build a hook that ONLY setups a boolean state value. This value governs if dark mode is on or off.
29+
* [ ] Return the slice of state created and the state modification function.
30+
* [ ] Replace the darkMode state definition with useDarkMode in index.js.
31+
32+
#### Build a useLocalStorage hook
33+
* [ ] Create a file called `useLocalStorage.js`.
34+
* [ ] Build a hook called that takes in a key value and an initialValue.
35+
* [ ] Use the code from GP to build the the hook.
36+
37+
#### Compose useLocalStorage around useDarkMode
38+
* [ ] Import useLocalStorage into the useDarkMode hook.
39+
* [ ] Confirm that when clicking the dark mode switch on the ui that the correct value is saved to localStorage.
40+
* [ ] Confirm that dark mode persists when reloading the app.
41+
42+
## Submission Format
43+
44+
- [ ] Only work on main.
45+
- [ ] Make sure to push your code at regular intervals.
46+
- [ ] Copy your github repo url and paste it into Canvas to submit your project

0 commit comments

Comments
 (0)