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

Commit c15614a

Browse files
authored
Merge pull request #2 from OS-Builders/leftcontainer
Leftcontainer
2 parents dca18d4 + 24e8961 commit c15614a

6 files changed

Lines changed: 99 additions & 61 deletions

File tree

src/components/CreateBoardModal.tsx

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
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,
10+
boardList,
11+
setBoardList,
12+
handleBoardSelect,
13+
selectedBoard,
1014
}: CreateBoardModalProps) => {
11-
const [boardName, setBoardName] = useState<string>('');
15+
const [boardName, setBoardName] = useState<string>("");
1216

1317
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
1418
const inputValue: string = e.target.value;
@@ -22,49 +26,64 @@ const CreateBoardModal = ({
2226
boardName: boardName,
2327
userId: user.id,
2428
};
25-
const response: Response = await fetch('/boards/create', {
26-
method: 'POST',
29+
const response: Response = await fetch("/boards/create", {
30+
method: "POST",
2731
headers: {
28-
'Content-type': 'application/json; charset=UTF-8',
32+
"Content-type": "application/json; charset=UTF-8",
2933
},
3034
body: JSON.stringify(body),
3135
});
32-
// receive username from backend
36+
// receive usernam and id from backend
3337
// if request success, save username to state and route to dashboard
3438
if (response.status === 200) {
3539
const responseData = await response.json();
40+
console.log("Board created: ", responseData);
41+
const newBoardListItem = (
42+
<button
43+
className={`board-selector ${
44+
selectedBoard === responseData._id ? "selected" : ""
45+
}`}
46+
onClick={handleBoardSelect}
47+
name={responseData.name}
48+
id={responseData._id}
49+
key={responseData._id}
50+
>
51+
{responseData.name}
52+
</button>
53+
);
54+
setBoardList([...boardList, newBoardListItem]);
55+
setCurrentBoard({ name: responseData.name, id: responseData._id });
3656
setCreatingBoard(false);
37-
console.log('Board created: ', responseData);
3857
} else {
39-
console.log('Failed To create board.');
58+
console.log("Failed To create board.");
4059
}
4160
};
4261

43-
const isButtonDisabled: boolean = boardName === ''; //checking if boardName is empty? using trim in handle input
62+
const isButtonDisabled: boolean = boardName === ""; //checking if boardName is empty? using trim in handle input
4463

4564
return createPortal(
46-
<div className='modal-overlay'>
47-
<div className='modal'>
48-
<form className='modal-form' onSubmit={handleFormSubmit}>
49-
<h2 className='modal-title'>New Board</h2>
65+
<div className="modal-overlay">
66+
<div className="modal">
67+
<form className="modal-form" onSubmit={handleFormSubmit}>
68+
<h2 className="modal-title">New Board</h2>
5069
<input
51-
className='modal-input'
52-
name='boardname'
53-
type='text'
54-
placeholder='Enter Board Name'
70+
className="modal-input"
71+
name="boardname"
72+
type="text"
73+
placeholder="Enter Board Name"
5574
onChange={handleInputChange}
5675
required
5776
/>
58-
<div className='modal-btns'>
77+
<div className="modal-btns">
5978
<button
60-
className='modal-submit'
61-
type='submit'
79+
className="modal-submit"
80+
type="submit"
6281
disabled={isButtonDisabled}
6382
>
6483
Save
6584
</button>
6685
<button
67-
className='modal-cancel'
86+
className="modal-cancel"
6887
onClick={() => {
6988
setCreatingBoard(false);
7089
}}
@@ -75,7 +94,7 @@ const CreateBoardModal = ({
7594
</form>
7695
</div>
7796
</div>,
78-
document.getElementById('portal') as Element
97+
document.getElementById("portal") as Element
7998
);
8099
};
81100

src/containers/LeftContainer.tsx

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
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 { BoardListItemState, ContainerProps } from "../types";
2+
import { ReactNode, 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
10-
const [boardList, setBoardList] = useState<BoardListItemState[]>([]);
10+
const [boardList, setBoardList] = useState<ReactNode[]>([]);
1111
//state for selected board
1212
const [selectedBoard, setSelectedBoard] = useState<string | null>(null);
1313
// make a request for all board naames, return an array containing strings of the board names
1414
useEffect(() => {
1515
const fetchBoardList = async () => {
1616
const reponse: Response = await fetch(`/boards/${user.id}`);
1717
const list = await reponse.json();
18-
setBoardList(list);
18+
const boardSelectors = list.map((board: BoardListItemState) => (
19+
<button
20+
className={`board-selector ${
21+
selectedBoard === board.id ? "selected" : ""
22+
}`}
23+
onClick={handleBoardSelect}
24+
name={board.name}
25+
id={board.id}
26+
key={board.id}
27+
>
28+
{board.name}
29+
</button>
30+
));
31+
setBoardList(boardSelectors);
1932
};
2033
fetchBoardList().catch(console.error);
34+
// iterate through board names push buttons or components into array boardlist in state
2135
}, []);
2236

2337
// function for changing board when click selection button
@@ -36,39 +50,29 @@ const LeftContainer = ({ user, setCurrentBoard }: ContainerProps) => {
3650
setCreatingBoard(true);
3751
};
3852

39-
// iterate through board names push buttons or components into array boardlist in state
40-
const boardSelectors = boardList.map((board, index) => (
41-
<button
42-
className={`board-selector ${
43-
selectedBoard === board.id ? 'selected' : ''
44-
}`}
45-
onClick={handleBoardSelect}
46-
name={board.name}
47-
id={board.id}
48-
key={index}
49-
>
50-
{board.name}
51-
</button>
52-
));
53-
5453
return (
55-
<div className='left-container'>
56-
<h1 className='heading'>Hello, {user.name}</h1>
57-
<button className='new-board-btn' onClick={handleCreateBoard}>
54+
<div className="left-container">
55+
<h1 className="heading">Task Pro</h1>
56+
<h1 className="heading">{user.name}'s Boards</h1>
57+
<button className="new-board-btn" onClick={handleCreateBoard}>
5858
Create New Board +
5959
</button>
60-
<div className='boards-info'>
61-
<div className='board-selectors'>{boardSelectors}</div>
60+
<div className="boards-info">
61+
<div className="board-selectors">{boardList}</div>
6262
</div>
6363
{creatingBoard ? (
6464
<CreateBoardModal
6565
setCreatingBoard={setCreatingBoard}
6666
setCurrentBoard={setCurrentBoard}
6767
user={user}
68+
boardList={boardList}
69+
setBoardList={setBoardList}
70+
handleBoardSelect={handleBoardSelect}
71+
selectedBoard={selectedBoard}
6872
/>
6973
) : null}
7074
<footer>
71-
<button className='setting-button'>Setting</button>
75+
<button className="settings-button">Settings</button>
7276
</footer>
7377
</div>
7478
);

src/containers/MainContainer.tsx

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

55
const MainContainer = ({ currentBoard }: ContainerProps) => {
66
// const [view, setView] = useState();
@@ -13,10 +13,20 @@ const MainContainer = ({ currentBoard }: ContainerProps) => {
1313
fetchBoard().catch(console.error);
1414
}, []);
1515

16+
if (!currentBoard?.name) {
17+
return (
18+
<div className="main-container">
19+
<h1 className="heading">
20+
Select existing board or create a new one to get started!
21+
</h1>
22+
</div>
23+
);
24+
}
25+
1626
return (
17-
<div className='main-container'>
27+
<div className="main-container">
1828
<h1>{currentBoard.name}</h1>
19-
<div className='task-container'></div>
29+
<div className="task-container"></div>
2030
</div>
2131
);
2232
};

src/scss/dashBoard.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
color: white;
33
display: flex;
44
height: 100%;
5+
width: 100%;
56
}

src/scss/leftContainer.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.left-container {
2-
width: 20%;
2+
width: 300px;
33
height: 100%;
44
background-color: rgb(22, 22, 22);
55
margin: 0;
@@ -14,7 +14,7 @@
1414
margin-top: auto;
1515
height: 60px;
1616
}
17-
.setting-button {
17+
.settings-button {
1818
border: none;
1919
background-color: rgb(22, 22, 22);
2020
color: white;
@@ -84,7 +84,7 @@
8484
border-radius: 5px;
8585

8686
&:before {
87-
content: '';
87+
content: "";
8888
background: linear-gradient(
8989
45deg,
9090
#ff0000,
@@ -115,7 +115,7 @@
115115
// }
116116
&:after {
117117
z-index: -1;
118-
content: '';
118+
content: "";
119119
position: absolute;
120120
width: 100%;
121121
height: 100%;

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export type ContainerProps = {
2020
export type CreateBoardModalProps = {
2121
setCreatingBoard: React.Dispatch<React.SetStateAction<boolean>>;
2222
setCurrentBoard: React.Dispatch<React.SetStateAction<CurrentBoardState>>;
23+
boardList: React.ReactNode[];
24+
setBoardList: React.Dispatch<React.SetStateAction<React.ReactNode[]>>;
2325
user: UserState;
26+
handleBoardSelect: (e: React.MouseEvent<HTMLButtonElement>) => void;
27+
selectedBoard: string | null;
2428
};
2529

2630
export interface UserState {

0 commit comments

Comments
 (0)