some change
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,6 @@
|
|||||||
node_modules
|
node_modules
|
||||||
/build
|
/build
|
||||||
/*.log
|
/*.log
|
||||||
/.idea
|
/.idea
|
||||||
|
|
||||||
|
deploy.sh
|
||||||
1
size-plugin.json
Normal file
1
size-plugin.json
Normal file
File diff suppressed because one or more lines are too long
@@ -1,22 +1,16 @@
|
|||||||
import { createContext } from "preact";
|
import { createContext } from "preact";
|
||||||
import { useEffect, useState } from "preact/hooks";
|
|
||||||
import usePlants from "./hooks/PlantsHook";
|
import usePlants from "./hooks/PlantsHook";
|
||||||
import { useLocalStorage } from "./hooks/LocalStorageHook"
|
import { useLocalStorage } from "./hooks/LocalStorageHook"
|
||||||
import useUser from "./hooks/UserHook";
|
import useUser from "./hooks/UserHook";
|
||||||
|
|
||||||
export const UserContext = createContext()
|
export const UserContext = createContext(null)
|
||||||
export const PlantsContext = createContext()
|
export const PlantsContext = createContext(null)
|
||||||
|
|
||||||
export default function ContextsProviders({children}) {
|
export default function ContextsProviders({children}) {
|
||||||
|
|
||||||
const [data, setData] = useLocalStorage('data', {})
|
const [data, setData] = useLocalStorage('data', {})
|
||||||
const [user, setUser] = useUser(data, setData)
|
const [user, setUser] = useUser(data, setData)
|
||||||
const {plants, addPlant, editPlant, removePlant, addAction, doneTask, history} = usePlants(data, setData)
|
const {plants, addPlant, editPlant, removePlant, addAction, doneTask, history} = usePlants(data, setData)
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
|
|
||||||
console.log('first', user);
|
|
||||||
}, [user])
|
|
||||||
|
|
||||||
return <UserContext.Provider value={[user, setUser]}>
|
return <UserContext.Provider value={[user, setUser]}>
|
||||||
<PlantsContext.Provider value={{plants, addPlant, editPlant, removePlant, addAction, doneTask, history}}>
|
<PlantsContext.Provider value={{plants, addPlant, editPlant, removePlant, addAction, doneTask, history}}>
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import {useEffect} from "preact/hooks";
|
|||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
|
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
if (!Notification) {
|
// if (!Notification) {
|
||||||
alert('Le navigateur ne supporte pas les notifications.');
|
// alert('Le navigateur ne supporte pas les notifications.');
|
||||||
} else if (Notification.permission !== 'granted') {
|
// } else if (Notification.permission !== 'granted') {
|
||||||
Notification.requestPermission();
|
// Notification.requestPermission();
|
||||||
}
|
// }
|
||||||
}, [])
|
// }, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="app" class="h-screen overflow-auto flex flex-col">
|
<div id="app" class="h-screen overflow-auto flex flex-col">
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import {route} from "preact-router";
|
|||||||
|
|
||||||
const usePlants = (data, setData) => {
|
const usePlants = (data, setData) => {
|
||||||
const [plants, setPlants] = useState([])
|
const [plants, setPlants] = useState([])
|
||||||
const [tasks, setTasks] = useState([])
|
|
||||||
|
|
||||||
useEffect(() =>{
|
useEffect(() =>{
|
||||||
setPlants(data.plants ?? [])
|
setPlants(data.plants ?? [])
|
||||||
@@ -32,9 +31,7 @@ const usePlants = (data, setData) => {
|
|||||||
|
|
||||||
const addAction = (plant, action) => {
|
const addAction = (plant, action) => {
|
||||||
action.id = action.action_type + '-' + plant.id
|
action.id = action.action_type + '-' + plant.id
|
||||||
let plantIndex = plants.findIndex(item => item.id === plant.id)
|
|
||||||
let actionIndex = plant.actions.findIndex(item => item.action_type === action.action_type)
|
let actionIndex = plant.actions.findIndex(item => item.action_type === action.action_type)
|
||||||
console.log(actionIndex, plantIndex, plant, plants, action)
|
|
||||||
actionIndex >= 0 ? plant.actions[actionIndex] = action
|
actionIndex >= 0 ? plant.actions[actionIndex] = action
|
||||||
: plant.actions.push(action)
|
: plant.actions.push(action)
|
||||||
editPlant(plant)
|
editPlant(plant)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const useUser = (data, setData) => {
|
|||||||
|
|
||||||
useEffect(() =>{
|
useEffect(() =>{
|
||||||
setData({...data, user: user})
|
setData({...data, user: user})
|
||||||
console.log('in', user);
|
|
||||||
document.querySelector('html').classList.toggle('dark', user.dark_mode)
|
document.querySelector('html').classList.toggle('dark', user.dark_mode)
|
||||||
}, [user])
|
}, [user])
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,11 @@ import {Tasks} from "../components/Tasks"
|
|||||||
export const Home = () => {
|
export const Home = () => {
|
||||||
const [addModal, setAddModal] = useState(false)
|
const [addModal, setAddModal] = useState(false)
|
||||||
const [plantForm, setPlantForm] = useState({})
|
const [plantForm, setPlantForm] = useState({})
|
||||||
const app = document.getElementById("app")
|
|
||||||
const { plants, addPlant } = useContext(PlantsContext)
|
const { plants, addPlant } = useContext(PlantsContext)
|
||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
console.log(plantForm)
|
|
||||||
addPlant(plantForm)
|
addPlant(plantForm)
|
||||||
setAddModal(false)
|
setAddModal(false)
|
||||||
}
|
}
|
||||||
@@ -47,7 +45,7 @@ export const Home = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{createPortal(
|
{typeof window !== "undefined" && createPortal(
|
||||||
<Modal isOpen={addModal} onChange={handleCloseAddModal}>
|
<Modal isOpen={addModal} onChange={handleCloseAddModal}>
|
||||||
<ModalTitle>
|
<ModalTitle>
|
||||||
Add Plant
|
Add Plant
|
||||||
@@ -62,7 +60,7 @@ export const Home = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Modal>,
|
</Modal>,
|
||||||
app
|
document.getElementById('app')
|
||||||
)}
|
)}
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ const Plant = ({id}) => {
|
|||||||
if (!actionForm.action_type) {
|
if (!actionForm.action_type) {
|
||||||
actionForm.action_type = action_types[0]
|
actionForm.action_type = action_types[0]
|
||||||
}
|
}
|
||||||
console.log("my event", e, actionForm)
|
|
||||||
addAction(plant, actionForm)
|
addAction(plant, actionForm)
|
||||||
setAddModal(false)
|
setAddModal(false)
|
||||||
}
|
}
|
||||||
|
|||||||
56
src/sw.js
56
src/sw.js
@@ -1,55 +1,3 @@
|
|||||||
import { getFiles, setupPrecaching, setupRouting } from 'preact-cli/sw/';
|
import { setupRouting } from 'preact-cli/sw'
|
||||||
|
|
||||||
setupRouting();
|
setupRouting()
|
||||||
setupPrecaching(getFiles());
|
|
||||||
|
|
||||||
function wait(ms) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
setTimeout(resolve, ms);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const BASE = location.protocol + '//' + location.host
|
|
||||||
const PREFIX = "V1"
|
|
||||||
const CACHED_FILES = [
|
|
||||||
`${BASE}/sw.js`,
|
|
||||||
`${BASE}/js/app.js`,
|
|
||||||
`${BASE}/css/app.css`,
|
|
||||||
`${BASE}/offline.html`,
|
|
||||||
]
|
|
||||||
|
|
||||||
self.addEventListener('install', (event) => {
|
|
||||||
self.skipWaiting()
|
|
||||||
event.waitUntil(
|
|
||||||
(async () => {
|
|
||||||
const cache = await caches.open(PREFIX)
|
|
||||||
await cache.addAll(CACHED_FILES)
|
|
||||||
})()
|
|
||||||
)
|
|
||||||
console.log(`${PREFIX} Install`)
|
|
||||||
})
|
|
||||||
|
|
||||||
self.addEventListener('activate', (event) => {
|
|
||||||
clients.claim()
|
|
||||||
event.waitUntil((async() => {
|
|
||||||
const keys = await caches.keys()
|
|
||||||
await Promise.all(
|
|
||||||
keys.map(key => {
|
|
||||||
if (!key.includes(PREFIX)) {
|
|
||||||
return caches.delete(key)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})())
|
|
||||||
console.log(`${PREFIX} Activate`)
|
|
||||||
})
|
|
||||||
|
|
||||||
const delay = 1000 * 60 * 60 * 24
|
|
||||||
|
|
||||||
console.log(localStorage.getItem('data'))
|
|
||||||
|
|
||||||
wait(delay)
|
|
||||||
.then(() => {
|
|
||||||
// do thing
|
|
||||||
|
|
||||||
}).catch(err => console.log(err))
|
|
||||||
|
|||||||
@@ -11,5 +11,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<% preact.bodyEnd %>
|
<% preact.bodyEnd %>
|
||||||
|
<script src="sw.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user