From f0c41cdaa0f7c0e4af00e427e18e319afa063c93 Mon Sep 17 00:00:00 2001 From: Clumsy-Coder <19594044+Clumsy-Coder@users.noreply.github.com> Date: Fri, 30 Sep 2022 11:17:58 -0600 Subject: [PATCH] feat(redux): add API query for 'TopBlocked' using Redux Toolkit Query ## what - add API query for 'TopBlocked' using Redux Toolkit Query - Query - GET queries/topBlocked - fetch data from NextJS API url '/api/queries/topBlocked' - export prebuilt React hook 'useGetTopBlockedQueriesQuery ' ## how - https://redux-toolkit.js.org/rtk-query/overview - https://redux-toolkit.js.org/rtk-query/usage/queries - https://redux-toolkit.js.org/rtk-query/usage/code-splitting ## why - Easy way to manage fetching data from API, etc - Less overhead to manage the code to handle these operations - most of the work is done for you ## where - ./src/redux/Queries/TopQueries.ts ## usage --- src/redux/Queries/TopQueries.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/redux/Queries/TopQueries.ts b/src/redux/Queries/TopQueries.ts index 6422f08f..69065cfa 100644 --- a/src/redux/Queries/TopQueries.ts +++ b/src/redux/Queries/TopQueries.ts @@ -1,6 +1,6 @@ import apiSlice, { TagTypes, HttpQueryType } from '@redux/apiSlice'; -import { getTopPermittedQueriesUrl } from '@utils/url/api'; -import { ITopPermittedQueries } from '@utils/url/upstream.types'; +import { getTopPermittedQueriesUrl, getTopBlockedQueriesUrl } from '@utils/url/api'; +import { ITopPermittedQueries, ITopBlockedQueries } from '@utils/url/upstream.types'; const topQueriesApi = apiSlice.injectEndpoints({ endpoints: (build) => ({ @@ -12,8 +12,15 @@ const topQueriesApi = apiSlice.injectEndpoints({ }), providesTags: () => [{ type: TagTypes.QUERY_TOP_PERMITTED }], }), + getTopBlockedQueries: build.query({ + query: (numEntries = 10) => ({ + url: `${getTopBlockedQueriesUrl}?numEntries=${numEntries}`, + method: HttpQueryType.GET, + }), + providesTags: () => [{ type: TagTypes.QUERY_TOP_BLOCKED }], + }), }), }); // eslint-disable-next-line import/prefer-default-export -export const { useGetTopPermittedQueriesQuery } = topQueriesApi; +export const { useGetTopPermittedQueriesQuery, useGetTopBlockedQueriesQuery } = topQueriesApi;