Skip to content

Commit

Permalink
Added Board component and select/list all boards functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jittania committed Jun 29, 2021
1 parent 832b4d3 commit 6855383
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
40 changes: 32 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import logo from './logo.svg';
import './App.css';

import {useEffect, useState} from 'react';
import axios from 'axios';


import Board from './components/Board';
import Card from './components/Card';
import NewBoardForm from './components/NewBoardForm';
Expand All @@ -14,24 +12,50 @@ import CardList from './components/CardList';

function App() {

// create a state for board -> set useSate to ([]), empty list == array of empty boards
// create state for board (default: empty array, meaning no boards created)
const [boardsData, setBoardsData] = useState([])
// create state for selected board
// create state for selected board (default: no board is selected)
const [selectedBoard, setSelectedBoard] = useState({
title: '',
owner: '',
board_id: null
});

// utilize useEffect for API call -> will call backend .env

// sends GET request to boards endpoint
// response contains data for all boards
useEffect(() => {
axios
.get(`${process.env.REACT_APP_BACKEND_URL}/boards`, {
})
.then((response) => {setBoardsData(response.data);
})
}, []);

//
const selectBoard = (board) => { setSelectedBoard(board) };

// mapping the response data from a successful GET request to
// a list of boards (boardsElements)
const boardsElements = boardsData.map((board) => {
return (<li>
<Board board={board} onBoardSelect={selectBoard}></Board>
</li>)
});

// Board component will display a blue border if rendered correctly
return (
<div>
<h1>Inspiration Board</h1>
<h2>Boards</h2>
<h2>Selected Boards</h2>
<section>
<h2>Boards</h2>
<ol className="boards__list">
{boardsElements}
</ol>
</section>
<section>
<h2>Selected Board</h2>
<p>{selectedBoard.board_id ? `${selectedBoard.title} - ${selectedBoard.owner}` : 'First select a board from list'}</p>
</section>
<h2>Create a New Board</h2>
<h2>Create a New Card</h2>
<h2>Selected Card</h2>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Board.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* for testing only: */
.board {
border: dashed 2px blue;
}
13 changes: 7 additions & 6 deletions src/components/Board.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import './Board.css';
import PropTypes from 'prop-types';


const Board = (props) => {
return (
<section>
{/* props we need: board & onBoardSelect
onClick too*/}
</section>
<div className="board"
onClick={() => props.onBoardSelect(props.board)}
>
{props.board.title}
</div>
);
}
};

export default Board;

0 comments on commit 6855383

Please sign in to comment.