diff --git a/lib/clientUtils.js b/lib/clientUtils.js index 61bf184..ba1a3c6 100644 --- a/lib/clientUtils.js +++ b/lib/clientUtils.js @@ -185,3 +185,10 @@ export const directionSelectOptions = ( ); + +/** + * Trigger a shallow router reload in order to trigger the Nprogress loader + * @param router {Object} - The Next.js router object + * @returns {*} + */ +export const triggerLoader = (router) => router.push({ pathname: router.asPath }, undefined, { shallow: true }); diff --git a/pages/combos/index.jsx b/pages/combos/index.jsx index 03dc92c..1fc8a67 100644 --- a/pages/combos/index.jsx +++ b/pages/combos/index.jsx @@ -8,20 +8,24 @@ import { hiddenStyle, landedAtCol, stanceSelectOptions, + triggerLoader, } from '../../lib/clientUtils'; import { stringifyValues } from '../../lib/commonUtils'; import GenericTable from '../../components/common/genericTable/GenericTable'; import TransitionScroll from 'react-transition-scroll'; import Filters from '../../components/common/Filters'; +import { useRouter } from 'next/router'; const defaultFilters = { grind: false, manual: false, stance: 'all', landed: 'any' }; export default function CombosPage() { const [combos, setCombos] = useState(null); const [filters, setFilters] = useState(defaultFilters); + const router = useRouter(); useAsyncEffect(async () => { try { + triggerLoader(router); const params = new URLSearchParams(stringifyValues(filters)); const { data } = await apiCall(`combos?${params}`, { method: 'GET' }); setCombos(data); diff --git a/pages/flatgroundtricks/index.jsx b/pages/flatgroundtricks/index.jsx index 8b3c105..163ebea 100644 --- a/pages/flatgroundtricks/index.jsx +++ b/pages/flatgroundtricks/index.jsx @@ -1,20 +1,31 @@ import { useState } from 'react'; import { useAsyncEffect } from '../../lib/customHooks'; import { toast } from 'react-toastify'; -import { apiCall, baseStyle, getCommonActions, hiddenStyle, landedAtCol, trickCol } from '../../lib/clientUtils'; +import { + apiCall, + baseStyle, + getCommonActions, + hiddenStyle, + landedAtCol, + trickCol, + triggerLoader, +} from '../../lib/clientUtils'; import GenericTable from '../../components/common/genericTable/GenericTable'; import TransitionScroll from 'react-transition-scroll'; import Filters from '../../components/common/Filters'; import { stringifyValues } from '../../lib/commonUtils'; +import { useRouter } from 'next/router'; const defaultFilters = { landed: 'any' }; export default function FlatgroundTricksPage() { const [flatgroundTricks, setFlatgroundTricks] = useState(null); const [filters, setFilters] = useState(defaultFilters); + const router = useRouter(); useAsyncEffect(async () => { try { + triggerLoader(router); const searchParams = new URLSearchParams(stringifyValues(filters)); const { data } = await apiCall(`flatgroundtricks`, { method: 'GET', searchParams }); setFlatgroundTricks(data); diff --git a/pages/grinds/index.jsx b/pages/grinds/index.jsx index 4c10f6b..5f66b59 100644 --- a/pages/grinds/index.jsx +++ b/pages/grinds/index.jsx @@ -1,20 +1,31 @@ import { useState } from 'react'; import { useAsyncEffect } from '../../lib/customHooks'; import { toast } from 'react-toastify'; -import { apiCall, baseStyle, getCommonActions, hiddenStyle, landedAtCol, trickCol } from '../../lib/clientUtils'; +import { + apiCall, + baseStyle, + getCommonActions, + hiddenStyle, + landedAtCol, + trickCol, + triggerLoader, +} from '../../lib/clientUtils'; import GenericTable from '../../components/common/genericTable/GenericTable'; import TransitionScroll from 'react-transition-scroll'; import Filters from '../../components/common/Filters'; import { stringifyValues } from '../../lib/commonUtils'; +import { useRouter } from 'next/router'; const defaultFilters = { landed: 'any' }; export default function GrindsPage() { const [grinds, setGrinds] = useState(null); const [filters, setFilters] = useState(defaultFilters); + const router = useRouter(); useAsyncEffect(async () => { try { + triggerLoader(router); const searchParams = new URLSearchParams(stringifyValues(filters)); const { data } = await apiCall('grinds', { method: 'GET', searchParams }); setGrinds(data); diff --git a/pages/manuals/index.jsx b/pages/manuals/index.jsx index 188c73a..82c2e2f 100644 --- a/pages/manuals/index.jsx +++ b/pages/manuals/index.jsx @@ -1,20 +1,23 @@ import { useState } from 'react'; import { useAsyncEffect } from '../../lib/customHooks'; import { toast } from 'react-toastify'; -import { apiCall, baseStyle, getCommonActions, hiddenStyle, landedAtCol } from '../../lib/clientUtils'; +import { apiCall, baseStyle, getCommonActions, hiddenStyle, landedAtCol, triggerLoader } from '../../lib/clientUtils'; import GenericTable from '../../components/common/genericTable/GenericTable'; import TransitionScroll from 'react-transition-scroll'; import Filters from '../../components/common/Filters'; import { stringifyValues } from '../../lib/commonUtils'; +import { useRouter } from 'next/router'; const defaultFilters = { landed: 'any' }; export default function ManualsPage() { const [manuals, setManuals] = useState(null); const [filters, setFilters] = useState(defaultFilters); + const router = useRouter(); useAsyncEffect(async () => { try { + triggerLoader(router); const searchParams = new URLSearchParams(stringifyValues(filters)); const { data } = await apiCall('manuals', { method: 'GET', searchParams }); setManuals(data);