mirror of
https://github.com/FranP-code/noti.io.git
synced 2025-10-13 00:14:03 +00:00
Modularizated even more the application
This commit is contained in:
@@ -4,6 +4,7 @@ import Header from './components/Header'
|
|||||||
import TaskList from "./components/TaskList";
|
import TaskList from "./components/TaskList";
|
||||||
import AddTask from "./components/AddTask";
|
import AddTask from "./components/AddTask";
|
||||||
import Footer from "./components/Footer";
|
import Footer from "./components/Footer";
|
||||||
|
import { checkCache } from "./components/cacheFunctions";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
|
||||||
@@ -23,7 +24,10 @@ function App() {
|
|||||||
|
|
||||||
const [formEditInput, setFormEditInput] = useState('')
|
const [formEditInput, setFormEditInput] = useState('')
|
||||||
|
|
||||||
|
window.onload = () => {
|
||||||
|
checkCache()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Header />
|
<Header />
|
||||||
@@ -60,6 +64,8 @@ function App() {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
|
||||||
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
|
|
||||||
const AddList = () => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default AddList
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, {useState} from 'react'
|
import React, {useState} from 'react'
|
||||||
|
import {persistTasks, persistCounter} from './cacheFunctions'
|
||||||
|
|
||||||
const AddTask = (props) => {
|
const AddTask = (props) => {
|
||||||
|
|
||||||
@@ -30,52 +31,12 @@ const AddTask = (props) => {
|
|||||||
text: props.text,
|
text: props.text,
|
||||||
id: props.counterInputs
|
id: props.counterInputs
|
||||||
}
|
}
|
||||||
])
|
], props)
|
||||||
|
|
||||||
persistCounter()
|
persistCounter(props)
|
||||||
//props.setText('')
|
//props.setText('')
|
||||||
}
|
}
|
||||||
|
|
||||||
const persistTasks = (modificatedTasks) => {
|
|
||||||
localStorage.setItem('tasks', JSON.stringify(modificatedTasks))
|
|
||||||
}
|
|
||||||
|
|
||||||
const persistCounter = () => {
|
|
||||||
localStorage.setItem('counter', JSON.stringify(props.counterInputs))
|
|
||||||
}
|
|
||||||
|
|
||||||
const restoreTasks = () => {
|
|
||||||
let tasksCache = localStorage.getItem('tasks')
|
|
||||||
|
|
||||||
tasksCache = JSON.parse(tasksCache)
|
|
||||||
|
|
||||||
props.setTasks(tasksCache)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const restoreCounter = () => {
|
|
||||||
let counterInputCache = localStorage.getItem('counter')
|
|
||||||
|
|
||||||
counterInputCache = JSON.parse(counterInputCache)
|
|
||||||
|
|
||||||
props.setCounterInputs(counterInputCache + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkCache = () => {
|
|
||||||
if (localStorage.getItem('tasks')) {
|
|
||||||
restoreTasks()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localStorage.getItem('counter')) {
|
|
||||||
restoreCounter()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
window.onload = () => {
|
|
||||||
checkCache()
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="add-task">
|
<div className="add-task">
|
||||||
|
|||||||
39
src/components/cacheFunctions.js
Normal file
39
src/components/cacheFunctions.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
const persistTasks = (modificatedTasks, props) => {
|
||||||
|
localStorage.setItem('tasks', JSON.stringify(modificatedTasks))
|
||||||
|
}
|
||||||
|
|
||||||
|
const persistCounter = (props) => {
|
||||||
|
localStorage.setItem('counter', JSON.stringify(props.counterInputs))
|
||||||
|
}
|
||||||
|
|
||||||
|
const restoreTasks = (props) => {
|
||||||
|
let tasksCache = localStorage.getItem('tasks')
|
||||||
|
|
||||||
|
tasksCache = JSON.parse(tasksCache)
|
||||||
|
|
||||||
|
props.setTasks(tasksCache)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const restoreCounter = (props) => {
|
||||||
|
let counterInputCache = localStorage.getItem('counter')
|
||||||
|
|
||||||
|
if (counterInputCache) {
|
||||||
|
counterInputCache = JSON.parse(counterInputCache)
|
||||||
|
}
|
||||||
|
|
||||||
|
props.setCounterInputs(counterInputCache + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkCache = () => {
|
||||||
|
if (localStorage.getItem('tasks')) {
|
||||||
|
restoreTasks()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localStorage.getItem('counter')) {
|
||||||
|
restoreCounter()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
export {persistTasks, persistCounter, checkCache}
|
||||||
Reference in New Issue
Block a user