Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sea Turtles - Nina G. #42

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,26 @@ yarn-error.log*
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
71 changes: 68 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,70 @@
# Inspiration Board: Front-end Layer
# Getting Started with Create React App

This scaffold only includes a `.gitignore` file.
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

To get started, follow the setup directions described in the project.
## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
5 changes: 5 additions & 0 deletions README.old.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Inspiration Board: Front-end Layer

This scaffold only includes a `.gitignore` file.

To get started, follow the setup directions described in the project.
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "front-end-inspiration-board",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
11 changes: 11 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Inspiration Board</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
154 changes: 154 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import React from 'react';
import { useState, useEffect } from 'react';
import axios from 'axios';
import BoardList from './components/BoardList'
import CardList from './components/CardList';
import NewCardForm from './components/NewCardForm';
import NewBoardForm from './components/NewBoardForm';

const backEndUrl = process.env.REACT_APP_BACKEND_URL;

function App() {

const [boards, setBoards] = useState([]);
const [selectedBoard, setSelectedBoard] = useState("");
const [cards, setCards] = useState([]);
const [showAddBoard, setShowAddBoard] = useState(false);
const [showAddCard, setShowAddCard] = useState(false);

useEffect(() => {
getBoards();
}, []);

const addBoard = (newBoardData) => {
axios.post(`${backEndUrl}/boards`, newBoardData)
.then((res) => {
const newBoard = {
board_id: res.data.board.board_id,
title: res.data.board.title,
owner: res.data.board.owner
};
setSelectedBoard()
setBoards((otherBoards) => {
return [...otherBoards, newBoard];
});
})
.catch((err) => {
console.log(err)
});
};

const getBoards = () => {
axios.get(`${backEndUrl}/boards`)
.then(res => {
setBoards(res.data)
}).catch((err) => {
console.log(err)
});
};

const selectBoard = (id, title, owner) => {
const chosenBoard = { id: id, title: title, owner: owner };
setSelectedBoard(chosenBoard);

axios.get(`${backEndUrl}/boards/${id}/cards`)
.then(res => {
setCards(res.data.cards)
}).catch((err) => {
console.log(err)
});
};

const addCard = (newCardData) => {
axios.post(`${backEndUrl}/boards/${selectedBoard.id}/cards`, newCardData)
.then((res) => {
const newCard = {
id: res.data.cards.id,
message: res.data.cards.message,
likes_count: res.data.cards.likes_count,
board_id: res.data.cards.board_id
};
setCards((otherCards) => {
return [...otherCards, newCard];
});
}).catch((err) => {
console.log(err)
});
};

const deleteCard = (cardId) => {
axios.delete(`${backEndUrl}/cards/${cardId}`)
.then(() => {
setCards(cards.filter((card) => card.id !== cardId));
}).catch((err) => {
console.log(err)
});
};

const likeCard = (cardId) => {
axios.patch(`${backEndUrl}/cards/${cardId}/like`)
.then((res) => {
for (const card of [...cards]) {
if (card.id === cardId) {
card.likes_count ++
};
};
setCards([...cards]);
}).catch((err) => {
console.log(err)
});
};

const sortCards = (category) => {
if (category === "id") {
setCards([...cards.sort(function(a,b){return a.id - b.id})]);
} else if (category === "abc") {
setCards([...cards.sort(function(a,b){return a.message > b.message ? 1: -1})]);
} else if (category === "likes") {
setCards([...cards.sort(function(a,b){return b.likes_count - a.likes_count})]);
};
};

return (
<div>
<main>
<section>
<h1>Welcome to the Inspiration Board!</h1>
<p>Have a look around. Anything that brain of yours can think of can be added.
You can create boards to collect your favorite quotes, to send positive notes,
to share jokes, or whatever you want. This site is your oyster <span className="italics">
(as long as the message is 40 characters or less)</span>.</p>
</section>
<section>
<BoardList boards={boards} onAddBoard={() =>
setShowAddBoard(!showAddBoard)} showAdd={showAddBoard} onToggle={selectBoard}></BoardList>
{ showAddBoard && <NewBoardForm onAdd={addBoard}></NewBoardForm> }

{ selectedBoard ? (<h3>Chosen topic: <span className="white">{selectedBoard.title}</span></h3>): "" }
{ selectedBoard ? (
<section>
<label>Sort notes by: </label>
<select onChange={ ((e) => sortCards(e.target.value)) }>
<option value="id">id</option>
<option value="abc">alphabetically</option>
<option value="likes">likes</option>
</select>
</section>
): "" }
{ selectedBoard ? (<CardList cards={cards} onDeleteCard={deleteCard} onLikeCard={likeCard}
onAddCard={() => setShowAddCard(!showAddCard)} showAdd={showAddCard}></CardList>): "" }

{ showAddCard && <NewCardForm onAdd={addCard}></NewCardForm> }
</section>
</main>
<footer>
<p>© Anacapamu 2022</p>
<li className="italics">credit to <a href="https://www.youtube.com/watch?v=k1BneeJTDcU">Bo Burnham</a> for
inspiration of website verbiage</li>
<li className="italics">credit to <a href="https://unsplash.com/photos/Ow-joAY8NyY">Alfred Aloushy</a> for background
image</li></footer>
</div>
);
};

export default App;
20 changes: 20 additions & 0 deletions src/components/Board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import PropTypes from 'prop-types';

const Board = (props) => {
return (
<li className="board"
onDoubleClick={() => props.onToggle(props.boardId, props.title, props.owner)}>
<span className="white">{props.title}</span> by <span className="white">{props.owner}</span></li>
);
};

Board.propTypes = {
boardId: PropTypes.number.isRequired,
title: PropTypes.string.isRequired,
owner: PropTypes.string.isRequired,
onToggle: PropTypes.func,
selected: PropTypes.bool
};

export default Board;
36 changes: 36 additions & 0 deletions src/components/BoardList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import PropTypes from 'prop-types';
import Board from './Board';
import Button from './Button';

const BoardList = (props) => {
const boardComponents = props.boards.map((board) => {
return (
<Board
key = {board.id}
boardId = {board.id}
title = {board.title}
owner = {board.owner}
onToggle = {props.onToggle}
selected = {props.selected}>
</Board>
);
});
return (
<section>
<h2>Mountains of Topics</h2>
{boardComponents}
<Button text={props.showAdd ? "hide add topic form": "add a topic"} color={props.showAdd ? "#a3905c": "#b9af63"}
onClick={props.onAddBoard}></Button></section>
);
};

BoardList.propTypes = {
boards: PropTypes.arrayOf(PropTypes.object).isRequired,
showAdd: PropTypes.bool,
onAddBoard: PropTypes.func,
onToggle: PropTypes.func,
selected: PropTypes.bool
};

export default BoardList;
17 changes: 17 additions & 0 deletions src/components/Button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';

const Button = (props) => {
return (
<button style={{ backgroundColor: props.color }} className="btn" onClick={props.onClick}>
{props.text}</button>
);
};

Button.propTypes = {
text: PropTypes.string.isRequired,
color: PropTypes.string,
onClick: PropTypes.func
};

export default Button;
Loading