Skip to content

Commit

Permalink
Merge pull request #15 from WCRI56-Team-GS/nathan/teampush
Browse files Browse the repository at this point in the history
Add column functionality
  • Loading branch information
gacetta authored Mar 7, 2023
2 parents 1ce461f + 9f1f1bc commit b219483
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 71 deletions.
7 changes: 4 additions & 3 deletions client/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const App = () => {
}

useEffect(() => {

},[loginError, isLoggedIn])
if (loginError === true) alert('Incorrect username or password. Please try again');
},[loginError])

return (
<>
Expand Down Expand Up @@ -50,7 +50,8 @@ const App = () => {
/>
)
)}
{loginError ? (<div>Incorrect username or password. Please try again</div>) : <></>}
{/* {loginError ? (<div>Incorrect username or password. Please try again</div>) : <></>} */}

</>
);
}
Expand Down
11 changes: 5 additions & 6 deletions client/components/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { ColumnModal, CardModal } from './Modals.jsx';
import Column from './Column.jsx'

function HomePage({user, isLoggedIn, setLogin}) {

// state to render a column creation modal
const [ showColumnModal, setShowColumnModal ] = useState(false)
// state to render a card creation modal
const [ showCardModal, setShowCardModal ] = useState(false)
// const [columnsState, setColumns] = useState(null);
const [ boardData, setBoardData ] = useState([]);
const [ currBoardID, setCurrBoardID] = useState('');

//render columns and cards within
// [
Expand Down Expand Up @@ -43,6 +43,7 @@ function HomePage({user, isLoggedIn, setLogin}) {
}).then((res) => res.json())
.then((data) => {
setBoardData(data);
setCurrBoardID(data[0]._id)
})
.catch((error) => {
console.log('Error fetching boardData in APP.jsx:', error)
Expand All @@ -59,11 +60,8 @@ function HomePage({user, isLoggedIn, setLogin}) {
}
let overlay = null;

useEffect(() => {
if (showColumnModal) overlay = <div className="overlay"></div>
else overlay = null;
}, [showColumnModal, showCardModal])
console.log('showColumnModal: ', showColumnModal)
if (showColumnModal || showCardModal) overlay = <div className="overlay"></div>
else overlay = null;

return (
<div className='homeCont'>
Expand All @@ -87,6 +85,7 @@ function HomePage({user, isLoggedIn, setLogin}) {
showCardModal={showCardModal}
setShowCardModal={setShowCardModal}
boardData={boardData}
currBoardID={currBoardID}
setBoardData={setBoardData} />)
: (<></>)
}
Expand Down
10 changes: 5 additions & 5 deletions client/components/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ function LoginPage ({user, setUser, password, setPassword, toggle, isLoggedIn, s
body: JSON.stringify(loginData)
}).then((res) => {
console.log(res.status)
// if (res.status === 404) {
// setLogin(false)
// setLoginError(true)
// } else {
if (res.status === 404) {
setLogin(false)
setLoginError(true)
} else {
setLogin(true);
setLoginError(false);
// }
}
console.log('logged in on LoginPage.jsx')
// console.log('users data', user)
}).catch((error) => {
Expand Down
95 changes: 66 additions & 29 deletions client/components/Modals.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { Component } from "react";
import { useState, useEffect } from "react";
import Column from './Column.jsx'

// Modal for the columns
const ColumnModal = ({ showColumnModal, setShowColumnModal, showCardModal, setShowCardModal, boardData, setBoardData}) => {

const ColumnModal = ({ showColumnModal, setShowColumnModal, showCardModal, setShowCardModal, boardData, setBoardData, currBoardID}) => {

/*
boardData {
Expand All @@ -20,18 +20,51 @@ const ColumnModal = ({ showColumnModal, setShowColumnModal, showCardModal, setSh
]
}
*/


const saveData = () => {
// get the value from the input field
const newColumnName = document.querySelector('.modal-column-input').value;

// store it somewhere (local?)
console.log('boardData: ', boardData);
console.log('boardColumnData: ', boardData[0].columns);
console.log('boardData from line 29: ', boardData);
console.log('typeof boardData[0]: ', typeof boardData[0]);
// our local state needs to reflect added column
// setBoardData(data => ({
const columnName = boardData[0]
console.log('line 33: ', columnName)
console.log('type of columnName: ', typeof columnName.columns)

const newBoardData = boardData.map(board => {
console.log('board: ', board)
console.log('currBoardID: ', currBoardID)
if (board._id === currBoardID) {
console.log('board and ID match')
board.columns.push({columnName: newColumnName, cards: [{cardText: 'Hello, I\'m a new column!'}]})
console.log('board: ', board)
}
return board;
})
console.log('newBoardData: ', newBoardData);
setBoardData(newBoardData)
console.log(boardData)


// [{board1}, {board2}, {board3}]
// grab our current board by currBoardID
// create a newArrayOfBoards without the currBoard (filter by currBoardID)
// update current board
// add to array of boards
// setBoardData(newArrayOfBoards)



// setBoardData([{}])
// boardData = array of BoardObjs
// filter currentBoard

// setBoardData((data) => ({
// ...data,
// columns: columns.columnName.push(newColumnName)
// columnName: newColumnName
// }))
// send a request to DB to udpate Board with new column
// toggle columnModal
Expand All @@ -48,17 +81,18 @@ const ColumnModal = ({ showColumnModal, setShowColumnModal, showCardModal, setSh

return (
<div className="modal-home">
{console.log('modal was opened')}
<div>
<form>
<input
className="modal-column-input"
type="text"
required
placeholder="column name"
// do we want an onChange here or wait until the input is finished
/>
</form>

<form className='modal-form'>
<h1>ADD COLUMN</h1>
<input
className="modal-column-input"
type="text"
required
placeholder="column name"
// do we want an onChange here or wait until the input is finished
/>
</form>
<div className='modal-button-cont'>
<button className="modal-text-button"
onClick={() => saveData()}>
SAVE
Expand All @@ -68,6 +102,7 @@ const ColumnModal = ({ showColumnModal, setShowColumnModal, showCardModal, setSh
DELETE
</button>
</div>

{showCardModal && <CardModal />}
</div>
)
Expand All @@ -91,9 +126,9 @@ const CardModal = ({ showCardModal,setShowCardModal }) => {

return (
<div className="modal-home">
<div>
<form>
<div>ADD CARD</div>

<form className='modal-form'>
<h1>ADD CARD</h1>
<input
className="card-modal-input"
type="text"
Expand All @@ -102,15 +137,17 @@ const CardModal = ({ showCardModal,setShowCardModal }) => {
// do we want an onChange here or wait until the input is finished
/>
</form>
<button className="modal-text-button"
onClick={() => addTask()}>
+
</button>
<button className="modal-text-button"
onClick={() => deleteTask()}>
X
</button>
</div>
<div className='modal-button-cont'>
<button className="modal-text-button"
onClick={() => addTask()}>
ADD CARD
</button>
<button className="modal-text-button"
onClick={() => deleteTask()}>
CANCEL
</button>
</div>

</div>
)
}
Expand Down
36 changes: 10 additions & 26 deletions client/styles/components/_columns.scss
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
.modal-home {


.columnCont {
display: flex;
flex-direction: column;
background-color: $color1;
color: $color3;
border-radius: 15px;
padding: 10px;
gap: 10px;
width: 175px;
}

.modal-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.modal-column-input {
width: 150px;
height: 20px;
border-radius: 5px;
margin-bottom: 20px;
background-color: $color2;
}


.modal-text-button {
.column-container {
display: flex;
flex-direction: row;
justify-content: space-around;
gap: 10px;
}

.columnCont {
.cardCont {
display: flex;
flex-direction: column;
background-color: $color1;
color: $color3;
border-radius: 15px;
padding: 10px;
gap: 10px;

}
43 changes: 43 additions & 0 deletions client/styles/components/_modals.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.modal-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 999;
}

.modal-home {
background-color: $color1;
color: $color3;
border-radius: 15px;
padding: 10px;
display: flex;
flex-direction: column;
gap: 10px;
}

.modal-column-input {
width: 150px;
height: 20px;
border-radius: 5px;
margin-bottom: 20px;
background-color: $color2;
}

.modal-text-button {
display: flex;
flex-direction: row;
justify-content: space-around;
}

.modal-button-cont {
display: flex;
gap: 20px;
}

.modal-form {
display: flex;
flex-direction: column;
gap: 10px;

}
3 changes: 2 additions & 1 deletion client/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

@import 'components/buttons';
@import 'components/cards';
@import 'components/columns'
@import 'components/columns';
@import 'components/modals';
6 changes: 6 additions & 0 deletions client/styles/pages/_home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
gap: 20px;
}

.column-container {
display: flex;
gap: 10px;

}

.overlay {
position: fixed;
top: 0;
Expand Down
2 changes: 1 addition & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ app.post(
// what should happen here on successful log in?
console.log("completing post request to '/login");
// res.redirect('/secret');
res.sendstatus(200)
res.sendStatus(200);
// res.redirect("/");
}
);
Expand Down
2 changes: 2 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ module.exports = {
port: 8080,
proxy: {
"/api": "http://localhost:3000",
"/login": "http://localhost:3000",
"/signup": "http://localhost:3000"
},
},
};

0 comments on commit b219483

Please sign in to comment.