Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3114 | Rev 3151 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3114 Rev 3146
Línea 1... Línea 1...
1
import { useCallback } from 'react'
1
import { useContext } from 'react'
2
import { useFetch } from '../useFetch'
-
 
Línea 3... Línea 2...
3
 
2
 
4
export function useHabits({ url }) {
-
 
5
  const {
-
 
6
    data: { items: habits, link_add, total },
-
 
7
    isLoading: loading,
-
 
8
    mutate
-
 
9
  } = useFetch(url)
-
 
10
 
-
 
11
  const addHabit = useCallback(
-
 
12
    (newHabit) => {
-
 
13
      const newHabits = [...habits, newHabit]
-
 
14
      mutate(newHabits)
-
 
15
    },
-
 
16
    [habits, mutate]
-
 
Línea 17... Línea 3...
17
  )
3
import { PurposesContext } from '@providers/habits/purposes'
18
 
4
 
19
  const deleteHabit = useCallback(
-
 
20
    (habitId) => {
5
export function useHabits() {
21
      const newHabits = habits.filter((habit) => habit.id !== habitId)
6
  const {
22
      mutate(newHabits)
7
    loading,
23
    },
8
    purposes,
24
    [habits, mutate]
-
 
25
  )
-
 
26
 
9
    addUrl: link_add,
27
  const updateHabit = useCallback(
-
 
28
    (updatedHabit) => {
-
 
29
      const newHabits = habits.map((habit) =>
10
    total,
30
        habit.id === updatedHabit.id ? updatedHabit : habit
11
    addPurpose,
31
      )
12
    deletePurpose,
32
      mutate(newHabits)
13
    updatePurpose,
33
    },
-
 
Línea 34... Línea 14...
34
    [habits, mutate]
14
    getPurposeById
35
  )
15
  } = useContext(PurposesContext)
36
 
16
 
37
  return {
17
  return {
38
    loading,
18
    loading,
39
    habits,
19
    purposes,
40
    addUrl: link_add,
20
    addUrl: link_add,
41
    total,
21
    total,
-
 
22
    addPurpose,
42
    addHabit,
23
    deletePurpose,
43
    deleteHabit,
24
    updatePurpose,