WIP refactoring confirm dialog to redux state.

pull/1665/head
Warrick Corfe-Tan 4 years ago
parent 1bfdbc5c93
commit 4c8f2bf720

@ -39,7 +39,6 @@ export class MessageView extends React.Component {
async function createClosedGroup( async function createClosedGroup(
groupName: string, groupName: string,
groupMembers: Array<ContactType>, groupMembers: Array<ContactType>,
setModal: () => void
): Promise<boolean> { ): Promise<boolean> {
// Validate groupName and groupMembers length // Validate groupName and groupMembers length
if (groupName.length === 0) { if (groupName.length === 0) {
@ -64,7 +63,7 @@ async function createClosedGroup(
const groupMemberIds = groupMembers.map(m => m.id); const groupMemberIds = groupMembers.map(m => m.id);
await createClosedGroupV2(groupName, groupMemberIds, setModal); await createClosedGroupV2(groupName, groupMemberIds);
return true; return true;
} }

@ -34,6 +34,8 @@ export type StatusLightType = {
const OnionPathModalInner = (props: any) => { const OnionPathModalInner = (props: any) => {
const onionNodes = useSelector((state: StateType) => state.onionPaths.snodePath); const onionNodes = useSelector((state: StateType) => state.onionPaths.snodePath);
const confirmModalState = useSelector((state: StateType) => state);
console.log('onion path: ', confirmModalState);
const onionPath = onionNodes.path; const onionPath = onionNodes.path;
// including the device and destination in calculation // including the device and destination in calculation
const glowDuration = onionPath.length + 2; const glowDuration = onionPath.length + 2;

@ -33,9 +33,13 @@ import { OpenGroupManagerV2 } from '../../opengroup/opengroupV2/OpenGroupManager
import { loadDefaultRooms } from '../../opengroup/opengroupV2/ApiUtil'; import { loadDefaultRooms } from '../../opengroup/opengroupV2/ApiUtil';
import { forceRefreshRandomSnodePool } from '../../session/snode_api/snodePool'; import { forceRefreshRandomSnodePool } from '../../session/snode_api/snodePool';
import { SwarmPolling } from '../../session/snode_api/swarmPolling'; import { SwarmPolling } from '../../session/snode_api/swarmPolling';
import _ from 'lodash'; import _, { divide } from 'lodash';
import { ActionPanelOnionStatusLight, OnionPathModal } from '../OnionStatusDialog'; import { ActionPanelOnionStatusLight, OnionPathModal } from '../OnionStatusDialog';
import { EditProfileDialog } from '../EditProfileDialog'; import { EditProfileDialog } from '../EditProfileDialog';
import { StateType } from '../../state/reducer';
import { updateConfirmModal } from "../../state/ducks/modalDialog";
import { useInView } from 'react-intersection-observer';
import { SessionConfirm } from './SessionConfirm';
// tslint:disable-next-line: no-import-side-effect no-submodule-imports // tslint:disable-next-line: no-import-side-effect no-submodule-imports
@ -72,9 +76,14 @@ const Section = (props: {
/* tslint:disable:no-void-expression */ /* tslint:disable:no-void-expression */
if (type === SectionType.Profile) { if (type === SectionType.Profile) {
// window.showEditProfileDialog(); // window.showEditProfileDialog();
console.log("edit profile");
// window.inboxStore?.dispatch(updateConfirmModal({ title: "title test" }));
dispatch(updateConfirmModal({ title: "title test" }));
// setModal(<EditProfileDialog2 onClose={() => setModal(null)}></EditProfileDialog2>); // setModal(<EditProfileDialog2 onClose={() => setModal(null)}></EditProfileDialog2>);
setModal(<EditProfileDialog onClose={handleModalClose} theme={theme} ></EditProfileDialog>); // setModal(<EditProfileDialog onClose={handleModalClose} theme={theme} ></EditProfileDialog>);
} else if (type === SectionType.Moon) { } else if (type === SectionType.Moon) {
const themeFromSettings = window.Events.getThemeSetting(); const themeFromSettings = window.Events.getThemeSetting();
const updatedTheme = themeFromSettings === 'dark' ? 'light' : 'dark'; const updatedTheme = themeFromSettings === 'dark' ? 'light' : 'dark';
@ -260,12 +269,31 @@ export const ActionsPanel = () => {
void forceRefreshRandomSnodePool(); void forceRefreshRandomSnodePool();
}, DAYS * 1); }, DAYS * 1);
const formatLog = (s: any ) => {
console.log("@@@@:: ", s);
}
// const confirmModalState = useSelector((state: StateType) => state);
const confirmModalState = useSelector((state: StateType) => state.confirmModal);
console.log('@@@ confirm modal state', confirmModalState);
// formatLog(confirmModalState.modalState.title);
formatLog(confirmModalState);
// formatLog(confirmModalState2);
return ( return (
<> <>
{modal ? modal : null} {/* {modal ? modal : null} */}
{/* { confirmModalState && confirmModalState.title ? <div>{confirmModalState.title}</div> : null} */}
{ confirmModalState ? <SessionConfirm {...confirmModalState} />: null}
<div className="module-left-pane__sections-container"> <div className="module-left-pane__sections-container">
<Section <Section
setModal={setModal} // setModal={setModal}
type={SectionType.Profile} type={SectionType.Profile}
avatarPath={ourPrimaryConversation.avatarPath} avatarPath={ourPrimaryConversation.avatarPath}
/> />
@ -275,7 +303,9 @@ export const ActionsPanel = () => {
<SessionToastContainer /> <SessionToastContainer />
<Section setModal={setModal} type={SectionType.PathIndicator} /> <Section
setModal={setModal}
type={SectionType.PathIndicator} />
<Section type={SectionType.Moon} /> <Section type={SectionType.Moon} />
</div> </div>
</> </>

@ -447,7 +447,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
return; return;
} }
this.setState({ loading: true }, async () => { this.setState({ loading: true }, async () => {
const groupCreated = await MainViewController.createClosedGroup(groupName, groupMembers, setModal); const groupCreated = await MainViewController.createClosedGroup(groupName, groupMembers);
if (groupCreated) { if (groupCreated) {
this.handleToggleOverlay(undefined); this.handleToggleOverlay(undefined);

@ -7,9 +7,9 @@ import { DefaultTheme, useTheme, withTheme } from 'styled-components';
import { SessionWrapperModal } from './SessionWrapperModal'; import { SessionWrapperModal } from './SessionWrapperModal';
type Props = { type Props = {
message: string; message?: string;
messageSub?: string; messageSub?: string;
title: string; title?: string;
onOk?: any; onOk?: any;
onClose?: any; onClose?: any;
onClickOk?: any; onClickOk?: any;
@ -27,7 +27,7 @@ type Props = {
const SessionConfirmInner = (props: Props) => { const SessionConfirmInner = (props: Props) => {
const { const {
title = '', title = '',
message, message = '',
messageSub = '', messageSub = '',
okTheme = SessionButtonColor.Primary, okTheme = SessionButtonColor.Primary,
closeTheme = SessionButtonColor.Primary, closeTheme = SessionButtonColor.Primary,

@ -359,7 +359,6 @@ export class SessionConversation extends React.Component<Props, State> {
onSetDisappearingMessages: conversation.updateExpirationTimer, onSetDisappearingMessages: conversation.updateExpirationTimer,
onDeleteMessages: conversation.deleteMessages, onDeleteMessages: conversation.deleteMessages,
onDeleteSelectedMessages: this.deleteSelectedMessages, onDeleteSelectedMessages: this.deleteSelectedMessages,
onChangeNickname: conversation.changeNickname,
onClearNickname: conversation.clearNickname, onClearNickname: conversation.clearNickname,
onCloseOverlay: () => { onCloseOverlay: () => {
this.setState({ selectedMessages: [] }); this.setState({ selectedMessages: [] });

@ -838,7 +838,7 @@ async function handleClosedGroupEncryptionKeyPairRequest(
return removeFromCache(envelope); return removeFromCache(envelope);
} }
export async function createClosedGroup(groupName: string, members: Array<string>, setModal: any) { export async function createClosedGroup(groupName: string, members: Array<string>) {
const setOfMembers = new Set(members); const setOfMembers = new Set(members);
const ourNumber = UserUtils.getOurPubKeyFromCache(); const ourNumber = UserUtils.getOurPubKeyFromCache();
@ -894,7 +894,6 @@ export async function createClosedGroup(groupName: string, members: Array<string
admins, admins,
encryptionKeyPair, encryptionKeyPair,
dbMessage, dbMessage,
setModal
); );
if (allInvitesSent) { if (allInvitesSent) {
@ -929,7 +928,6 @@ async function sendToGroupMembers(
admins: Array<string>, admins: Array<string>,
encryptionKeyPair: ECKeyPair, encryptionKeyPair: ECKeyPair,
dbMessage: MessageModel, dbMessage: MessageModel,
setModal: any,
isRetry: boolean = false, isRetry: boolean = false,
): Promise<any> { ): Promise<any> {
const promises = createInvitePromises( const promises = createInvitePromises(
@ -954,20 +952,10 @@ async function sendToGroupMembers(
// setModal(<SessionConfirm message={'hi'} title={invitesTitle} />) // setModal(<SessionConfirm message={'hi'} title={invitesTitle} />)
setModal( window.confirmationDialog({
<SessionConfirm title: invitesTitle,
title={title} message: window.i18n('closedGroupInviteSuccessMessage'),
message={message} });
onClickOk={deleteAccount}
okTheme={SessionButtonColor.Danger}
onClickClose={clearModal}
/>)
)
// window.confirmationDialog({
// title: invitesTitle,
// message: window.i18n('closedGroupInviteSuccessMessage'),
// });
} }
return allInvitesSent; return allInvitesSent;
} else { } else {
@ -1001,7 +989,6 @@ async function sendToGroupMembers(
admins, admins,
encryptionKeyPair, encryptionKeyPair,
dbMessage, dbMessage,
setModal,
isRetrySend isRetrySend
); );
} }

@ -0,0 +1,93 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { DefaultTheme } from 'styled-components';
import { SessionIconSize, SessionIconType } from '../../components/session/icon';
import { SessionButtonColor } from '../../components/session/SessionButton';
// import { OpenGroupV2InfoJoinable } from '../../opengroup/opengroupV2/ApiUtil';
// export type DefaultRoomsState = Array<OpenGroupV2InfoJoinable>;
// const initialState: DefaultRoomsState = [];
// /**
// * Payload to dispatch to update the base64 data of a default room
// */
// export type Base64Update = {
// base64Data: string;
// roomId: string;
// };
// /**
// * This slice is the one holding the default joinable rooms fetched once in a while from the default opengroup v2 server.
// */
// const defaultRoomsSlice = createSlice({
// name: 'defaultRooms',
// initialState,
// reducers: {
// updateDefaultRooms(state, action) {
// window.log.warn('updating default rooms', action.payload);
// return action.payload as DefaultRoomsState;
// },
// updateDefaultBase64RoomData(state, action: PayloadAction<Base64Update>) {
// const payload = action.payload;
// const newState = state.map(room => {
// if (room.id === payload.roomId) {
// return {
// ...room,
// base64Data: payload.base64Data,
// };
// }
// return room;
// });
// return newState;
// },
// },
// });
// const { actions, reducer } = defaultRoomsSlice;
// export const { updateDefaultRooms, updateDefaultBase64RoomData } = actions;
// export const defaultRoomReducer = reducer;
export type ConfirmModalState = {
message?: string;
messageSub?: string;
title?: string;
onOk?: any;
onClose?: any;
onClickOk?: any;
onClickClose?: any;
okText?: string;
cancelText?: string;
hideCancel?: boolean;
okTheme?: SessionButtonColor;
closeTheme?: SessionButtonColor;
sessionIcon?: SessionIconType;
iconSize?: SessionIconSize;
theme?: DefaultTheme;
} | null;
const initialState: ConfirmModalState = null;
// const initialState: any = { idk: 'hi'};
const confirmModalSlice = createSlice({
name: 'confirmModal',
initialState,
reducers: {
// updateConfirmModal(state, action: PayloadAction<ConfirmModalState>) {
updateConfirmModal(state, action: any) {
// return action.payload;
// state.title = action.payload;
state = action.payload;
return action.payload;
// state.confirmModal = action.payload;
}
}
})
const { actions, reducer } = confirmModalSlice;
export const { updateConfirmModal } = actions;
export const confirmModalReducer = reducer;

@ -1,17 +1,10 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import _, { forEach } from 'underscore';
import { SnodePath, Snode } from '../../session/onions/index'; import { SnodePath, Snode } from '../../session/onions/index';
export type OnionState = { export type OnionState = {
// nodes: Array<OnionPathNodeType>;
// path: SnodePath;
snodePath: SnodePath; snodePath: SnodePath;
}; };
// const initialState: OnionState = {
// // nodes: new Array<OnionPathNodeType>(),
// nodes: new Array<Snode>(),
// };
const initialState = { const initialState = {
snodePath: { snodePath: {
@ -32,8 +25,6 @@ const onionSlice = createSlice({
let isEqual = JSON.stringify(state, null, 2) == JSON.stringify(newPayload, null, 2); let isEqual = JSON.stringify(state, null, 2) == JSON.stringify(newPayload, null, 2);
return isEqual ? state : newPayload; return isEqual ? state : newPayload;
return newPayload;
}, },
}, },
}); });

@ -6,8 +6,8 @@ import { reducer as user, UserStateType } from './ducks/user';
import { reducer as theme, ThemeStateType } from './ducks/theme'; import { reducer as theme, ThemeStateType } from './ducks/theme';
import { reducer as section, SectionStateType } from './ducks/section'; import { reducer as section, SectionStateType } from './ducks/section';
import { defaultRoomReducer as defaultRooms, DefaultRoomsState } from './ducks/defaultRooms'; import { defaultRoomReducer as defaultRooms, DefaultRoomsState } from './ducks/defaultRooms';
import { defaultOnionReducer as onionPaths, OnionState } from './ducks/onion'; import { defaultOnionReducer as onionPaths, OnionState } from './ducks/onion';
import { confirmModalReducer as confirmModal, ConfirmModalState } from "./ducks/modalDialog";
export type StateType = { export type StateType = {
search: SearchStateType; search: SearchStateType;
@ -19,6 +19,9 @@ export type StateType = {
defaultRooms: DefaultRoomsState; defaultRooms: DefaultRoomsState;
onionPaths: OnionState; onionPaths: OnionState;
confirmModal: ConfirmModalState
// modalState: ConfirmModalState
}; };
export const reducers = { export const reducers = {
@ -31,8 +34,8 @@ export const reducers = {
theme, theme,
section, section,
defaultRooms, defaultRooms,
onionPaths, onionPaths,
confirmModal
}; };
// Making this work would require that our reducer signature supported AnyAction, not // Making this work would require that our reducer signature supported AnyAction, not

6
ts/window.d.ts vendored

@ -96,5 +96,11 @@ declare global {
darkTheme: DefaultTheme; darkTheme: DefaultTheme;
LokiPushNotificationServer: any; LokiPushNotificationServer: any;
LokiPushNotificationServerApi: any; LokiPushNotificationServerApi: any;
confirmationDialog: any;
}
window.confirmationDialog = () => {
console.log("confirmation dialog stub called");
} }
} }

Loading…
Cancel
Save