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

Panthers - Group 4: Betts, Mejia, Tamang, Xu #27

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
918c9cb
project setup
n1colemejia Jan 3, 2023
142933d
set up components
atamang90 Jan 4, 2023
4cdbc75
added props and proptypes to all components
n1colemejia Jan 4, 2023
9a4d59b
added new board form
n1colemejia Jan 5, 2023
3c51e7d
added message after new board form submission
n1colemejia Jan 6, 2023
e4b8d22
added custom error message
n1colemejia Jan 6, 2023
ac1ffee
added some stylin
n1colemejia Jan 6, 2023
e0eb417
added card form and styling
n1colemejia Jan 12, 2023
36cb97b
added request to display all boards, updated Board
n1colemejia Jan 16, 2023
103c3a4
added event handler to for selected board
n1colemejia Jan 17, 2023
17f24fe
added get all cards callback for current board
n1colemejia Jan 17, 2023
db113b5
added functions to display current board's cards
n1colemejia Jan 17, 2023
9fae832
Trying toggle form/separate hide button
atamang90 Jan 18, 2023
b63ca06
added toggle to hide/show new card form
n1colemejia Jan 18, 2023
85df9d2
fixed new card form post request
n1colemejia Jan 18, 2023
b5c086d
added after submit messages for each form
n1colemejia Jan 18, 2023
49ee667
board form
atamang90 Jan 19, 2023
f1343de
added styling to cards
n1colemejia Jan 19, 2023
6879fb2
refactored unused styles
n1colemejia Jan 19, 2023
a972c0d
added delete card event handler and api call
n1colemejia Jan 19, 2023
37c56bb
swapped out api requests to use deployed backend
n1colemejia Jan 19, 2023
677efcb
working like button but not rendering
atamang90 Jan 20, 2023
0220c09
fixed like count to appear for new cards
n1colemejia Jan 20, 2023
68a93cb
Merge branch 'main' of https://github.com/n1colemejia/front-end-inspi…
n1colemejia Jan 20, 2023
95982b0
finalized styling and refactoring
n1colemejia Jan 20, 2023
865da9b
cleaned up code and added delete board button
atamang90 Jan 22, 2023
bf02cd8
Co-authored-by: Farrah-Unger <[email protected]>
atamang90 Jan 22, 2023
13eefc1
Update README.md
n1colemejia Jun 21, 2023
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*
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Inspiration Board: Front-end Layer
## Inspo Board - Frontend

This scaffold only includes a `.gitignore` file.
Inspo Board is an digital bulletin board for inspirational content! Users can create new boards, select their board, view all the cards associated with the selected board, add new cards, and +1 cards that they like.

To get started, follow the setup directions described in the project.
- Link to Backend Repo: https://github.com/n1colemejia/back-end-inspiration-board

<img width="auto" alt="" src="https://github.com/n1colemejia/inspo-board/assets/100858764/0a89ba77-566c-460b-8161-29d848af5b18">
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.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"axios": "^1.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.0"
},
"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"
]
}
}
43 changes: 43 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<!-- <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> -->
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<!-- <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> -->
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
25 changes: 25 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
Empty file added src/App.css
Empty file.
235 changes: 235 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
import { useEffect, useState } from "react";
import axios from "axios";
import "./App.css";
import BoardContainer from "./components/BoardContainer";
import CardContainer from "./components/CardContainer";
import Header from "./components/Header";
import NewBoardForm from "./components/NewBoardForm";
import NewCardForm from "./components/NewCardForm";

// const url = "https://group-4-inspo-board.herokuapp.com"
const url = "http://localhost:5000"


// helper function for boards API request
const getAllBoardsApi = () => {
return axios
.get(`${url}/board`)
.then((response) => {
const newBoards = response.data.map((board) => {
return {
id: board.board_id,
title: board.title,
owner: board.owner,
};
});

return newBoards;
})
.catch((error) => {
console.log(error);
});
};

// helper function for cards API request
const getAllCardsApi = (id) => {
return axios
.get(`${url}/board/${id}/cards`)
.then((response) => {
return response.data;
})
.catch((error) => {
console.log(error);
});
};

// helper function for delete card API request
const deleteCardApi = (boardId, cardId) => {
return axios.delete(`${url}/board/${boardId}/cards/${cardId}`)
.then(response => {
console.log(response);
console.log(`Card ${cardId} from Board ${boardId} deleted`);
})
.catch(error => {
console.log(error);
})
};

// helper function for patch API request
const patchCardApi = (boardId, cardId) => {
return axios.patch(`${url}/board/${boardId}/cards/${cardId}`)
.then(response => {
console.log(response)
console.log(`Card ${cardId} from Board ${boardId} patched`);
return response.data;
})
.catch(error => {
console.log(error);
})};

function App() {
// state
const[isBoardFormVisible,setIsBoardFormVisible] = useState(true);
const [boards, setBoards] = useState([]);
const [cards, setCards] = useState([]);
const [boardFormMessage, setBoardFormMessage] = useState("");
const [cardFormMessage, setCardFormMessage] = useState("");
const [currentBoard, setCurrentBoard] = useState({title: "No board selected",});
const [boardSelected, setBoardSelected] = useState(false);

// toggle button
const toggleNewBoardForm = () =>{setIsBoardFormVisible(!isBoardFormVisible)}

// get all boards using API helper
const getAllBoards = () => {
return getAllBoardsApi().then((boards) => setBoards(boards));
};

// get all boards when App renders
useEffect(() => {
getAllBoards();
}, [currentBoard]);

//Delete board
const deleteBoard =()=>{

try {
const res = axios.delete(`${url}/board/${currentBoard.id}`)
console.log(res,"got the data back from api ")
setCurrentBoard({title: "No board selected",})


} catch (error) {
console.log(error)
}


}
// get all cards using API helper
const getAllCards = (id) => {
console.log(`currentBoard.id: ${currentBoard.id}`)
getAllCardsApi(id).then((cards) => {
const allCards = [];
for (let card of cards) {
allCards.push({
id: card.card_id,
message: card.message,
likeCount: card.likes_count,
});
}
setCards(allCards);
});
};

// display current board callback for selected Board
const displayCurrentBoard = (id) => {
for (let board of boards) {
if (id === board.id) {
console.log(board,"display current board")
setCurrentBoard(board);
getAllCards(id);
setBoardSelected(true);
setBoardFormMessage("");
setCardFormMessage("");
}
}
};

// add new board callback for new board form
const addBoard = (boardData) => {
if (!boardData.title || !boardData.owner) {
setBoardFormMessage("Please enter a title or owner.");
} else {
axios
.post(`${url}/board`, boardData)
.then((response) => {

const newBoards = [...boards];

newBoards.push({
title: response.data.title,
owner: response.data.owner,
...boardData,
});

setBoards(newBoards);
setBoardFormMessage("You made a new board!");
})
.catch((error) => {
console.log(error);
setBoardFormMessage("Input is invalid.");
});
}
};

// add new card callback for new card form
const addCard = (cardData) => {
console.log(`currentBoard.id: ${currentBoard.id}`)
axios
.post(`${url}/board/${currentBoard.id}/cards`, cardData)
.then((response) => {

const newCards = [...cards];

newCards.push({
message: response.data.message,
likeCount: response.data.likes_count,
...cardData,
});

setCards(newCards);
setCardFormMessage("You made a new card!");
})
.catch((error) => {
console.log(error);
// add conditional to display custom message for empty message or exceeded character limit
setCardFormMessage("Input invalid");
});
};

// delete card from board
const deleteCard = (cardId) => {
deleteCardApi(currentBoard.id, cardId)
.then(response => {
setCards(cards => cards.filter(card => {
return card.id !== cardId;
}))
})
};

// increase like count for card
// add function to increase likes on card
const incrementLikeCount = (id) => {
patchCardApi(currentBoard.id, id)
.then(newLikeCount =>{
setCards(cards => cards.map(card => {
if (card.id === id) {
return {
id: id,
message: card.message,
likeCount: newLikeCount,
...cards};
} else {
return card;
}
}));
});
}

return (
<div className="App">
<Header />
{isBoardFormVisible ? <NewBoardForm addBoardCallback={addBoard} afterSubmitMessage={boardFormMessage}></NewBoardForm>: ''}
<span onClick={toggleNewBoardForm} className='new-board-form__toggle-btn'>{isBoardFormVisible ? 'Hide New Board Form' : 'Show New Board Form'}</span>
{/* <NewBoardForm addBoardCallback={addBoard} afterSubmitMessage={boardFormMessage} toggleHide={toggleHide} isVisible={isVisible}/> */}
<BoardContainer
boards={boards}
onDisplayCurrentBoard={displayCurrentBoard}
/>
<NewCardForm addCardCallback={addCard} afterSubmitMessage={cardFormMessage} boardSelected={boardSelected}/>
<CardContainer deleteBoard={deleteBoard} currentBoard={currentBoard} cards={cards} onDeleteCard={deleteCard} incrementLikeCount={incrementLikeCount}/>
</div>
);
};

export default App;
Loading