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 queries for 'Summary' using Redux toolkit Query
Browse files Browse the repository at this point in the history
  ## what
  - Add Redux Toolkit queries for 'Summary'
    - GET summary
      - Fetch Pi-hole Summary from API
        - The data is formatted for readability
    - GET summary raw
      - Fetch Pi-hole Summary raw from API
        - The data is in raw format
  - export prebuilt React hooks for 'Summary' queries
    - useGetSummaryQuery
      - React hook for fetching Pi-hole Summary
    - useGetSummaryRawQuery
      - React hook for fetching Pi-hole Summary in raw format

  ## how
  - used guide from
    - 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/utils/url/api.ts

  ## usage
  • Loading branch information
Clumsy-Coder committed Aug 20, 2023
1 parent 8b37100 commit c223210
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/redux/Summary/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import apiSlice, { TagTypes } from '@redux/apiSlice';
import { getSummaryUrl, getSummaryRawUrl } from '@utils/url/api';
import { ISummary, ISummaryRaw } from '@utils/url/upstream.types';

const summaryApi = apiSlice.injectEndpoints({
endpoints: (build) => ({
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
getSummary: build.query<ISummary, void>({
query: () => ({
url: getSummaryUrl,
method: 'GET',
}),
providesTags: () => [{ type: TagTypes.SUMMARY }],
}),
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
getSummaryRaw: build.query<ISummaryRaw, void>({
query: () => ({
url: getSummaryRawUrl,
method: 'GET',
}),
providesTags: () => [{ type: TagTypes.SUMMARY_RAW }],
}),
}),
});

export const { useGetSummaryQuery, useGetSummaryRawQuery } = summaryApi;

0 comments on commit c223210

Please sign in to comment.