Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
2630 stevensc 1
import React, { createContext, useState } from 'react'
2
 
3
export const GoalsContext = createContext()
4
 
5
export default function GoalsProvider({ children }) {
6
  const [goals, setGoals] = useState([
7
    {
8
      id: 1,
9
      title: 'Lograr un ascenso',
10
      description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
11
      value: 10,
12
      finishDate: Date.now(),
13
      habits: [
14
        { value: Date.now(), name: 'Levantarse temprano' },
15
        { value: Date.now(), name: 'Estudiar' },
16
        { value: Date.now(), name: 'Meditar' }
17
      ]
18
    },
19
    {
20
      id: 2,
21
      title: 'Mejorar mi fisico',
22
      description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
23
      value: 10,
24
      finishDate: Date.now(),
25
      habits: [
26
        { value: Date.now(), name: 'Levantarse temprano' },
27
        { value: Date.now(), name: 'Estudiar' },
28
        { value: Date.now(), name: 'Meditar' }
29
      ]
30
    }
31
  ])
32
  const [showModal, setshowModal] = useState(false)
33
 
34
  const toggleModal = () => setshowModal(!showModal)
35
 
36
  const addGoal = (goal) => {
37
    const newGoal = {
38
      id: goals.length + 1,
39
      ...goal
40
    }
41
    setGoals([...goals, newGoal])
42
    toggleModal()
43
  }
44
 
45
  return (
46
    <GoalsContext.Provider
47
      value={{
48
        setGoals,
49
        goals,
50
        toggleModal,
51
        showModal,
52
        addGoal
53
      }}
54
    >
55
      {children}
56
    </GoalsContext.Provider>
57
  )
58
}