Skip to content

Instantly share code, notes, and snippets.

@TheHumanistX
Created May 27, 2023 23:38
Show Gist options
  • Save TheHumanistX/4fa02817ef89b74bb1cc7da0035ce7e9 to your computer and use it in GitHub Desktop.
Save TheHumanistX/4fa02817ef89b74bb1cc7da0035ce7e9 to your computer and use it in GitHub Desktop.
import React from 'react';
import { Box } from '@mui/material';
const CardContainer = ({ children }) => {
return (
<Box
width="31vw"
height="100%"
bgcolor="cardBackgroundColor.main"
p={2}
display="flex"
flexDirection="column"
borderRadius="22px"
justifyContent="center"
alignItems="center"
boxSizing="border-box"
>
{children}
</Box>
);
};
export default CardContainer;
import React, { useContext } from 'react';
import { Typography, Card, CardContent, Box } from '@mui/material';
import { Task, AddButton, CardContainer } from '../';
import { TodoContext } from '../../context/TodoContext';
const Tasks = ( ) => {
const { selectedTaskList, setAddTaskMode } = useContext(TodoContext);
if (!selectedTaskList) {
return (
<CardContainer>
<Typography variant="h5" mb={2}>
Please select a task list.
</Typography>
</CardContainer>
);
}
const tasksCompleted = selectedTaskList.tasks.filter((task) => task.completed);
const tasksOutstanding = selectedTaskList.tasks.filter((task) => !task.completed);
const handleAddTask = () => {
// Handle adding a new task
console.log('Selected Task List In Tasks: ', selectedTaskList)
setAddTaskMode(true);
};
return (
<CardContainer>
<Typography variant="h5" mb={2}>
{selectedTaskList.listName} Tasks
</Typography>
<Typography variant="h6" mb={2}>
Outstanding ({tasksOutstanding.length}):
</Typography>
<Box
width="100%"
p={2}
display="flex"
flexDirection="column"
borderRadius="22px"
justifyContent="stretch"
alignItems="center"
boxSizing="border-box"
>
{selectedTaskList && selectedTaskList.tasks.map((task) => (
<Task key={task.taskId} task={task} />
))}
</Box>
<Card variant="plain" sx={{ backgroundColor: 'cardBackgroundColor.main', mt: 'auto', ml: 'auto' }}>
<CardContent>
<AddButton onClick={() => handleAddTask()} />
</CardContent>
</Card>
</CardContainer>
);
};
export default Tasks;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment