{shouldRenderPasswordLock ? (
this.renderPasswordLock()
@@ -529,7 +522,7 @@ class SettingsViewInner extends React.Component
{
buttonColor: SessionButtonColor.Primary,
},
onClick: () => {
- this.displayPasswordModal(PasswordAction.Set);
+ this.displayPasswordModal('set');
},
confirmationDialogParams: undefined,
},
@@ -547,7 +540,7 @@ class SettingsViewInner extends React.Component {
buttonColor: SessionButtonColor.Primary,
},
onClick: () => {
- this.displayPasswordModal(PasswordAction.Change);
+ this.displayPasswordModal('change');
},
confirmationDialogParams: undefined,
},
@@ -565,7 +558,7 @@ class SettingsViewInner extends React.Component {
buttonColor: SessionButtonColor.Danger,
},
onClick: () => {
- this.displayPasswordModal(PasswordAction.Remove);
+ this.displayPasswordModal('remove');
},
confirmationDialogParams: undefined,
},
@@ -573,25 +566,14 @@ class SettingsViewInner extends React.Component {
}
private displayPasswordModal(passwordAction: PasswordAction) {
- this.setState({
- ...this.state,
- modal: (
- {
- this.clearModal();
- }}
- onOk={this.onPasswordUpdated}
- action={passwordAction}
- />
- ),
- });
- }
-
- private clearModal(): void {
- this.setState({
- ...this.state,
- modal: null,
- });
+ window.inboxStore?.dispatch(
+ sessionPassword({
+ passwordAction,
+ onOk: () => {
+ this.onPasswordUpdated(passwordAction);
+ },
+ })
+ );
}
private getBlockedUserSettings(): Array {
diff --git a/ts/hooks/useNetwork.ts b/ts/hooks/useNetwork.ts
deleted file mode 100644
index d92fc9937..000000000
--- a/ts/hooks/useNetwork.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { useEffect, useState } from 'react';
-
-export function useNetwork() {
- const [isOnline, setNetwork] = useState(window.navigator.onLine);
- const updateNetwork = () => {
- setNetwork(window.navigator.onLine);
- };
-
- // there are some weird behavior with this api.
- // basically, online events might not be called if the pc has a virtual machine running
- // https://github.com/electron/electron/issues/11290#issuecomment-348598311
- useEffect(() => {
- window.addEventListener('offline', updateNetwork);
- window.addEventListener('online', updateNetwork);
-
- return () => {
- window.removeEventListener('offline', updateNetwork);
- window.removeEventListener('online', updateNetwork);
- };
- });
- return isOnline;
-}
diff --git a/ts/state/ducks/modalDialog.tsx b/ts/state/ducks/modalDialog.tsx
index 9fba3bfa8..91ce81173 100644
--- a/ts/state/ducks/modalDialog.tsx
+++ b/ts/state/ducks/modalDialog.tsx
@@ -1,5 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { SessionConfirmDialogProps } from '../../components/session/SessionConfirm';
+import { PasswordAction } from '../../components/session/SessionPasswordModal';
export type ConfirmModalState = SessionConfirmDialogProps | null;
export type InviteContactModalState = { conversationId: string } | null;
@@ -13,6 +14,8 @@ export type EditProfileModalState = {} | null;
export type OnionPathModalState = EditProfileModalState;
export type RecoveryPhraseModalState = EditProfileModalState;
+export type SessionPasswordModalState = { passwordAction: PasswordAction; onOk: () => void } | null;
+
export type UserDetailsModalState = {
conversationId: string;
authorAvatarPath?: string;
@@ -32,6 +35,7 @@ export type ModalState = {
onionPathModal: OnionPathModalState;
recoveryPhraseModal: RecoveryPhraseModalState;
adminLeaveClosedGroup: AdminLeaveClosedGroupModalState;
+ sessionPasswordModal: SessionPasswordModalState;
};
export const initialModalState: ModalState = {
@@ -47,6 +51,7 @@ export const initialModalState: ModalState = {
onionPathModal: null,
recoveryPhraseModal: null,
adminLeaveClosedGroup: null,
+ sessionPasswordModal: null,
};
const ModalSlice = createSlice({
@@ -89,6 +94,9 @@ const ModalSlice = createSlice({
adminLeaveClosedGroup(state, action: PayloadAction) {
return { ...state, adminLeaveClosedGroup: action.payload };
},
+ sessionPassword(state, action: PayloadAction) {
+ return { ...state, sessionPasswordModal: action.payload };
+ },
},
});
@@ -106,5 +114,6 @@ export const {
onionPathModal,
recoveryPhraseModal,
adminLeaveClosedGroup,
+ sessionPassword,
} = actions;
export const modalReducer = reducer;
diff --git a/ts/state/selectors/modal.ts b/ts/state/selectors/modal.ts
index 769b18e23..ec3f765a8 100644
--- a/ts/state/selectors/modal.ts
+++ b/ts/state/selectors/modal.ts
@@ -12,6 +12,7 @@ import {
OnionPathModalState,
RecoveryPhraseModalState,
RemoveModeratorsModalState,
+ SessionPasswordModalState,
UpdateGroupMembersModalState,
UpdateGroupNameModalState,
UserDetailsModalState,
@@ -80,3 +81,8 @@ export const getAdminLeaveClosedGroupDialog = createSelector(
getModal,
(state: ModalState): AdminLeaveClosedGroupModalState => state.adminLeaveClosedGroup
);
+
+export const getSessionPasswordDialog = createSelector(
+ getModal,
+ (state: ModalState): SessionPasswordModalState => state.sessionPasswordModal
+);