Skip to content

Commit

Permalink
Don't connect before store state is restored
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed Apr 24, 2024
1 parent 350d197 commit f90ccc0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/usecase/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ export default class WeechatNative extends React.Component<null, State> {
);
}

componentDidMount(): void {
const { hostname, password, ssl } = store.getState().connection;
if (hostname && password) this.onConnect(hostname, password, ssl);
}

componentWillUnmount(): void {
this.connection?.disconnect();
this.appStateListener.remove();
Expand All @@ -130,6 +125,11 @@ export default class WeechatNative extends React.Component<null, State> {
this.unsubscribeFetchBuffersDispatchListener();
}

onBeforeLift = (): void => {
const { hostname, password, ssl } = store.getState().connection;
if (hostname && password) this.onConnect(hostname, password, ssl);
};

setNotificationToken = async (): Promise<void> => {
const token = await getPushNotificationStatusAsync();
if (token) this.sendMessageToBuffer('core.weechat', '/weechatrn ' + token);
Expand Down Expand Up @@ -218,7 +218,11 @@ export default class WeechatNative extends React.Component<null, State> {
return (
<Provider store={store}>
<SafeAreaProvider>
<PersistGate loading={null} persistor={persistor}>
<PersistGate
loading={null}
persistor={persistor}
onBeforeLift={this.onBeforeLift}
>
<ConnectionGate
connecting={connecting}
connectionError={connectionError}
Expand Down

0 comments on commit f90ccc0

Please sign in to comment.