Skip to content

Commit

Permalink
Auto-connect on launch
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
mhoran committed Mar 19, 2024
1 parent a0b5ef0 commit 8fa8959
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/usecase/ConnectionGate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { connect } from 'react-redux';
import { StoreState } from '../store';
import { useEffect } from 'react';
import { connect, useStore } from 'react-redux';
import { ConnectionError } from '../lib/weechat/connection';
import { StoreState } from '../store';
import SettingsNavigator from './settings/SettingsNavigator';

interface Props {
Expand All @@ -18,6 +19,19 @@ const ConnectionGate: React.FC<Props> = ({
onConnect,
connectionError
}) => {
const store = useStore<StoreState>();

useEffect(() => {
const connectionSettings = store.getState().connection;
if (connectionSettings.hostname && connectionSettings.password) {
onConnect(
connectionSettings.hostname,
connectionSettings.password,
connectionSettings.ssl
);
}
}, [onConnect, store]);

if (connected) {
return children;
} else {
Expand Down

0 comments on commit 8fa8959

Please sign in to comment.