fix add plant
This commit is contained in:
1 parent
dedda0157d
commit
f35944752e
11 files changed
+7576
-3004
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import { classNames } from "../utilities/classNames"
|
||||
|
||||
export const Modal = ({children, isOpen, customClose = false, ...props}) => {
|
||||
|
||||
@@ -26,3 +25,5 @@ export const Modal = ({children, isOpen, customClose = false, ...props}) => {
|
||||
export const ModalTitle = ({children, ...props}) => {
|
||||
return <div className="bg-green-700 text-white text-2xl font-bold text-center -mx-2 -mt-2 p-2 rounded-tl rounded-tr" {...props}>{children}</div>
|
||||
}
|
||||
|
||||
export const isCloseModal = e => e.target.classList.contains("overlay") || e.target.classList.contains("close-button")
|
||||
@@ -1,11 +1,14 @@
|
||||
import { Link } from "preact-router/match"
|
||||
import {getPicture} from "../utilities/pictures";
|
||||
import {getPicture} from "../utilities/pictures"
|
||||
import {InputField, TextAreaField} from "./Form"
|
||||
import {Button} from "./Button"
|
||||
import {useState} from "preact/hooks"
|
||||
|
||||
export const PlantThumb = ({ plant, children }) => {
|
||||
|
||||
return <Link href={`/plant/${plant.id}`} class="block h-48">
|
||||
<div className="bg-green-400 relative rounded shadow-lg flex flex-col">
|
||||
<img src={getPicture(plant.id)} alt="" className="object-cover h-48 w-full rounded" />
|
||||
<img src={getPicture(plant.id)} alt="" className="object-cover h-48 w-full min-h-48 min-w-48 rounded" />
|
||||
<div className="bg-green-700 text-white p-2 text-center absolute bottom-0 w-full rounded-bl rounded-br">
|
||||
{children}
|
||||
</div>
|
||||
@@ -15,3 +18,18 @@ export const PlantThumb = ({ plant, children }) => {
|
||||
</div>
|
||||
</Link>
|
||||
}
|
||||
|
||||
export const PlantForm = ({children, plant, ...props}) => {
|
||||
|
||||
const [plantForm, setPlantForm] = useState(plant)
|
||||
|
||||
return <form onSubmit={e => props.onChange(e, plantForm)}>
|
||||
|
||||
<InputField name="name" className="mb-2 mt-5" value={plantForm.name} onChange={(e) => setPlantForm({ ...plantForm, name: e.target.value }) }>Name</InputField>
|
||||
<TextAreaField name="description" className="mb-5" value={plantForm.description} onChange={(e) => setPlantForm({ ...plantForm, description: e.target.value })}>Description</TextAreaField>
|
||||
|
||||
<Button type="submit" className="block w-full mt-5 mb-2 bg-green-800 hover:bg-green-900 text-white mx-auto px-2 py-1 shadow">
|
||||
{ children }
|
||||
</Button>
|
||||
</form>
|
||||
}
|
||||
+13
-10
@@ -24,14 +24,14 @@
|
||||
inkscape:document-units="mm"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:zoom="11.313709"
|
||||
inkscape:cx="14.363106"
|
||||
inkscape:cy="36.769553"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1403"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:zoom="22.627417"
|
||||
inkscape:cx="24.660349"
|
||||
inkscape:cy="24.660349"
|
||||
inkscape:window-width="2121"
|
||||
inkscape:window-height="1263"
|
||||
inkscape:window-x="26"
|
||||
inkscape:window-y="23"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs2" />
|
||||
@@ -40,9 +40,12 @@
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
style="fill:#000000;stroke-width:0.021906"
|
||||
style="fill:#12a307;stroke-width:0.021906;fill-opacity:1"
|
||||
d="M 4.5377718,12.05761 C 4.1994548,11.977511 3.7979842,11.796451 3.5561386,11.614901 3.1840467,11.335577 2.8224522,10.773529 2.5265027,10.014477 2.0810926,8.8720867 2.0050802,8.5977957 1.9995488,8.1129597 c -0.00519,-0.454835 0.070428,-0.506841 0.3076026,-0.211559 0.1874978,0.233432 0.3938129,0.432462 0.6533878,0.630312 0.4131031,0.31487 0.8192714,0.562933 1.1600561,0.708491 0.3064949,0.130912 0.4553781,0.172384 0.6262268,0.174439 0.2332332,0.0028 0.3209911,-0.08682 0.2985938,-0.30496 C 5.0301754,8.9612257 4.9165382,8.6915157 4.832857,8.6051787 4.7450247,8.5145577 4.4279614,8.3503937 4.0120276,8.1801807 3.457158,7.9531127 3.3624242,7.9120117 3.135787,7.8000177 2.5423595,7.5067737 2.3747958,7.3102247 2.3149871,6.8372387 c -0.026127,-0.206636 -0.00465,-0.399669 0.098068,-0.882022 0.091869,-0.431339 0.1199369,-0.60435 0.1201508,-0.740621 9.05e-5,-0.05794 0.00895,-0.09992 0.019679,-0.09329 0.010732,0.0066 0.046431,0.0639 0.079328,0.127252 0.1759542,0.338855 0.4525164,0.688153 0.7697606,0.972204 0.1694411,0.151713 0.8471077,0.716211 1.1097391,0.924416 0.2913464,0.230968 0.647747,0.284372 0.8234172,0.123381 0.072622,-0.06655 0.078129,-0.08068 0.07782,-0.199598 -2.601e-4,-0.09911 -0.01445,-0.153737 -0.062947,-0.242227 C 5.2220848,6.5933247 4.5517686,6.0749577 4.4446724,5.9868917 4.3031575,5.8705227 4.1135989,5.7396547 4.0064932,5.6550587 3.6925515,5.4070947 3.2241173,5.1298297 2.9138425,4.8282537 2.7939107,4.7074767 2.7767518,4.6789097 2.7536717,4.5615967 c -0.014216,-0.07226 -0.026267,-0.232274 -0.026772,-0.355579 -7.998e-4,-0.192839 0.00834,-0.251855 0.065356,-0.422024 0.094918,-0.28331 0.2034415,-0.468575 0.5196945,-0.8323 0.065301,-0.0751 0.1854873,-0.214945 0.2097246,-0.241613 0.01634,-0.01798 0.010087,-0.02085 0.095295,-0.0949 0.026722,-0.02218 0.03478,-0.02172 0.041833,0.0024 0.01492,0.05095 0.049965,0.529834 0.062138,0.619417 0.1046194,0.401061 0.3608987,0.74424 0.5135563,1.086243 0.1993188,0.446539 0.3068308,0.624889 0.5638609,0.924908 0.319498,0.372934 0.6512504,0.510917 0.8319382,0.392063 0.1213654,-0.07983 0.095613,-0.106675 0.1251223,-0.155953 0.012431,-0.02076 0.028557,-0.09033 0.031001,-0.189527 0.0015,-0.06049 -0.05976,-0.165852 -0.096426,-0.243524 -0.037989,-0.0811 -0.1081818,-0.180641 -0.1322387,-0.234851 -0.086343,-0.194566 -0.2636691,-0.383509 -0.3448994,-0.508848 -0.021609,-0.03334 -0.050778,-0.06411 -0.058534,-0.07492 -0.014096,-0.01965 -0.068775,-0.100289 -0.086007,-0.125096 C 5.0368619,4.0622137 4.9786172,3.9932237 4.9445858,3.9490307 4.900339,3.8915707 4.7144987,3.6753437 4.6351163,3.5729557 4.5899248,3.5146647 4.5280112,3.4322207 4.5012811,3.3985377 4.3813398,3.2473977 4.3276392,3.1302207 4.2501973,2.9102987 c -0.053326,-0.153825 -0.056459,-0.54779 4.903e-4,-0.714366 0.1483969,-0.329221 0.3406003,-0.419593 0.4948784,-0.501248 0.043322,-0.02293 0.1357776,-0.07444 0.1760327,-0.09899 0.1034662,-0.06308 0.5294131,-0.325994 0.6348057,-0.4068729 0.161734,-0.124115 0.2185001,-0.17753 0.339923,-0.31985604 0.042662,-0.067776 0.096972,-0.1041355 0.1306182,-0.1600499 0.036704,-0.061001 0.043442,-0.10431 0.057588,-0.1047239 0.051534,0.045701 0.1688432,0.1772628 0.2064802,0.2309609 0.01822,0.026002 0.188378,0.17558094 0.256187,0.28041594 0.06722,0.1064849 0.188285,0.1874599 0.317217,0.2859049 0.09988,0.07626 0.234648,0.141781 0.300794,0.185655 0.134957,0.08952 0.303532,0.122576 0.399149,0.256937 0.10437,0.154873 0.114784,0.396788 0.03906,0.907269 -0.03357,0.160176 -0.02242,0.134442 -0.05383,0.261689 -0.05565,0.225423 -0.171176,0.551783 -0.231084,0.7173 -0.06025,0.166448 -0.101942,0.25034 -0.171672,0.444676 -0.0198,0.0582 -0.03373,0.150478 -0.05014,0.208442 -0.257821,0.90339 -0.2756,0.979413 -0.274512,1.173792 0.0017,0.307581 0.06711,0.364078 0.28698,0.262729 0.129084,-0.0595 0.159493,-0.107353 0.186398,-0.134164 0.03011,-0.03 0.08118,-0.07301 0.108724,-0.108527 0.03809,-0.04912 0.115554,-0.202253 0.179741,-0.345041 0.06634,-0.149085 0.189181,-0.575751 0.206388,-0.627383 0.05127,-0.15384 0.265699,-1.255871 0.404436,-1.760271 0.04343,-0.156628 0.08867,-0.320725 0.100539,-0.364659 0.04365,-0.161613 0.139564,-0.123879 0.345588,0.154577 0.151099,0.204222 0.320683,0.465967 0.463632,0.681689 0.08802,0.132825 0.212762,0.295317 0.277383,0.360979 0.118124,0.120027 0.140644,0.143956 0.118928,0.306526 -0.02671,0.199985 -0.113477,0.338288 -0.158081,0.396351 -0.02744,0.03571 -0.142803,0.158663 -0.17936,0.197589 -0.118153,0.125809 -0.197102,0.19847 -0.359964,0.343554 -0.256774,0.228743 -0.422777,0.471247 -0.634231,0.706812 -0.131832,0.146864 -0.532008,0.586887 -0.783567,1.135324 -0.09071,0.197753 -0.07788,0.386058 -0.01314,0.508532 0.249015,0.471128 0.483972,0.114265 0.690762,-0.159529 0.276104,-0.365275 0.489589,-0.595091 0.787319,-0.916129 0.129205,-0.139321 0.401463,-0.55509 0.556665,-0.814076 0.175409,-0.290543 0.290461,-0.525355 0.377204,-0.769849 0.04815,-0.135703 0.07847,-0.194286 0.09071,-0.175248 0.08163,0.126905 0.2142762,0.579787 0.2810672,0.959604 0.143313,0.814975 0.14304,1.257841 -9.5e-4,1.564Line truncated
|
||||
id="path854"
|
||||
sodipodi:nodetypes="cssssssssssssscssssscssscssssscscssssscsssssssccssscscscssccssccsssscscssssssssssscscscsssscssssssssssssssssccsssssccsssssssssssssssssssssssscssssssssssss" />
|
||||
sodipodi:nodetypes="cssssssssssssscssssscssscssssscscssssscsssssssccssscscscssccssccsssscscssssssssssscscscsssscssssssssssssssssccsssssccsssssssssssssssssssssssscssssssssssss"
|
||||
inkscape:export-filename="/home/romain/Web/Perso/Sites/plantes/src/assets/icons/android-chrome-192x192.png"
|
||||
inkscape:export-xdpi="384"
|
||||
inkscape:export-ydpi="384" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.7 KiB |
+6
-17
@@ -1,19 +1,17 @@
|
||||
import { createPortal } from "preact/compat"
|
||||
import { useContext, useState } from "preact/hooks"
|
||||
import { Button } from "../components/Button"
|
||||
import {Modal, ModalTitle} from "../components/Modals"
|
||||
import {isCloseModal, Modal, ModalTitle} from "../components/Modals"
|
||||
import { PageLayout } from "../components/PageLayout"
|
||||
import { PlantThumb } from "../components/Plants"
|
||||
import {PlantForm, PlantThumb} from "../components/Plants"
|
||||
import { PlantsContext } from "../Contexts"
|
||||
import {InputField, TextAreaField} from "../components/Form"
|
||||
import {Tasks} from "../components/Tasks"
|
||||
|
||||
export const Home = () => {
|
||||
const [addModal, setAddModal] = useState(false)
|
||||
const [plantForm, setPlantForm] = useState({})
|
||||
const { plants, addPlant } = useContext(PlantsContext)
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
const handleSubmit = (e, plantForm) => {
|
||||
console.log(e)
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
addPlant(plantForm)
|
||||
@@ -21,8 +19,7 @@ export const Home = () => {
|
||||
}
|
||||
|
||||
const handleCloseAddModal = (e) => {
|
||||
if (e.target.classList.contains("overlay") ||
|
||||
e.target.classList.contains("close-button")) {
|
||||
if (isCloseModal(e)) {
|
||||
setAddModal(false)
|
||||
}
|
||||
}
|
||||
@@ -50,15 +47,7 @@ export const Home = () => {
|
||||
<ModalTitle>
|
||||
Add Plant
|
||||
</ModalTitle>
|
||||
<form onSubmit={handleSubmit}>
|
||||
|
||||
<InputField name="name" className="mb-2 mt-5" onChange={(e) => setPlantForm({ ...plantForm, name: e.target.value }) }>Name</InputField>
|
||||
<TextAreaField name="description" className="mb-5" onChange={(e) => setPlantForm({ ...plantForm, description: e.target.value })}>Description</TextAreaField>
|
||||
|
||||
<Button type="submit" className="block w-full mt-5 mb-2 bg-green-800 hover:bg-green-900 text-white mx-auto px-2 py-1 shadow">
|
||||
Add
|
||||
</Button>
|
||||
</form>
|
||||
<PlantForm plant={{}} onChange={handleSubmit}>Add</PlantForm>
|
||||
</Modal>,
|
||||
document.getElementById('app')
|
||||
)}
|
||||
|
||||
+33
-26
@@ -1,19 +1,20 @@
|
||||
import {createPortal, useRef} from "preact/compat"
|
||||
import { useContext, useEffect, useState } from "preact/hooks"
|
||||
import {Button, SmallButton} from "../components/Button"
|
||||
import {Modal, ModalTitle} from "../components/Modals"
|
||||
import {isCloseModal, Modal, ModalTitle} from "../components/Modals"
|
||||
import { PageLayout } from "../components/PageLayout"
|
||||
import { PlantsContext } from "../Contexts"
|
||||
import {InputField, SelectField, TextAreaField} from "../components/Form"
|
||||
import {InputField, SelectField} from "../components/Form"
|
||||
import {getPicture, storePicture} from "../utilities/pictures"
|
||||
import {EditSVG, PlusSVG} from "../components/SVG";
|
||||
import {classNames} from "../utilities/classNames";
|
||||
import {EditSVG, PlusSVG} from "../components/SVG"
|
||||
import {classNames} from "../utilities/classNames"
|
||||
import {PlantForm} from "../components/Plants"
|
||||
|
||||
const Plant = ({id}) => {
|
||||
|
||||
const [addModal, setAddModal] = useState(false)
|
||||
const [editModal, setEditModal] = useState(false)
|
||||
const [plantForm, setPlantForm] = useState({})
|
||||
const [deleteModal, setDeleteModal] = useState(false)
|
||||
const {plants, editPlant, removePlant, addAction, doneTask, history} = useContext(PlantsContext)
|
||||
const [plant, setPlant] = useState({})
|
||||
const [actionForm, setActionForm] = useState({})
|
||||
@@ -42,7 +43,7 @@ const Plant = ({id}) => {
|
||||
setAddModal(false)
|
||||
}
|
||||
|
||||
const handleEditSubmit = (e) => {
|
||||
const handleEditSubmit = (e, plantForm) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
editPlant(plantForm)
|
||||
@@ -50,18 +51,10 @@ const Plant = ({id}) => {
|
||||
setPlant(plantForm)
|
||||
}
|
||||
|
||||
const isCloseModal = e => e.target.classList.contains("overlay") || e.target.classList.contains("close-button")
|
||||
|
||||
const handleCloseAddModal = (e) => {
|
||||
if (isCloseModal(e)) {
|
||||
setAddModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleOpenEditModal = () => {
|
||||
setEditModal(true)
|
||||
console.log(plant)
|
||||
setPlantForm(plant)
|
||||
}
|
||||
|
||||
const handleCloseEditModal = (e) => {
|
||||
@@ -70,19 +63,29 @@ const Plant = ({id}) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleCloseDeleteModal = (e) => {
|
||||
if (isCloseModal(e)) {
|
||||
setDeleteModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDeletePlant = () => removePlant(plant)
|
||||
|
||||
const handleOpenEditModal = () => setEditModal(true)
|
||||
|
||||
const addPicture = e => storePicture(e, id)
|
||||
|
||||
return <PageLayout>
|
||||
<div className="flex justify-between items-center">
|
||||
<h1 className="my-2 flex-1 text-center">{ plant.name }</h1>
|
||||
<div>
|
||||
<Button className="bg-blue-500" onClick={() => handleOpenEditModal()}>Edit</Button>
|
||||
{/*<Button className="bg-red-500" onClick={() => removePlant(plant)}>Delete</Button>*/}
|
||||
<Button className="bg-blue-500 hover:bg-blue-700" onClick={() => handleOpenEditModal()}>Edit</Button>
|
||||
<Button className="bg-red-500 hover:bg-red-700" onClick={() => setDeleteModal(true)}>Delete</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-around flex-wrap gap-5">
|
||||
<div className="relative">
|
||||
<img id="picture" ref={picture} src={getPicture(id)} alt=""/>
|
||||
<img id="picture" ref={picture} src={getPicture(id)} alt="" className="inline-block min-w-[300px] min-h-[200px] bg-gray-400"/>
|
||||
<SmallButton className="absolute top-2 left-2 cursor-pointer bg-blue-500 hover:bg-blue-700 max-w-[300px]">
|
||||
<label className="relative">
|
||||
<EditSVG className="w-4 h-4 block z-10 cursor-pointer" />
|
||||
@@ -90,7 +93,9 @@ const Plant = ({id}) => {
|
||||
</label>
|
||||
</SmallButton>
|
||||
</div>
|
||||
<p className="flex-1">{ plant.description }</p>
|
||||
<div className="flex-1">
|
||||
<p>{ plant.description }</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -138,15 +143,17 @@ const Plant = ({id}) => {
|
||||
<ModalTitle>
|
||||
Edit Plant
|
||||
</ModalTitle>
|
||||
<form onSubmit={handleEditSubmit}>
|
||||
<PlantForm plant={plant} onChange={handleEditSubmit}>Add</PlantForm>
|
||||
</Modal>,
|
||||
app
|
||||
)}
|
||||
|
||||
<InputField name="name" className="mb-2 mt-5" value={plantForm.name} onChange={(e) => setPlantForm({ ...plantForm, name: e.target.value }) }>Name</InputField>
|
||||
<TextAreaField name="description" className="mb-5" value={plantForm.description} onChange={(e) => setPlantForm({ ...plantForm, description: e.target.value })}>Description</TextAreaField>
|
||||
|
||||
<Button type="submit" className="block w-full mt-5 mb-2 bg-green-800 hover:bg-green-900 text-white mx-auto px-2 py-1 shadow">
|
||||
Edit
|
||||
</Button>
|
||||
</form>
|
||||
{createPortal(
|
||||
<Modal isOpen={deleteModal} onChange={handleCloseDeleteModal}>
|
||||
<ModalTitle>
|
||||
Delete Plant ?
|
||||
</ModalTitle>
|
||||
<Button className="bg-red-500 hover:bg-red-700 mt-10" onClick={handleDeletePlant}>Confirm delete plant</Button>
|
||||
</Modal>,
|
||||
app
|
||||
)}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { setupRouting } from 'preact-cli/sw'
|
||||
import { getFiles, setupPrecaching, setupRouting } from 'preact-cli/sw/'
|
||||
|
||||
setupRouting()
|
||||
setupPrecaching(getFiles())
|
||||
@@ -4,7 +4,7 @@ const pictureName = id => {
|
||||
}
|
||||
|
||||
export const getPicture = id => {
|
||||
return localStorage.getItem('picture-' + id ?? '')
|
||||
return localStorage.getItem('picture-' + id ?? '') ?? ""
|
||||
}
|
||||
|
||||
export const storePicture = (e, id) => {
|
||||
|
||||
Reference in new issue
Block a user