Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
feat: Show loading spinner on Feedback submit button
Browse files Browse the repository at this point in the history
  • Loading branch information
binarybaron committed May 31, 2024
1 parent 432f648 commit 945f609
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/renderer/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function submitFeedbackViaHttp(

if (!response.ok) {
throw new Error(
`Failed to submit feedback. Status: ${response.status}, Status Text: ${response.statusText}`
`Status: ${response.status}`
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/renderer/components/modal/feedback/FeedbackDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { store } from '../../../store/storeRenderer';
import { submitFeedbackViaHttp } from '../../../api';
import { CliLog } from '../../../../models/cliModel';
import { PiconeroAmount } from '../../other/Units';
import LoadingButton from '../../other/LoadingButton';

async function submitFeedback(body: string, swapId: string | number) {
let attachedBody = '';
Expand Down Expand Up @@ -134,7 +135,7 @@ export default function FeedbackDialog({
</DialogContent>
<DialogActions>
<Button onClick={onClose}>Cancel</Button>
<Button
<LoadingButton
color="primary"
variant="contained"
onClick={async () => {
Expand All @@ -150,17 +151,16 @@ export default function FeedbackDialog({
});
} catch (e) {
console.error(`Failed to submit feedback: ${e}`);
enqueueSnackbar('Failed to submit feedback', {
enqueueSnackbar(`Failed to submit feedback (${e})`, {
variant: 'error',
});
} finally {
setPending(false);
}
onClose();
}}
>
} } loading={pending} >
Submit
</Button>
</LoadingButton>
</DialogActions>
</Dialog>
);
Expand Down
22 changes: 22 additions & 0 deletions src/renderer/components/other/LoadingButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import Button, { ButtonProps } from '@material-ui/core/Button';
import CircularProgress from '@material-ui/core/CircularProgress';

interface LoadingButtonProps extends ButtonProps {
loading: boolean;
}

const LoadingButton: React.FC<LoadingButtonProps> = ({ loading, disabled, children, ...props }) => {
return (
<Button
className={classes.button}
disabled={loading || disabled}
{...props}
endIcon={loading && <CircularProgress size="1rem" />}
>
{children}
</Button>
);
};

export default LoadingButton;

0 comments on commit 945f609

Please sign in to comment.