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

Add console scanning indicator #187

Merged
merged 1 commit into from
Jun 26, 2021
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
19 changes: 17 additions & 2 deletions src/renderer/containers/Console/NewConnectionList.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
/** @jsx jsx */
import { DiscoveredConsoleInfo } from "@console/types";
import { css, jsx } from "@emotion/react";
import CircularProgress from "@material-ui/core/CircularProgress";
import React from "react";

import { InfoBlock } from "@/components/InfoBlock";

import { NewConnectionItem } from "./NewConnectionItem";

export interface NewConnectionListProps {
isScanning?: boolean;
consoleItems: DiscoveredConsoleInfo[];
onClick: (conn: DiscoveredConsoleInfo) => void;
}

export const NewConnectionList: React.FC<NewConnectionListProps> = ({ consoleItems, onClick }) => {
export const NewConnectionList: React.FC<NewConnectionListProps> = ({ consoleItems, isScanning, onClick }) => {
return (
<InfoBlock title={`New Connections (${consoleItems.length})`}>
<InfoBlock
title={
<div
css={css`
display: flex;
justify-content: space-between;
align-items: center;
`}
>
<div>New Connections ({consoleItems.length})</div>
{isScanning && <CircularProgress size={16} thickness={6} color="inherit" />}
</div>
}
>
<div
css={css`
display: flex;
Expand Down
14 changes: 10 additions & 4 deletions src/renderer/containers/Console/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Outer = styled.div`
`;

export const Console: React.FC = () => {
const [isScanning, setIsScanning] = React.useState(false);
const [modalOpen, setModalOpen] = React.useState(false);
const [currentFormValues, setCurrentFormValues] = React.useState<Partial<StoredConnection> | null>(null);
const savedConnections = useSettings((store) => store.connections);
Expand All @@ -42,15 +43,19 @@ export const Console: React.FC = () => {

React.useEffect(() => {
// Start scanning for new consoles
startDiscovery.renderer!.trigger({}).catch((err) => {
addToast(err.message ?? JSON.stringify(err), { appearance: "error" });
});
setIsScanning(false);
startDiscovery
.renderer!.trigger({})
.then(() => setIsScanning(true))
.catch((err) => {
addToast(err.message ?? JSON.stringify(err), { appearance: "error" });
});

// Stop scanning on component unmount
return () => {
void stopDiscovery.renderer!.trigger({});
};
}, []);
}, [addToast]);

const onCancel = () => {
setModalOpen(false);
Expand Down Expand Up @@ -112,6 +117,7 @@ export const Console: React.FC = () => {
`}
>
<NewConnectionList
isScanning={isScanning}
consoleItems={consoleItemsToShow}
onClick={(item) => {
setCurrentFormValues({ ipAddress: item.ip });
Expand Down