@@ -5,14 +5,15 @@ import CardList from './Cards/CardList'
55import AddCard from './Cards/AddCard'
66import Context from './context'
77import 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
1212const { loadData, postData, setDataServLogin } = DataService ( )
1313const testText = "Notes App"
1414
1515var cardCount = 0
16+
1617function 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
5865function 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 )
0 commit comments