Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
feat(redux): add API query for 'TopBlocked' using Redux Toolkit Query
Browse files Browse the repository at this point in the history
  ## 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
  • Loading branch information
Clumsy-Coder committed Aug 20, 2023
1 parent 197c177 commit f0c41cd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/redux/Queries/TopQueries.ts
Original file line number Diff line number Diff line change
@@ -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) => ({
Expand All @@ -12,8 +12,15 @@ const topQueriesApi = apiSlice.injectEndpoints({
}),
providesTags: () => [{ type: TagTypes.QUERY_TOP_PERMITTED }],
}),
getTopBlockedQueries: build.query<ITopBlockedQueries, number>({
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;

0 comments on commit f0c41cd

Please sign in to comment.