Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent double clicking. #65

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions server/app/src/components/BooksGrid/BooksGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface Props {
}

export const BooksGrid: React.FC<Props> = ({ books }: Props) => {
const dispatch = useDispatch();
const { data: onlineServers, refetch } = useGetServersQuery(null);
const [titleFilter, setTitleFilter] = useState<string>("");
const [authorFilter, setAuthorFilter] = useState<string>("");
Expand Down Expand Up @@ -114,19 +113,7 @@ export const BooksGrid: React.FC<Props> = ({ books }: Props) => {
{book.size}
</Table.TextCell>
<Table.Cell flexBasis={150} flexGrow={0} flexShrink={0}>
<Button
appearance="primary"
size="small"
onClick={() =>
dispatch(
sendMessage({
type: MessageType.DOWNLOAD,
payload: { book: book.full }
})
)
}>
Download
</Button>
<DownloadButton book={book.full} />
</Table.Cell>
</Table.Row>
));
Expand Down Expand Up @@ -186,3 +173,26 @@ export const BooksGrid: React.FC<Props> = ({ books }: Props) => {
</Table>
);
};

function DownloadButton({ book }: { book: string }) {
const dispatch = useDispatch();
const [disabled, setDisabled] = useState(false);

// Prevent hitting the same button multiple times
const onClick = () => {
if (disabled) return;
dispatch(
sendMessage({
type: MessageType.DOWNLOAD,
payload: { book }
})
);
setDisabled(true);
};

return (
<Button appearance="primary" size="small" onClick={onClick}>
Download
</Button>
);
}
3 changes: 1 addition & 2 deletions todo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Future:

- Show IRC logs in the browser
- Show online servers in the CLI.
- Handle name collisions
- Handle IRC name collisions
- Simplify dto model calling code in Go. Don't need as many types.
- Allow reconnecting to same IRC connection if websocket disconnects.
- Currently we immediately terminate the IRC connection and remove the client
Expand All @@ -14,4 +14,3 @@ Future:
- Improve message formats.
- Don't need as many separate message types. Just have functions that create them with the appropriate status code.
- Log the address to access it in the browser on startup
- Prevent double clicking the download button.