Skip to content

Commit ed02ba6

Browse files
committed
refolder & some fixes
1 parent 924f197 commit ed02ba6

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

src/App.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import CardList from './Cards/CardList'
55
import AddCard from './Cards/AddCard'
66
import Context from './context'
77
import Loader from './Content/Loader'
8-
import ModalCardEdit from './Modal/ModalCardEdit'
9-
import ModalLogin from './Modal/ModalLogin'
10-
import DataService from './DataService'
8+
import ModalCardEdit from './Cards/ModalCardEdit'
9+
import ModalLogin from './Login/ModalLogin'
10+
import DataService from './Services/DataService'
1111

1212
const { loadData, postData, setDataServLogin } = DataService()
1313
const testText = "Notes App"
1414

1515
var cardCount = 0
16+
1617
function calcCount(cards) {
1718
let id = cardCount;
1819
[...cards].forEach(element => {
@@ -53,22 +54,28 @@ function checkCardFields(card) {
5354
return res
5455
}
5556

56-
var timer
57+
function useUpdater() {
58+
const [updaterVal, setUpdaterVal] = React.useState(null)
59+
const timer = React.useRef()
60+
if (timer.current) clearTimeout(timer.current)
61+
timer.current = setTimeout(() => setUpdaterVal(Date.now()), 60 * 1000) // обновяем через минуту
62+
return [updaterVal]
63+
}
5764

5865
function App() {
5966
const [cardsArr, setCards] = useCardsArr([])
6067
const [editCardId, setEditCardId] = React.useState(null)
6168
const [loading, setLoading] = React.useState(false)
69+
70+
const [openLogin, setOpenLogin] = React.useState(false)
6271
const [logged, setLogged] = React.useState(false)
6372
const [userName, setUserName] = React.useState(undefined)
6473

65-
const [timerVal, setTimerVal] = React.useState(null)
66-
if (timer) clearInterval(timer)
67-
timer = setInterval(() => setTimerVal(Date.now()), 60 * 1000) // обновяем через минуту
74+
const [updaterVal] = useUpdater()
75+
6876
React.useEffect(onLogout, [logged, userName])// eslint-disable-line react-hooks/exhaustive-deps
69-
React.useEffect(loadDataFromServer, [logged, userName, timerVal]) // eslint-disable-line react-hooks/exhaustive-deps
77+
React.useEffect(loadDataFromServer, [logged, userName, updaterVal]) // eslint-disable-line react-hooks/exhaustive-deps
7078
React.useEffect(loadDataToServer, [cardsArr]) // eslint-disable-line react-hooks/exhaustive-deps
71-
const [openLogin, setOpenLogin] = React.useState(false)
7279

7380
///////////
7481
function tryLogin(login) {
@@ -85,7 +92,7 @@ function App() {
8592
)
8693
.catch(
8794
e => {
88-
console.log("setDataServLogin in Try login", "catch", e);
95+
console.log("setDataServLogin catch in Try login", e)
8996
rej(e)
9097
}
9198
)

src/Cards/CardItem.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,35 @@ function createHTML(text) {
1010

1111
function CardItem(props) {
1212
const { removeCard, changeCardState, setEditCard } = useContext(Context)
13+
const { card, index } = props
1314
const lineClip = 12
15+
const [color, btcolor] = card && card.completed ? ["green", "success"] : ["red", "danger"]
1416
return (
1517

1618
<div className="p-1" >
17-
<div className="card" style={{ color: "white", backgroundColor: props.card.completed ? "green" : "red" }} >
19+
<div className="card" style={{ color: "white", backgroundColor: color }} >
1820

19-
<div className="card-body" onClick={() => setEditCard(props.index)} >
20-
<h5 className="card-title">Id: {props.card.id}</h5>
21+
<div className="card-body" onClick={() => setEditCard(index)} >
22+
<h5 className="card-title">Id: {card.id}</h5>
2123
<p
2224
className="card-text"
2325
style={{ overflow: "hidden", display: "-webkit-box", WebkitLineClamp: String(lineClip), WebkitBoxOrient: "vertical" }}
24-
dangerouslySetInnerHTML={createHTML(props.card.text)}
26+
dangerouslySetInnerHTML={createHTML(card.text)}
2527
/>
2628
</div>
2729

2830
<div className="card-body pt-0">
2931
<button
30-
className={`btn btn-${props.card.completed ? "success" : "danger"} p-0`}
32+
className={`btn btn-${btcolor} p-0`}
3133
style={{ width: "1.8em", height: "1.8em", float: "right", borderColor: "transparent", backgroundColor: "transparent" }}
32-
onClick={() => removeCard(props.index)}
34+
onClick={() => removeCard(index)}
3335
>
3436
&#10007;
3537
</button>
3638
<button
37-
className={`btn btn-${props.card.completed ? "success" : "danger"} p-0 mx-2`}
39+
className={`btn btn-${btcolor} p-0 mx-2`}
3840
style={{ width: "1.8em", height: "1.8em", float: "right", borderColor: "transparent", backgroundColor: "transparent" }}
39-
onClick={() => changeCardState(props.index)}
41+
onClick={() => changeCardState(index)}
4042
>
4143
&#10003;
4244
</button>

src/Modal/ModalCardEdit.js renamed to src/Cards/ModalCardEdit.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import PropTypes from 'prop-types'
33
import Context from '../context'
44
import TextareaAutosize from 'react-textarea-autosize'
5-
import Modal, { ModalProps } from "./Modal"
5+
import Modal, { ModalProps } from "../Modal/Modal"
66

77
function calcMaxRows() {
88
const small = 576
@@ -62,6 +62,9 @@ function ModalCardEdit(props) {
6262
close()
6363
}
6464

65+
// eslint-disable-next-line no-unused-vars
66+
const [color, btcolor] = card&&card.completed ? ["green", "success"] : ["red", "danger"]
67+
6568
return (
6669
<Modal {...modalProps.bind()}>
6770
<div className="container p-2">
@@ -72,7 +75,7 @@ function ModalCardEdit(props) {
7275
<h1 className="mb-2">Id: {card.id}</h1>
7376
<h5 className="mb-2">Completed:
7477
<span
75-
className={`px-2 py-1 m-1 d-inline-block text-center badge ${card.completed ? "badge-success" : "badge-danger"}`}
78+
className={`px-2 py-1 m-1 d-inline-block text-center badge bage-${btcolor}`}
7679
style={{ width: "3em" }}
7780
>
7881
{String(card.completed)}

src/Modal/ModalLogin.js renamed to src/Login/ModalLogin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react"
2-
import Modal, { ModalProps } from "./Modal"
2+
import Modal, { ModalProps } from "../Modal/Modal"
33
import PropTypes from 'prop-types'
44

55
function checkUsername(str) {
File renamed without changes.

0 commit comments

Comments
 (0)