Fix RTK-Query empty fetch method + minor changes
Change-Id: I0411ff0f046d820eb6c6857762332e87a1ba1767
This commit is contained in:
parent
8d18290080
commit
31488b89a4
4 changed files with 8 additions and 8 deletions
|
@ -1,12 +1,12 @@
|
||||||
import React, { FC, ReactElement, ReactNode } from 'react';
|
import React, { FC, ReactElement, ReactNode } from 'react';
|
||||||
|
|
||||||
export type FetchLoaderProps = {
|
export type FetchLoaderProps = {
|
||||||
|
active: boolean;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
isLoading: boolean;
|
|
||||||
placeholder?: ReactElement;
|
placeholder?: ReactElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const FetchLoader: FC<FetchLoaderProps> = ({ children, isLoading, placeholder }) => {
|
export const FetchLoader: FC<FetchLoaderProps> = ({ children, active: isLoading, placeholder }) => {
|
||||||
if (!isLoading) {
|
if (!isLoading) {
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,13 @@ export const baseQuery =
|
||||||
{
|
{
|
||||||
body?: RequestBody;
|
body?: RequestBody;
|
||||||
headers?: Record<string, string | number | boolean>;
|
headers?: Record<string, string | number | boolean>;
|
||||||
method: string;
|
method?: string;
|
||||||
params?: Record<string, string>;
|
params?: Record<string, string>;
|
||||||
url: string;
|
url: string;
|
||||||
},
|
},
|
||||||
Response
|
Response
|
||||||
> =>
|
> =>
|
||||||
async ({ url, method, params, body, headers }, { getState }) => {
|
async ({ url, method = 'GET', params, body, headers }, { getState }) => {
|
||||||
if ((getState() as AuthRootState).treejs[AUTH_REDUCER_NAME] !== undefined) {
|
if ((getState() as AuthRootState).treejs[AUTH_REDUCER_NAME] !== undefined) {
|
||||||
const isAuthenticated = getAuthAttribute([getState() as AuthRootState, 'authenticated']);
|
const isAuthenticated = getAuthAttribute([getState() as AuthRootState, 'authenticated']);
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ export default {
|
||||||
|
|
||||||
export const Input: Story = {
|
export const Input: Story = {
|
||||||
args: {
|
args: {
|
||||||
isLoading: true,
|
active: true,
|
||||||
children: 'children',
|
children: 'children',
|
||||||
placeholder: <FetchShapeInput />,
|
placeholder: <FetchShapeInput />,
|
||||||
},
|
},
|
||||||
|
@ -30,7 +30,7 @@ export const Input: Story = {
|
||||||
|
|
||||||
export const Table: Story = {
|
export const Table: Story = {
|
||||||
args: {
|
args: {
|
||||||
isLoading: true,
|
active: true,
|
||||||
children: 'children',
|
children: 'children',
|
||||||
placeholder: <FetchShapeTable />,
|
placeholder: <FetchShapeTable />,
|
||||||
},
|
},
|
||||||
|
@ -38,7 +38,7 @@ export const Table: Story = {
|
||||||
|
|
||||||
export const Block: Story = {
|
export const Block: Story = {
|
||||||
args: {
|
args: {
|
||||||
isLoading: true,
|
active: true,
|
||||||
children: 'children',
|
children: 'children',
|
||||||
placeholder: <FetchShapeBlock />,
|
placeholder: <FetchShapeBlock />,
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,7 +22,7 @@ const FetchPage = (): React.ReactElement => {
|
||||||
<Button status={StatusEnum.warning} label="Odeslat" onClick={() => handleFetch(1)} disabled={isFetching} />
|
<Button status={StatusEnum.warning} label="Odeslat" onClick={() => handleFetch(1)} disabled={isFetching} />
|
||||||
</GridCol>
|
</GridCol>
|
||||||
</Grid>
|
</Grid>
|
||||||
<FetchLoader isLoading={isFetching} placeholder={<Placeholder />}>
|
<FetchLoader active={isFetching} placeholder={<Placeholder />}>
|
||||||
<pre>{JSON.stringify(data, undefined, 2)}</pre>
|
<pre>{JSON.stringify(data, undefined, 2)}</pre>
|
||||||
</FetchLoader>
|
</FetchLoader>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Add table
Reference in a new issue