<commit_before>import React, { useCallback, useRef } from "react"
import { useQuery } from "@apollo/react-hooks"
import { Header, Footer } from "dicty-components-header-footer"
import { Navbar } from "dicty-components-navbar"
import jwtDecode from "jwt-decode"
import { CartProvider } from "components/ShoppingCart/CartStore"
import {
  headerItems,
  loggedHeaderItems,
  generateLinks,
} from "utils/headerItems"
import CartIcon from "components/ShoppingCart/CartIcon"
import ErrorBoundary from "components/Errors/ErrorBoundary"
import RenderRoutes from "routes/RenderRoutes"
import { useAuthStore } from "components/authentication/AuthStore"
import useFetchRefreshToken from "hooks/useFetchRefreshToken"
import useFooter from "hooks/useFooter"
import useNavbar from "hooks/useNavbar"
import { GET_REFRESH_TOKEN } from "graphql/queries"
import { useStyles, navTheme } from "./appStyles"

const getTokenIntervalDelay = (token: string) => {
  if (token === "") {
    return
  }
  const decodedToken = jwtDecode(token) as any
  const currentTime = new Date(Date.now())
  const jwtTime = new Date(decodedToken.exp * 1000)
  const timeDiffInMins = (+jwtTime - +currentTime) / 60000
  // all this to say we want the delay to be two minutes before the JWT expires
  return (timeDiffInMins - 2) * 60 * 1000
}

const App = () => {
  const [{ isAuthenticated, token }, dispatch] = useAuthStore()
  const { navbarData } = useNavbar()
  const { footerData } = useFooter()
  const classes = useStyles()
  const { refetch } = useQuery(GET_REFRESH_TOKEN, {
    variables: { token: token },
    errorPolicy: "ignore",
  })
  const interval = useRef(null)
  const delay = getTokenIntervalDelay(token)

  const fetchRefreshToken = useCallback(async () => {
    const res = await refetch({ token: token })
    if (res.data.getRefreshToken) {
      dispatch({
        type: "UPDATE_TOKEN",
        payload: {
          provider: res.data.getRefreshToken.identity.provider,
          token: res.data.getRefreshToken.token,
          user: res.data.getRefreshToken.user,
        },
      })
    }
  }, [dispatch, refetch, token])
  useFetchRefreshToken(fetchRefreshToken, interval, delay!, isAuthenticated)

  const headerContent = isAuthenticated ? loggedHeaderItems : headerItems
<commit_msg>refactor: rename function to specify milliseconds<commit_after>import React, { useCallback, useRef } from "react"
import { useQuery } from "@apollo/react-hooks"
import { Header, Footer } from "dicty-components-header-footer"
import { Navbar } from "dicty-components-navbar"
import jwtDecode from "jwt-decode"
import { CartProvider } from "components/ShoppingCart/CartStore"
import {
  headerItems,
  loggedHeaderItems,
  generateLinks,
} from "utils/headerItems"
import CartIcon from "components/ShoppingCart/CartIcon"
import ErrorBoundary from "components/Errors/ErrorBoundary"
import RenderRoutes from "routes/RenderRoutes"
import { useAuthStore } from "components/authentication/AuthStore"
import useFetchRefreshToken from "hooks/useFetchRefreshToken"
import useFooter from "hooks/useFooter"
import useNavbar from "hooks/useNavbar"
import { GET_REFRESH_TOKEN } from "graphql/queries"
import { useStyles, navTheme } from "./appStyles"

const getTokenIntervalDelayInMS = (token: string) => {
  if (token === "") {
    return
  }
  const decodedToken = jwtDecode(token) as any
  const currentTime = new Date(Date.now())
  const jwtTime = new Date(decodedToken.exp * 1000)
  const timeDiffInMins = (+jwtTime - +currentTime) / 60000
  // all this to say we want the delay to be two minutes before the JWT expires
  return (timeDiffInMins - 2) * 60 * 1000
}

const App = () => {
  const [{ isAuthenticated, token }, dispatch] = useAuthStore()
  const { navbarData } = useNavbar()
  const { footerData } = useFooter()
  const classes = useStyles()
  const { refetch } = useQuery(GET_REFRESH_TOKEN, {
    variables: { token: token },
    errorPolicy: "ignore",
  })
  const interval = useRef(null)
  const delay = getTokenIntervalDelayInMS(token)

  const fetchRefreshToken = useCallback(async () => {
    const res = await refetch({ token: token })
    if (res.data.getRefreshToken) {
      dispatch({
        type: "UPDATE_TOKEN",
        payload: {
          provider: res.data.getRefreshToken.identity.provider,
          token: res.data.getRefreshToken.token,
          user: res.data.getRefreshToken.user,
        },
      })
    }
  }, [dispatch, refetch, token])
  useFetchRefreshToken(fetchRefreshToken, interval, delay!, isAuthenticated)

  const headerContent = isAuthenticated ? loggedHeaderItems : headerItems

{'fraction_non_alphanumeric': 0.10648954703832753, 'fraction_numerical': 0.006968641114982578, 'mean_word_length': 4.207482993197279, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1513666', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1393, 'n_words': 365}