Skip to content

Commit

Permalink
hide button while loading
Browse files Browse the repository at this point in the history
  • Loading branch information
angelo-v committed Oct 29, 2021
1 parent 29c4202 commit d10361a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/content/Toolbar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ describe('Toolbar', () => {
expect(screen.getByText('Jane Doe')).toBeInTheDocument();
});

it('disables the clip it button', () => {
it('hides the clip it button', () => {
render(<Toolbar profile={{ name: 'Jane Doe' }} />);

expect(screen.queryByText('Clip it!')).toBeInTheDocument();
const button = screen.getByText('Clip it!');
expect(button).toBeDisabled();
const button = screen.queryByRole('button');
expect(button).not.toBeInTheDocument();
expect(screen.queryByText('Clip it!')).not.toBeInTheDocument();
});
});

Expand Down Expand Up @@ -91,6 +91,7 @@ describe('Toolbar', () => {
it('shows an error if the bookmark cannot be saved', () => {
(useBookmark as jest.Mock).mockReturnValue({
saving: false,
loading: false,
error: new Error('Pod not available'),
addBookmark,
});
Expand Down
17 changes: 10 additions & 7 deletions src/content/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ interface Props {
export const Toolbar = ({ profile }: Props) => {
const page = usePage();
const { addBookmark, loading, saving, error, bookmark } = useBookmark(page);
const waiting = loading || saving;
return (
<>
<p className="my-1">{profile.name}</p>
<button
className="my-1 px-4 py-2 bg-blue-400 rounded text-white hover:opacity-90 font-bold"
disabled={loading || saving}
onClick={() => addBookmark()}
>
{saving ? 'Saving...' : 'Clip it!'}
</button>
{loading ? null : (
<button
className="my-1 px-4 py-2 bg-blue-400 rounded text-white hover:opacity-90 font-bold"
disabled={waiting}
onClick={() => addBookmark()}
>
{saving ? 'Saving...' : 'Clip it!'}
</button>
)}
{error && <p>{error.message}</p>}
{bookmark && (
<p className="my-1 text-blue-400 opacity-90 hover:opacity-100">
Expand Down

0 comments on commit d10361a

Please sign in to comment.