mirror of
https://github.com/bendtherules/demo-trello-app.git
synced 2026-08-18 13:42:40 +00:00
Refactor Board into separate TaskList and Taskcard
This commit is contained in:
@@ -1,29 +1,23 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { createList, selectBoard } from "../../storeSlices/boardSlice";
|
|
||||||
|
import { TaskList } from "../TaskList/TaskList";
|
||||||
|
import { NewTaskListPrompt } from "../TaskList/NewTaskListPrompt";
|
||||||
|
|
||||||
import styles from "./Board.module.css";
|
import styles from "./Board.module.css";
|
||||||
|
|
||||||
export function Board() {
|
export function Board() {
|
||||||
const boardData = useSelector(selectBoard);
|
const selectBoardData = state => state.board;
|
||||||
const dispatch = useDispatch();
|
const boardData = useSelector(selectBoardData);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className={styles.boardName}>{boardData.name}</div>
|
<div className={styles.boardName}>{boardData.name}</div>
|
||||||
<div className={styles.listsContainer}>
|
<div className={styles.listsContainer}>
|
||||||
{boardData.lists.map(listData => (
|
{boardData.lists.map(listData => (
|
||||||
<div key={listData.id} className={styles.listContainer}>
|
<TaskList key={listData.id} listData={listData} />
|
||||||
<div className={styles.listName}>{listData.name}</div>
|
|
||||||
<div className={styles.cardsContainer}>
|
|
||||||
{listData.cards.map(cardData => (
|
|
||||||
<div key={cardData.id} className={styles.cardContainer}>
|
|
||||||
{cardData.text}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
))}
|
||||||
|
<NewTaskListPrompt key="newListPrompt" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
|
import { createList } from "../../storeSlices/boardSlice";
|
||||||
|
|
||||||
|
import styles from "./TaskCard.module.css";
|
||||||
|
|
||||||
|
export function TaskCard({ cardData }) {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.cardContainer}>
|
||||||
|
{cardData.text}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
|
import { useDispatch } from "react-redux";
|
||||||
|
import { createList } from "../../storeSlices/boardSlice";
|
||||||
|
|
||||||
|
import styles from "./TaskList.module.css";
|
||||||
|
|
||||||
|
export function NewTaskListPrompt() {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
const [newListname, setNewListname] = useState("");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.listContainer}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Create list"
|
||||||
|
value={newListname}
|
||||||
|
onChange={e => setNewListname(e.target.value)}
|
||||||
|
onKeyPress={e => {
|
||||||
|
if (newListname.trim().length > 0 && e.key === "Enter") {
|
||||||
|
dispatch(createList({ name: newListname }));
|
||||||
|
|
||||||
|
setNewListname("");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
></input>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
|
|
||||||
|
import { createList } from "../../storeSlices/boardSlice";
|
||||||
|
|
||||||
|
import { TaskCard } from "../TaskCard/TaskCard";
|
||||||
|
|
||||||
|
import styles from "./TaskList.module.css";
|
||||||
|
|
||||||
|
export function TaskList({ listData }) {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.listContainer}>
|
||||||
|
<div className={styles.listName}>{listData.name}</div>
|
||||||
|
<div className={styles.cardsContainer}>
|
||||||
|
{/* Refactor to card component */}
|
||||||
|
{listData.cards.map(cardData => (
|
||||||
|
<TaskCard key={cardData.id} cardData={cardData} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -54,9 +54,4 @@ export const slice = createSlice({
|
|||||||
|
|
||||||
export const { createList } = slice.actions;
|
export const { createList } = slice.actions;
|
||||||
|
|
||||||
// The function below is called a selector and allows us to select a value from
|
|
||||||
// the state. Selectors can also be defined inline where they're used instead of
|
|
||||||
// in the slice file. For example: `useSelector((state) => state.counter.value)`
|
|
||||||
export const selectBoard = state => state.board;
|
|
||||||
|
|
||||||
export default slice.reducer;
|
export default slice.reducer;
|
||||||
|
|||||||
Reference in New Issue
Block a user