mirror of
https://github.com/sergeyyarkov/todo-app.git
synced 2026-10-11 10:29:14 +03:00
category modals
This commit is contained in:
parent
792d013c08
commit
5357e3c0ca
@ -3,11 +3,11 @@ import { Link } from 'react-router-dom'
|
|||||||
import { ListItem, ListItemText } from '@material-ui/core'
|
import { ListItem, ListItemText } from '@material-ui/core'
|
||||||
|
|
||||||
const Categories = ({ data, history, classes }) => {
|
const Categories = ({ data, history, classes }) => {
|
||||||
return data.map((e, i) => {
|
return data.map((category, i) => {
|
||||||
return (
|
return (
|
||||||
<Link className={classes.link} key={i} to={`/category/${i}`}>
|
<Link className={classes.link} key={i} to={`/category/${category._id.$oid}`}>
|
||||||
<ListItem selected={history.location.pathname === `/category/${i}`} button className={classes.nested}>
|
<ListItem selected={history.location.pathname === `/category/${category._id.$oid}`} button className={classes.nested}>
|
||||||
<ListItemText primary={"Категория " + i} />
|
<ListItemText primary={category.title} />
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</Link>
|
</Link>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -0,0 +1,69 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import useStyles from '../styles'
|
||||||
|
import { Dialog, DialogContent, DialogTitle, DialogActions, Button, TextField } from '@material-ui/core'
|
||||||
|
|
||||||
|
import CategoryIcon from '@material-ui/icons/Category';
|
||||||
|
|
||||||
|
const CreateCategoryModal = ({ isModalOpen, handleCloseModal }) => {
|
||||||
|
const classes = useStyles()
|
||||||
|
const [fieldsData, setFieldsData] = React.useState({
|
||||||
|
title: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleFormSubmit = e => {
|
||||||
|
e.preventDefault()
|
||||||
|
const elements = e.target.elements
|
||||||
|
const data = {
|
||||||
|
title: elements.title.value,
|
||||||
|
}
|
||||||
|
handleCloseModal()
|
||||||
|
setFieldsData({
|
||||||
|
title: '',
|
||||||
|
})
|
||||||
|
console.log('Request on create category:', data)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleFieldChange = e => {
|
||||||
|
const target = e.target
|
||||||
|
setFieldsData({
|
||||||
|
title: target.name === 'title' ? target.value : fieldsData.title,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Dialog fullWidth={true} open={isModalOpen} onClose={handleCloseModal} color='default'>
|
||||||
|
<DialogTitle>
|
||||||
|
<CategoryIcon className={classes.headingIcon} /> Добавить новую категорию
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<form onSubmit={handleFormSubmit} noValidate autoComplete="off" className={classes.form}>
|
||||||
|
<TextField
|
||||||
|
name='title'
|
||||||
|
label="Название категории"
|
||||||
|
margin="normal"
|
||||||
|
placeholder='Название вашей категории'
|
||||||
|
variant="outlined"
|
||||||
|
className={classes.textField}
|
||||||
|
value={fieldsData.title}
|
||||||
|
onChange={handleFieldChange}
|
||||||
|
InputLabelProps={{
|
||||||
|
shrink: true,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<DialogActions>
|
||||||
|
<Button type='submit' color="default">
|
||||||
|
Добавить
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleCloseModal} color="secondary">
|
||||||
|
Закрыть
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CreateCategoryModal
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import useStyles from '../styles'
|
||||||
|
import { Dialog, DialogContent, DialogTitle, DialogActions, Button, TextField } from '@material-ui/core'
|
||||||
|
import EditIcon from '@material-ui/icons/Edit'
|
||||||
|
|
||||||
|
|
||||||
|
const UpdateCategoryModal = ({ isModalOpen, handleCloseModal, selectedCategory, setSelectedCategory }) => {
|
||||||
|
const classes = useStyles()
|
||||||
|
const handleFormSubmit = e => {
|
||||||
|
e.preventDefault()
|
||||||
|
const elements = e.target.elements
|
||||||
|
const data = {
|
||||||
|
id: elements.title.value,
|
||||||
|
}
|
||||||
|
handleCloseModal()
|
||||||
|
console.log('Request on update category:', data)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(selectedCategory)
|
||||||
|
|
||||||
|
const handleFieldChange = e => {
|
||||||
|
const target = e.target
|
||||||
|
// setSelectedCategory({
|
||||||
|
// id: target.name === 'title' ? target.value : selectedTodo.title,
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Dialog fullWidth={true} open={isModalOpen} onClose={handleCloseModal} color='default'>
|
||||||
|
<DialogTitle className={classes.heading}>
|
||||||
|
<EditIcon className={classes.headingIcon} />
|
||||||
|
Изменить категорию
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<form onSubmit={handleFormSubmit} noValidate autoComplete="off" className={classes.form}>
|
||||||
|
<TextField
|
||||||
|
name='title'
|
||||||
|
label="Название вашей категории"
|
||||||
|
margin="normal"
|
||||||
|
placeholder='Название вашей категории'
|
||||||
|
variant="outlined"
|
||||||
|
className={classes.textField}
|
||||||
|
value={selectedCategory.id}
|
||||||
|
onChange={handleFieldChange}
|
||||||
|
InputLabelProps={{
|
||||||
|
shrink: true,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<DialogActions>
|
||||||
|
<Button type='submit' color="default">
|
||||||
|
Обновить
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleCloseModal} color="secondary">
|
||||||
|
Закрыть
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UpdateCategoryModal
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import useStyles from './styles'
|
import useStyles from '../styles'
|
||||||
import { Dialog, DialogContent, DialogTitle, DialogActions, Button, TextField, Select, MenuItem, InputLabel, FormControl } from '@material-ui/core'
|
import { Dialog, DialogContent, DialogTitle, DialogActions, Button, TextField, Select, MenuItem, InputLabel, FormControl } from '@material-ui/core'
|
||||||
import AddIcon from '@material-ui/icons/Add'
|
import AddIcon from '@material-ui/icons/Add'
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import useStyles from './styles'
|
import useStyles from '../styles'
|
||||||
import { Dialog, DialogContent, DialogTitle, DialogActions, Button, TextField, Select, MenuItem, InputLabel, FormControl } from '@material-ui/core'
|
import { Dialog, DialogContent, DialogTitle, DialogActions, Button, TextField, Select, MenuItem, InputLabel, FormControl } from '@material-ui/core'
|
||||||
import EditIcon from '@material-ui/icons/Edit'
|
import EditIcon from '@material-ui/icons/Edit'
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import NavContent from './NavContent/NavContent'
|
import NavContent from './NavContent/NavContent'
|
||||||
|
import CreateCategoryModal from '../Modals/Category/CreateCategoryModal'
|
||||||
import { Drawer, Hidden, makeStyles, useTheme } from '@material-ui/core';
|
import { Drawer, Hidden, makeStyles, useTheme } from '@material-ui/core';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
@ -17,40 +18,46 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
const Nav = ({ window, mobileOpen, handleDrawerToggle, history }) => {
|
const Nav = ({ window, mobileOpen, handleDrawerToggle, history }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const container = window !== undefined ? () => window().document.body : undefined;
|
const container = window !== undefined ? () => window().document.body : undefined;
|
||||||
|
|
||||||
|
const [isModalOpen, setIsModalOpen] = React.useState(false)
|
||||||
|
const handleCloseModal = () => setIsModalOpen(false)
|
||||||
|
const handleOpenModal = () => setIsModalOpen(true)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className={classes.drawer} aria-label="mailbox folders">
|
<>
|
||||||
<Hidden smUp implementation="css">
|
<CreateCategoryModal isModalOpen={isModalOpen} handleCloseModal={handleCloseModal} />
|
||||||
<Drawer
|
<nav className={classes.drawer} aria-label="mailbox folders">
|
||||||
container={container}
|
<Hidden smUp implementation="css">
|
||||||
variant="temporary"
|
<Drawer
|
||||||
anchor={theme.direction === 'rtl' ? 'right' : 'left'}
|
container={container}
|
||||||
open={mobileOpen}
|
variant="temporary"
|
||||||
onClose={handleDrawerToggle}
|
anchor={theme.direction === 'rtl' ? 'right' : 'left'}
|
||||||
classes={{
|
open={mobileOpen}
|
||||||
paper: classes.drawerPaper,
|
onClose={handleDrawerToggle}
|
||||||
}}
|
classes={{
|
||||||
ModalProps={{
|
paper: classes.drawerPaper,
|
||||||
keepMounted: true,
|
}}
|
||||||
}}
|
ModalProps={{
|
||||||
>
|
keepMounted: true,
|
||||||
<NavContent history={history} />
|
}}
|
||||||
</Drawer>
|
>
|
||||||
</Hidden>
|
<NavContent handleOpenModal={handleOpenModal} history={history} />
|
||||||
<Hidden xsDown implementation="css">
|
</Drawer>
|
||||||
<Drawer
|
</Hidden>
|
||||||
classes={{
|
<Hidden xsDown implementation="css">
|
||||||
paper: classes.drawerPaper,
|
<Drawer
|
||||||
}}
|
classes={{
|
||||||
variant="permanent"
|
paper: classes.drawerPaper,
|
||||||
open
|
}}
|
||||||
>
|
variant="permanent"
|
||||||
<NavContent history={history} />
|
open
|
||||||
</Drawer>
|
>
|
||||||
</Hidden>
|
<NavContent handleOpenModal={handleOpenModal} history={history} />
|
||||||
</nav>
|
</Drawer>
|
||||||
|
</Hidden>
|
||||||
|
</nav>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,8 @@ import GitHubIcon from '@material-ui/icons/GitHub';
|
|||||||
import ExpandLess from '@material-ui/icons/ExpandLess'
|
import ExpandLess from '@material-ui/icons/ExpandLess'
|
||||||
import ExpandMore from '@material-ui/icons/ExpandMore'
|
import ExpandMore from '@material-ui/icons/ExpandMore'
|
||||||
|
|
||||||
|
import categories from '../../../db/categories.json'
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
navHeading: {
|
navHeading: {
|
||||||
padding: '10px 0px 10px 16px',
|
padding: '10px 0px 10px 16px',
|
||||||
@ -41,7 +43,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const NavContent = ({ history }) => {
|
const NavContent = ({ history, handleOpenModal }) => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const [collapseInfo, setCollapseInfo] = React.useState({
|
const [collapseInfo, setCollapseInfo] = React.useState({
|
||||||
idCollapse: 0,
|
idCollapse: 0,
|
||||||
@ -57,55 +59,55 @@ const NavContent = ({ history }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={classes.navHeading}>
|
<div className={classes.navHeading}>
|
||||||
<Typography>
|
<Typography>
|
||||||
<MuiLink style={{ color: 'rgba(255, 255, 255, 0.7)' }} href="#" variant='h1'>
|
<MuiLink style={{ color: 'rgba(255, 255, 255, 0.7)' }} href="#" variant='h1'>
|
||||||
Todo App
|
Todo App
|
||||||
</MuiLink>
|
</MuiLink>
|
||||||
<br />
|
<br />
|
||||||
<span className={classes.author} href="#">
|
<span className={classes.author} href="#">
|
||||||
Github: <MuiLink href='https://github.com/sergeyyarkov/todo-app' target='_blank'><GitHubIcon className={classes.githubIcon} color='action' fontSize='small' /></MuiLink>
|
Github: <MuiLink href='https://github.com/sergeyyarkov/todo-app' target='_blank'><GitHubIcon className={classes.githubIcon} color='action' fontSize='small' /></MuiLink>
|
||||||
</span>
|
</span>
|
||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
<Divider />
|
|
||||||
<List>
|
|
||||||
<Link className={classes.link} to='/'>
|
|
||||||
<ListItem selected={history.location.pathname === '/'} button>
|
|
||||||
<ListItemIcon>
|
|
||||||
<FormatListBulletedIcon />
|
|
||||||
</ListItemIcon>
|
|
||||||
<ListItemText primary={'Список дел'} />
|
|
||||||
</ListItem>
|
|
||||||
</Link>
|
|
||||||
<ListItem onClick={(e) => listItemSelectedHandler(e, 1)} button>
|
|
||||||
<ListItemIcon>
|
|
||||||
<CategoryIcon />
|
|
||||||
</ListItemIcon>
|
|
||||||
<ListItemText primary={'Категории'} />
|
|
||||||
{collapseInfo.isCollapseOpen ? <ExpandLess /> : <ExpandMore />}
|
|
||||||
</ListItem>
|
|
||||||
<Collapse in={collapseInfo.isCollapseOpen} timeout="auto" unmountOnExit>
|
|
||||||
<List component="div" disablePadding>
|
|
||||||
<Categories data={[1,2,3]} history={history} classes={classes} />
|
|
||||||
<ListItem className={classes.addCategoryItem}>
|
|
||||||
<IconButton aria-label="add">
|
|
||||||
<AddIcon />
|
|
||||||
</IconButton>
|
|
||||||
</ListItem>
|
|
||||||
</List>
|
|
||||||
</Collapse>
|
|
||||||
<Divider />
|
<Divider />
|
||||||
<Link className={classes.link} to='/trash'>
|
<List>
|
||||||
<ListItem selected={history.location.pathname === '/trash'} button>
|
<Link className={classes.link} to='/'>
|
||||||
|
<ListItem selected={history.location.pathname === '/'} button>
|
||||||
|
<ListItemIcon>
|
||||||
|
<FormatListBulletedIcon />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary={'Список дел'} />
|
||||||
|
</ListItem>
|
||||||
|
</Link>
|
||||||
|
<ListItem onClick={(e) => listItemSelectedHandler(e, 1)} button>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<DeleteIcon />
|
<CategoryIcon />
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText primary={'Корзина'} />
|
<ListItemText primary={'Категории'} />
|
||||||
|
{collapseInfo.isCollapseOpen ? <ExpandLess /> : <ExpandMore />}
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</Link>
|
<Collapse in={collapseInfo.isCollapseOpen} timeout="auto" unmountOnExit>
|
||||||
</List>
|
<List component="div" disablePadding>
|
||||||
</>
|
<Categories data={categories} history={history} classes={classes} />
|
||||||
|
<ListItem className={classes.addCategoryItem}>
|
||||||
|
<IconButton onClick={() => handleOpenModal()} aria-label="add">
|
||||||
|
<AddIcon />
|
||||||
|
</IconButton>
|
||||||
|
</ListItem>
|
||||||
|
</List>
|
||||||
|
</Collapse>
|
||||||
|
<Divider />
|
||||||
|
<Link className={classes.link} to='/trash'>
|
||||||
|
<ListItem selected={history.location.pathname === '/trash'} button>
|
||||||
|
<ListItemIcon>
|
||||||
|
<DeleteIcon />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary={'Корзина'} />
|
||||||
|
</ListItem>
|
||||||
|
</Link>
|
||||||
|
</List>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,25 +1,46 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Todos from '../../components/Todos/Todos'
|
import Todos from '../../components/Todos/Todos'
|
||||||
|
import UpdateCategoryModal from '../../components/Modals/Category/UpdateCategoryModal'
|
||||||
import Fab from '../../components/Fab/Fab'
|
import Fab from '../../components/Fab/Fab'
|
||||||
import { Grid, Typography } from '@material-ui/core'
|
import { Grid, Typography } from '@material-ui/core'
|
||||||
|
|
||||||
import todos from '../../db/todos.json'
|
import todos from '../../db/todos.json'
|
||||||
|
|
||||||
// import { useParams } from 'react-router-dom'
|
import { useParams } from 'react-router-dom'
|
||||||
|
|
||||||
const Category = () => {
|
const Category = () => {
|
||||||
// const { slug } = useParams()
|
const { slug } = useParams()
|
||||||
|
const [isModalOpen, setIsModalOpen] = React.useState(false)
|
||||||
|
const [selectedCategory, setSelectedCategory] = React.useState({
|
||||||
|
id: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleOpenModal = () => {
|
||||||
|
setSelectedCategory({
|
||||||
|
id: slug
|
||||||
|
})
|
||||||
|
setIsModalOpen(true)
|
||||||
|
}
|
||||||
|
const handleCloseModal = () => {
|
||||||
|
setSelectedCategory({
|
||||||
|
id: ''
|
||||||
|
})
|
||||||
|
setIsModalOpen(false)
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={2}>
|
<>
|
||||||
<Fab size='large' ariaLabel='add' typeIcon='edit'/>
|
<UpdateCategoryModal isModalOpen={isModalOpen} handleCloseModal={handleCloseModal} selectedCategory={selectedCategory} setSelectedCategory={setSelectedCategory} />
|
||||||
<Grid item xs={12}>
|
<Fab size='large' ariaLabel='add' typeIcon='edit' handleOpenModal={handleOpenModal} />
|
||||||
<Typography>
|
<Grid container spacing={2}>
|
||||||
Сортируйте свои повседневные дела используя категории.
|
<Grid item xs={12}>
|
||||||
</Typography>
|
<Typography>
|
||||||
|
Сортируйте свои повседневные дела используя категории.
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
{/* Здесь берем значение slug из query и передаем полученные данные в prop data !!!! */}
|
||||||
|
<Todos data={todos} />
|
||||||
</Grid>
|
</Grid>
|
||||||
{/* Здесь берем значение slug из query и передаем полученные данные в prop data !!!! */}
|
</>
|
||||||
<Todos data={todos} />
|
|
||||||
</Grid>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user