Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 2778 Rev 3416
Línea 1... Línea 1...
1
import { useEffect, useMemo } from 'react'
1
import { useMemo } from "react";
Línea 2... Línea 2...
2
 
2
 
Línea 3... Línea 3...
3
import { useFetch } from '@hooks'
3
import { useFetch } from "@hooks";
4
 
4
 
5
export function useNavbar() {
-
 
6
  const { data: menuData } = useFetch('/helpers/menu')
-
 
7
  const {
-
 
8
    data: session,
-
 
9
    refetch,
5
export function useNavbar() {
Línea 10... Línea 6...
10
    isLoading
6
  const { data: menuData } = useFetch("/helpers/menu");
11
  } = useFetch(menuData?.routeCheckSession)
7
  const { data: session } = useFetch(menuData?.routeCheckSession);
Línea 12... Línea 8...
12
 
8
 
13
  const memoMenu = useMemo(() => {
9
  const memoMenu = useMemo(() => {
14
    if (!menuData.menu) return []
10
    if (!menuData.menu) return [];
15
 
11
 
16
    const menu = structuredClone(menuData?.menu)
12
    const menu = structuredClone(menuData?.menu);
Línea 17... Línea 13...
17
    const comunicationIndex = menu.findIndex(
13
    const comunicationIndex = menu.findIndex(
18
      (item) => item.label === 'Comunicación'
14
      (item) => item.label === "Comunicación"
19
    )
15
    );
20
    const comunication = menu[comunicationIndex]
16
    const comunication = menu[comunicationIndex];
Línea 21... Línea 17...
21
 
17
 
22
    const newComunicationChilds = comunication.childs.map((child) => {
18
    const newComunicationChilds = comunication.childs.map((child) => {
23
      if (child.label === 'Notificaciones') {
19
      if (child.label === "Notificaciones") {
Línea 24... Línea 20...
24
        return { ...child, count: session?.total_notifications }
20
        return { ...child, count: session?.total_notifications };
25
      }
21
      }
Línea 26... Línea 22...
26
 
22
 
27
      if (child.label === 'Inmail') {
23
      if (child.label === "Inmail") {
Línea 28... Línea 24...
28
        return { ...child, count: session?.total_messages }
24
        return { ...child, count: session?.total_messages };
29
      }
25
      }
30
 
-
 
31
      return child
-
 
32
    })
-
 
33
 
-
 
34
    comunication.childs = newComunicationChilds
-
 
35
    menu[comunicationIndex] = comunication
-
 
36
 
-
 
37
    return menu
-
 
38
  }, [menuData, session])
-
 
39
 
-
 
Línea 40... Línea 26...
40
  useEffect(() => {
26
 
41
    const sessionInterval = setTimeout(() => {
27
      return child;
42
      !isLoading && refetch()
28
    });
43
    }, 3000)
29
 
44
 
30
    comunication.childs = newComunicationChilds;
45
    return () => {
31
    menu[comunicationIndex] = comunication;