Proyectos de Subversion LeadersLinked - SPA

Rev

Autoría | Ultima modificación | Ver Log |

import React, { createContext, useState } from 'react'

export const GoalsContext = createContext()

export default function GoalsProvider({ children }) {
  const [goals, setGoals] = useState([
    {
      id: 1,
      title: 'Lograr un ascenso',
      description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
      value: 10,
      finishDate: Date.now(),
      habits: [
        { value: Date.now(), name: 'Levantarse temprano' },
        { value: Date.now(), name: 'Estudiar' },
        { value: Date.now(), name: 'Meditar' }
      ]
    },
    {
      id: 2,
      title: 'Mejorar mi fisico',
      description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
      value: 10,
      finishDate: Date.now(),
      habits: [
        { value: Date.now(), name: 'Levantarse temprano' },
        { value: Date.now(), name: 'Estudiar' },
        { value: Date.now(), name: 'Meditar' }
      ]
    }
  ])
  const [showModal, setshowModal] = useState(false)

  const toggleModal = () => setshowModal(!showModal)

  const addGoal = (goal) => {
    const newGoal = {
      id: goals.length + 1,
      ...goal
    }
    setGoals([...goals, newGoal])
    toggleModal()
  }

  return (
    <GoalsContext.Provider
      value={{
        setGoals,
        goals,
        toggleModal,
        showModal,
        addGoal
      }}
    >
      {children}
    </GoalsContext.Provider>
  )
}