Skip to content
This repository was archived by the owner on Mar 21, 2026. It is now read-only.

Commit d153b39

Browse files
committed
building main container, styled left container
1 parent 9e7f708 commit d153b39

10 files changed

Lines changed: 152 additions & 57 deletions

File tree

server/controllers/boardsController.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const boardsController = {
5858
},
5959
createBoard: async (req: Request, res: Response, next: NextFunction) => {
6060
try {
61-
console.log('req.body', req.body.boardName);
6261
const createdBoard = await Board.create({
6362
name: req.body.boardName,
6463
backlog: [],
@@ -94,6 +93,29 @@ const boardsController = {
9493
});
9594
}
9695
},
96+
getCurrentBoard: async (req: Request, res: Response, next: NextFunction) => {
97+
try {
98+
// find all boards beloning to the user, push board names into an array and save on locals
99+
const board = await User.findOne({ _id: req.params.boardID });
100+
console.log(board);
101+
if (!board) {
102+
return next({
103+
log: `boardsController.getCurrentBoard ERROR: Board cannot be found.`,
104+
status: 500,
105+
message: { err: 'Cannot find board.' },
106+
});
107+
}
108+
res.locals.boardInfo = board;
109+
return next();
110+
} catch (err) {
111+
// pass error through to global error handler
112+
return next({
113+
log: `boardssController.getCurrentBoard ERROR: ${err}`,
114+
status: 500,
115+
message: { err: 'Error getting current board' },
116+
});
117+
}
118+
},
97119
};
98120

99121
export default boardsController;

server/routes/boardsRouter.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
import express, { Request, Response } from "express";
1+
import express, { Request, Response } from 'express';
22

33
const router = express.Router();
44

55
// import controllers
6-
import boardsController from "../controllers/boardsController.ts";
6+
import boardsController from '../controllers/boardsController.ts';
77

88
// define routes
99

1010
// route for getting board names
1111
router.get(
12-
"/:userId",
12+
'/:userId',
1313
boardsController.getMyBoards,
1414
boardsController.getBoardNamesAndIds,
1515
(_req: Request, res: Response) => {
1616
return res.status(200).json(res.locals.namesAndIds);
1717
}
1818
);
1919

20+
router.get(
21+
'/:boardID',
22+
boardsController.getCurrentBoard,
23+
(_req: Request, res: Response) => {
24+
return res.status(200).json(res.locals.boardInfo);
25+
}
26+
);
27+
2028
router.post(
21-
"/create",
29+
'/create',
2230
boardsController.createBoard,
2331
boardsController.assignNewBoard,
2432
(_req: Request, res: Response) => {
25-
return res.sendStatus(200); //may need the board just created data to render into the main container
33+
return res.status(200).json(res.locals.createdBoard); //may need the board just created data to render into the main container
2634
}
2735
);
2836

src/components/CreateBoardModal.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { createPortal } from "react-dom";
2-
import { CreateBoardModalProps } from "../types";
3-
import { useState } from "react";
4-
import "../scss/modal.scss";
1+
import { createPortal } from 'react-dom';
2+
import { CreateBoardModalProps } from '../types';
3+
import { useState } from 'react';
4+
import '../scss/modal.scss';
55

66
const CreateBoardModal = ({
77
setCreatingBoard,
88
setCurrentBoard,
99
user,
1010
}: CreateBoardModalProps) => {
11-
const [boardName, setBoardName] = useState<string>("");
11+
const [boardName, setBoardName] = useState<string>('');
1212

1313
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
1414
setBoardName(e.target.value);
@@ -21,10 +21,10 @@ const CreateBoardModal = ({
2121
boardName: boardName,
2222
userId: user.id,
2323
};
24-
const response: Response = await fetch("/boards/create", {
25-
method: "POST",
24+
const response: Response = await fetch('/boards/create', {
25+
method: 'POST',
2626
headers: {
27-
"Content-type": "application/json; charset=UTF-8",
27+
'Content-type': 'application/json; charset=UTF-8',
2828
},
2929
body: JSON.stringify(body),
3030
});
@@ -33,31 +33,31 @@ const CreateBoardModal = ({
3333
if (response.status === 200) {
3434
const responseData = await response.json();
3535
setCreatingBoard(false);
36-
setCurrentBoard(responseData.name);
36+
console.log('Board created: ', responseData);
3737
} else {
38-
console.log("Board creation failed");
38+
console.log('Failed To create board.');
3939
}
4040
};
4141

4242
return createPortal(
43-
<div className="modal-overlay">
44-
<div className="modal">
45-
<form className="modal-form" onSubmit={handleFormSubmit}>
46-
<h2 className="modal-title">New Board</h2>
43+
<div className='modal-overlay'>
44+
<div className='modal'>
45+
<form className='modal-form' onSubmit={handleFormSubmit}>
46+
<h2 className='modal-title'>New Board</h2>
4747
<input
48-
className="modal-input"
49-
name="boardname"
50-
type="text"
51-
placeholder="Enter Board Name"
48+
className='modal-input'
49+
name='boardname'
50+
type='text'
51+
placeholder='Enter Board Name'
5252
onChange={handleInputChange}
5353
required
5454
/>
55-
<div className="modal-btns">
56-
<button className="modal-submit" type="submit">
55+
<div className='modal-btns'>
56+
<button className='modal-submit' type='submit'>
5757
Save
5858
</button>
5959
<button
60-
className="modal-cancel"
60+
className='modal-cancel'
6161
onClick={() => {
6262
setCreatingBoard(false);
6363
}}
@@ -68,7 +68,7 @@ const CreateBoardModal = ({
6868
</form>
6969
</div>
7070
</div>,
71-
document.getElementById("portal") as Element
71+
document.getElementById('portal') as Element
7272
);
7373
};
7474

src/containers/LeftContainer.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,44 @@
1-
import { ContainerProps, BoardListItemState } from "../types";
2-
import { useEffect, useState } from "react";
3-
import CreateBoardModal from "../components/CreateBoardModal";
4-
import "../scss/leftContainer.scss";
1+
import { ContainerProps, BoardListItemState } from '../types';
2+
import { useEffect, useState } from 'react';
3+
import CreateBoardModal from '../components/CreateBoardModal';
4+
import '../scss/leftContainer.scss';
55

66
const LeftContainer = ({ user, setCurrentBoard }: ContainerProps) => {
77
// creating state to open board creating modal
88
const [creatingBoard, setCreatingBoard] = useState<boolean>(false);
99
// creating state to store the list of board names
1010
const [boardList, setBoardList] = useState<BoardListItemState[]>([]);
1111
// make a request for all board naames, return an array containing strings of the board names
12-
console.log(user);
1312
useEffect(() => {
1413
const fetchBoardList = async () => {
1514
const reponse: Response = await fetch(`/boards/${user.id}`);
1615
const list = await reponse.json();
1716
setBoardList(list);
18-
console.log("boardList: ", boardList);
1917
};
2018
fetchBoardList().catch(console.error);
2119
}, []);
2220

2321
// function for changing board when click selection button
2422
const handleBoardSelect = (e: React.MouseEvent<HTMLButtonElement>) => {
25-
e.preventDefault;
23+
e.preventDefault();
2624
setCurrentBoard({
2725
name: e.currentTarget.name,
2826
id: e.currentTarget.id,
2927
});
3028
};
3129

3230
// function for creating a new board
33-
const handleCreateBoard = (e: React.MouseEvent<HTMLButtonElement>) => {
34-
e.preventDefault;
31+
const handleCreateBoard = () => {
3532
// create a pop up to create the new board
3633
setCreatingBoard(true);
3734
};
3835

3936
// iterate through board names push buttons or components into array boardlist in state
4037
const boardSelectors = [];
4138
for (let i = 0; i < boardList.length; i++) {
42-
console.log("boardList[i]: ", boardList[i]);
4339
boardSelectors.push(
4440
<button
45-
className="board-selector"
41+
className='board-selector'
4642
onClick={handleBoardSelect}
4743
name={boardList[i].name}
4844
id={boardList[i].id}
@@ -54,22 +50,24 @@ const LeftContainer = ({ user, setCurrentBoard }: ContainerProps) => {
5450
}
5551

5652
return (
57-
<div className="left-container">
58-
<div className="boards-info">
59-
<h1 className="heading">{user.name}'s Boards</h1>
60-
<button className="new-board-btn" onClick={handleCreateBoard}>
53+
<div className='left-container'>
54+
<h1 className='heading'>Hello, {user.name}</h1>
55+
<div className='boards-info'>
56+
<button className='new-board-btn' onClick={handleCreateBoard}>
6157
Create New Board +
6258
</button>
63-
<div className="board-selectors">{boardSelectors}</div>
59+
<div className='board-selectors'>{boardSelectors}</div>
6460
</div>
65-
<button className="settings-btn">Settings</button>
6661
{creatingBoard ? (
6762
<CreateBoardModal
6863
setCreatingBoard={setCreatingBoard}
6964
setCurrentBoard={setCurrentBoard}
7065
user={user}
7166
/>
7267
) : null}
68+
<footer>
69+
<button className='settings-btn'>Settings</button>
70+
</footer>
7371
</div>
7472
);
7573
};

src/containers/MainContainer.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
import "../scss/mainContainer.scss";
1+
import { useState, useEffect } from 'react';
2+
import '../scss/mainContainer.scss';
3+
import { ContainerProps } from '../types';
24

3-
const MainContainer = () => {
4-
return <div className="main-container">Main Container</div>;
5+
const MainContainer = ({ currentBoard }: ContainerProps) => {
6+
// const [view, setView] = useState();
7+
useEffect(() => {
8+
const fetchBoard = async () => {
9+
const reponse: Response = await fetch(`/boards/${currentBoard.id}`);
10+
const board = await reponse.json();
11+
console.log(board);
12+
};
13+
fetchBoard().catch(console.error);
14+
}, []);
15+
16+
return (
17+
<div className='main-container'>
18+
<h1>{currentBoard.name}</h1>
19+
<div className='task-container'></div>
20+
</div>
21+
);
522
};
623

724
export default MainContainer;

src/routes/Dashboard.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ const Dashboard = ({ user }: DashboardProps) => {
1111
id: '',
1212
});
1313
//state confirmDelete false
14-
console.log('User in dash board', user);
1514
return (
1615
<div className='main-page'>
1716
<LeftContainer user={user} setCurrentBoard={setCurrentBoard} />
18-
<MainContainer />
17+
<MainContainer currentBoard={currentBoard}/>
1918
</div>
2019
);
2120
};

src/scss/leftContainer.scss

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,65 @@
33
height: 100%;
44
background-color: rgb(22, 22, 22);
55
margin: 0;
6-
padding: 20px;
76
display: flex;
87
flex-direction: column;
98
justify-content: space-between;
9+
text-align: center; /* Center text horizontally */
10+
h1 {
11+
padding: 10px;
12+
}
13+
footer {
14+
margin-top: auto;
15+
height: fit-content;
16+
}
17+
.settings-btn {
18+
margin: 20px;
19+
border: 2px solid rgb(169, 166, 166);
20+
border-radius: 10px;
21+
background-color: rgb(22, 22, 22);
22+
color: white;
23+
font-size: x-large;
24+
padding: 10px;
25+
&:hover {
26+
background-color: rgb(54, 53, 53);
27+
}
28+
}
29+
}
30+
.boards-info {
31+
display: flex;
32+
flex-direction: column;
33+
justify-content: space-between;
34+
align-items: center;
35+
}
36+
.board-selector {
37+
display: flex;
38+
flex-direction: column;
1039
align-items: center;
40+
color: white;
41+
background-color: rgb(22, 22, 22);
42+
padding: 15px;
43+
border: 2px solid rgb(22, 22, 22);
44+
border-radius: 4px;
45+
font-weight: bold;
46+
font-size: large;
47+
width: 200px;
48+
margin: 10px;
49+
&:hover {
50+
border: 2px solid rgb(195, 255, 14);
51+
}
52+
&:target {
53+
border: 2px solid rgb(195, 255, 14);
54+
}
1155
}
12-
.boardSelector {
56+
.new-board-btn {
1357
align-self: center;
14-
background-color: #4caf50;
15-
color: #fff;
58+
border: 2px solid rgb(22, 22, 22);
59+
border-radius: 10px;
60+
background-color: rgb(22, 22, 22);
61+
color: white;
62+
font-size: large;
1663
padding: 10px;
17-
border: 1px solid black;
18-
border-radius: 4px;
64+
&:hover {
65+
background-color: rgb(54, 53, 53);
66+
}
1967
}

src/scss/mainContainer.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.main-container {
22
width: 80%;
33
text-align: center;
4+
height: 100%;
45
}

src/scss/modal.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@
5757

5858
.modal-submit {
5959
background-color: #4caf50;
60+
width: 100px;
6061
}
6162

6263
.modal-cancel {
6364
background-color: goldenrod;
65+
width: 100px;
6466
}
6567
}
6668
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type DashboardProps = {
1313

1414
export type ContainerProps = {
1515
user: UserState;
16-
currentBoard?: string;
16+
currentBoard?: CurrentBoardState;
1717
setCurrentBoard: React.Dispatch<React.SetStateAction<CurrentBoardState>>;
1818
};
1919

0 commit comments

Comments
 (0)