Feature/swr for library screens (#186)
* Wrap data fetching in library and manga screen with swr for better dev and user experience. Refactor some API calls and data handling. Add manual refresh to manga detail. * Fix manga card layout * Fix refresh button position on small screens * Revert "Fix manga card layout" This reverts commit d85da3d8385e1ef64feed1789e4cd4591c8bd563. * Fix manga not setting title * Move chapters loading to Manga component, join data fetching, add auto online fetch if fetched data is old * Revert some changes
This commit is contained in:
32
src/components/atoms/LoadingIconButton.tsx
Normal file
32
src/components/atoms/LoadingIconButton.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import { CircularProgress, IconButton, IconButtonProps } from '@mui/material';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
interface IProps extends Omit<IconButtonProps, 'onClick'> {
|
||||
loading?: boolean
|
||||
onClick: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => Promise<any>
|
||||
}
|
||||
|
||||
const LoadingIconButton = ({
|
||||
onClick, children, loading: iLoading, ...rest
|
||||
}: IProps) => {
|
||||
const [sLoading, setLoading] = useState(false);
|
||||
const loading = sLoading || iLoading;
|
||||
|
||||
const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
||||
setLoading(true);
|
||||
onClick(e).finally(() => setLoading(false));
|
||||
};
|
||||
|
||||
return (
|
||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
<IconButton disabled={loading} {...rest} onClick={handleClick}>
|
||||
{loading ? (<CircularProgress size={24} />) : children}
|
||||
</IconButton>
|
||||
);
|
||||
};
|
||||
|
||||
LoadingIconButton.defaultProps = {
|
||||
loading: false,
|
||||
};
|
||||
|
||||
export default LoadingIconButton;
|
||||
Reference in New Issue
Block a user