Skip to content

Commit

Permalink
Trigger loaders when using filters
Browse files Browse the repository at this point in the history
  • Loading branch information
alianza committed Jun 1, 2024
1 parent bf9cf6f commit e78f6f0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/clientUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,10 @@ export const directionSelectOptions = (
<option value="none">No direction</option>
</>
);

/**
* 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 });
4 changes: 4 additions & 0 deletions pages/combos/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion pages/flatgroundtricks/index.jsx
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
13 changes: 12 additions & 1 deletion pages/grinds/index.jsx
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
5 changes: 4 additions & 1 deletion pages/manuals/index.jsx
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit e78f6f0

Please sign in to comment.