Skip to content

Commit 40e8971

Browse files
committed
fixed 10.06.2019
1 parent fdecc36 commit 40e8971

File tree

14 files changed

+99
-116
lines changed

14 files changed

+99
-116
lines changed

src/App.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import { Container } from 'react-bootstrap';
33
import { Route, HashRouter as Router } from 'react-router-dom';
44
import { FORM_ADD, FORM_EDIT } from './lib/const';
5-
import './css/micalendar.css';
65

76
import Navigation from './components/navigation';
87
import { NAV_ITEMS, NAV_MAIN } from './lib/nav_data';
@@ -22,15 +21,32 @@ export default class App extends React.Component {
2221
}
2322

2423
componentDidMount() {
25-
let taskList = [];
24+
let taskList = null;
2625
try {
2726
taskList = JSON.parse(localStorage.getItem('TASKS'));
2827
} catch {
2928
console.log('Error localstorage upload data');
3029
}
31-
this.setState({ taskList });
30+
this.setState({ taskList: taskList !== null ? taskList : [] })
3231
}
3332

33+
handleSaveFormData = data => {
34+
const { taskList } = this.state;
35+
if (this.state.formSate === FORM_ADD) {
36+
taskList.push(data);
37+
} else {
38+
taskList.filter(item => this.state.taskId === item.id)[0] = { ...data };
39+
}
40+
this.setState({
41+
taskList,
42+
taskId: null,
43+
taskForEdit: null,
44+
formSate: FORM_ADD
45+
});
46+
localStorage.setItem('TASKS', JSON.stringify(taskList));
47+
return true;
48+
};
49+
3450
handleEditTask = (e, taskId) => {
3551
const { taskList } = this.state;
3652
const taskForEdit = taskList.filter(item => item.id === taskId)[0];
@@ -41,6 +57,7 @@ export default class App extends React.Component {
4157
};
4258

4359
handleDeleteTask = (e, taskId) => {
60+
4461
console.log('this is DELETE from App, id = ', taskId);
4562
};
4663

@@ -74,6 +91,7 @@ export default class App extends React.Component {
7491
onTaskDelete={this.handleDeleteTask}
7592
taskForEdit={this.state.taskForEdit}
7693
formSate={this.state.formSate}
94+
onSaveData={ this.handleSaveFormData }
7795
/>
7896
) : (
7997
<Dnd />

src/api/localstorage.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/api/newid.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/components/form/textarea.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const TextArea = props => {
1111
if (cols !== null) {
1212
colsRows.cols = cols;
1313
}
14-
console.log("textarea", props)
14+
1515
return (
1616
<div className="form-group">
1717
<label htmlFor={name} className={err ? 'text-danger' : null}>

src/components/main_form/index.jsx

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,26 @@ export default class MainForm extends React.Component {
1010
static propTypes = {
1111
formSate: PropTypes.string, // состояние формы (редактровать или добавить таску)
1212
taskForEdit: PropTypes.object, // номер таски, которую редактируют
13+
onSaveData: PropTypes.func
1314
};
1415

15-
1616
constructor(props) {
1717
super(props);
1818
this.state = {
1919
data: {
20-
taskid: null,
21-
taskName: '',
22-
taskDesciption: '',
23-
taskDate: null,
24-
taskUrgent: false,
25-
taskStatus: 'todo',
20+
// taskId: null,
21+
// taskName: '',
22+
// taskDescription: '',
23+
// taskDate: null,
24+
// taskUrgent: false,
25+
// taskStatus: 'todo',
2626
},
2727
err: {},
2828
propsFlag: false
2929
}
30-
this.initialState = { ...this.state };
3130
}
3231

3332
static getDerivedStateFromProps = (nextProps, state) => {
34-
3533
console.log("getDerivedStateFromProps ", nextProps.taskForEdit)
3634
console.log("getDerivedStateFromProps if=", (!state.propsFlag), !!nextProps.taskForEdit)
3735
if (!state.propsFlag && nextProps.taskForEdit) {
@@ -57,24 +55,32 @@ export default class MainForm extends React.Component {
5755
}
5856

5957
handleClearForm = () => {
60-
this.setState({ ...this.initialState });
58+
this.setState({ data: {} });
6159
}
6260

63-
handleAddTask = (e) => {
64-
e.preventDefault();
61+
handleResetData = () => {
62+
this.handleClearForm();
63+
}
6564

65+
handleSaveData = (e) => {
66+
e.preventDefault();
67+
if (this.props.onSaveData({ ...this.state.data, id: new Date().valueOf() }) === true) {
68+
this.setState({ data: {} });
69+
}
6670
}
6771

6872
render() {
69-
console.log("main RNR", this.props.taskForEdit)
73+
// console.log("main RNR", this.props.taskForEdit)
74+
console.log('props', this.props);
7075
return (
7176
<Card>
7277
<h4>
73-
{
74-
this.props.formSate === FORM_ADD
75-
? "Add new task"
76-
: `Edit task ${ this.props.taskId || "" }`
77-
}</h4>
78+
{
79+
this.props.formSate === FORM_ADD
80+
? "Add new task"
81+
: `Edit task ${this.props.taskId || ""}`
82+
}
83+
</h4>
7884

7985
<TextInput
8086
value={this.state.data.taskName || ''}
@@ -88,7 +94,7 @@ export default class MainForm extends React.Component {
8894

8995
<TextArea
9096
value={this.state.data.taskDescription || ''}
91-
name='taskDesciption'
97+
name='taskDescription'
9298
onChange={this.handleChange}
9399
label='Task description'
94100
helper={'Введите описание вашей задачи'}
@@ -133,23 +139,28 @@ export default class MainForm extends React.Component {
133139
/>
134140

135141
<div className="row">
136-
<div className="col-sm-6">
142+
<div className='col-sm-6'>
137143
<button
138144
type="submit"
139-
className="btn btn-primary"
140-
onClick={this.handleAddTask}
145+
className={`btn ${this.props.formSate === FORM_ADD ? 'btn-primary' : 'btn-warning'}`}
146+
onClick={this.handleSaveData}
141147
>
142-
Add new task
143-
</button>
148+
{
149+
this.props.formSate === FORM_ADD ? "Add new task" : "Save changes"
150+
}
151+
</button>
144152
</div>
145-
<div className="col-sm-6">
153+
<div className='col-sm-6'>
146154
<button
147155
type="submit"
148156
className="btn btn-secondary"
149-
onClick={this.handleClearForm}
157+
onClick={this.handleResetData}
150158
>
151-
Clear form
152-
</button>
159+
160+
{
161+
this.props.formSate === FORM_ADD ? "Clear form" : "Cancel"
162+
}
163+
</button>
153164
</div>
154165
</div>
155166
</Card>

src/components/main_list/index.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default class MainList extends React.Component {
1515
}
1616
}
1717

18-
1918
static propTypes = {
2019
data: PropTypes.array, // список задач длдя рендера
2120
onTaskEdit: PropTypes.func,
@@ -106,7 +105,7 @@ export default class MainList extends React.Component {
106105
? this.props.data.map(this.renderOneTask)
107106
: emptyList;
108107

109-
const filterElement = (id) => {
108+
const filterElement = () => {
110109
return this.props.data ? this.props.data.filter(item => item.id === this.state.taskId)[0] : null;
111110
}
112111

@@ -118,7 +117,6 @@ export default class MainList extends React.Component {
118117
list
119118
}
120119
</ul>
121-
122120
{
123121
this.props.children // компоненты "дети", которые были переданы внутрь <MainList>....</MainList>
124122
}

src/components/main_list/task.jsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/css/index.css

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import 'bootstrap/dist/css/bootstrap.min.css';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
44

5-
import './css/index.css';
6-
import './css/micalendar.css';
5+
import './micalendar.css';
76
import App from './App';
87
import * as serviceWorker from './serviceWorker';
98

src/css/micalendar.css renamed to src/micalendar.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
4+
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
5+
-webkit-font-smoothing: antialiased;
6+
-moz-osx-font-smoothing: grayscale;
7+
}
8+
9+
code {
10+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
11+
}
12+
113
.micalendar {
214
font-family: 'Open Sans Condensed', sans-serif;
315
background-color: #fff;

0 commit comments

Comments
 (0)