Skip to content

Commit

Permalink
feat(loading): added custom component that can be displayed in place …
Browse files Browse the repository at this point in the history
…of default loading UI (#23)

* feat(loading): added custom component that can be displayed in place of loading UI

* ci: fixed test job name [skip ci]
  • Loading branch information
roerohan authored Feb 19, 2022
1 parent cd990a1 commit 8005dd2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- main
jobs:
lint:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ interface Props {
autoConnect?: number; // defaults to true
retryDuration?: number; // in milliseconds
debug?: boolean; // show logs in the console
loadingUI?: React.ReactNode; // custom component that is displayed when loading
onConnect?: (rfb?: RFB) => void;
onDisconnect?: (rfb?: RFB) => void;
onCredentialsRequired?: (rfb?: RFB) => void;
Expand Down
7 changes: 3 additions & 4 deletions src/lib/VncScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Props {
autoConnect?: boolean;
retryDuration?: number;
debug?: boolean;
loadingUI?: React.ReactNode;
onConnect?: (rfb?: RFB) => void;
onDisconnect?: (rfb?: RFB) => void;
onCredentialsRequired?: (rfb?: RFB) => void;
Expand Down Expand Up @@ -60,6 +61,7 @@ const VncScreen: React.ForwardRefRenderFunction<VncScreenHandle, Props> = (props
autoConnect = true,
retryDuration = 3000,
debug = false,
loadingUI,
onConnect,
onDisconnect,
onCredentialsRequired,
Expand Down Expand Up @@ -109,7 +111,6 @@ const VncScreen: React.ForwardRefRenderFunction<VncScreenHandle, Props> = (props
}

const connected = getConnected();
console.log('onDisconnect: connected', connected);
if (connected) {
logger.info(`Unexpectedly disconnected from remote VNC, retrying in ${retryDuration / 1000} seconds.`);

Expand Down Expand Up @@ -169,7 +170,6 @@ const VncScreen: React.ForwardRefRenderFunction<VncScreenHandle, Props> = (props

const connect = () => {
try {
console.log('connected', connected);
if (connected && !!rfb) {
disconnect();
}
Expand Down Expand Up @@ -202,7 +202,6 @@ const VncScreen: React.ForwardRefRenderFunction<VncScreenHandle, Props> = (props

_rfb.addEventListener('desktopname', _onDesktopName);

console.log('Setting connected to true again');
setConnected(true);
} catch (err) {
logger.error(err);
Expand Down Expand Up @@ -257,7 +256,7 @@ const VncScreen: React.ForwardRefRenderFunction<VncScreenHandle, Props> = (props
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
/>
{loading && <div className="text-white loading">Loading...</div>}
{loading && (loadingUI ?? <div className="text-white loading">Loading...</div>)}
</>
);
}
Expand Down

0 comments on commit 8005dd2

Please sign in to comment.