add loading for leaving opengroup dialog

pull/1734/head
Audric Ackermann 4 years ago
parent e4dae7f408
commit 15aa6b5ef9
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -17,7 +17,7 @@ export interface SessionConfirmDialogProps {
title?: string; title?: string;
onOk?: any; onOk?: any;
onClose?: any; onClose?: any;
onClickOk?: () => any; onClickOk?: () => Promise<void> | void;
onClickClose?: () => any; onClickClose?: () => any;
okText?: string; okText?: string;
cancelText?: string; cancelText?: string;

@ -1,84 +1,63 @@
import React from 'react'; import React, { useEffect, useState } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { updateConfirmModal } from '../../state/ducks/modalDialog'; import { updateConfirmModal } from '../../state/ducks/modalDialog';
import { useDispatch } from 'react-redux';
interface Props { type Props = {
active: boolean; active: boolean;
onClick: any; onClick: () => void;
confirmationDialogParams?: any | undefined; confirmationDialogParams?: any | undefined;
};
updateConfirmModal?: any; export const SessionToggle = (props: Props) => {
} const [active, setActive] = useState(false);
interface State { const dispatch = useDispatch();
active: boolean;
}
export class SessionToggle extends React.PureComponent<Props, State> {
public static defaultProps = {
onClick: () => null,
};
constructor(props: any) {
super(props);
this.clickHandler = this.clickHandler.bind(this);
const { active } = this.props;
this.state = { useEffect(() => {
active: active, setActive(props.active);
}; }, []);
}
public render() {
return (
<div
className={classNames('session-toggle', this.state.active ? 'active' : '')}
role="button"
onClick={this.clickHandler}
>
<div className="knob" />
</div>
);
}
private clickHandler(event: any) { const clickHandler = (event: any) => {
const stateManager = (e: any) => { const stateManager = (e: any) => {
this.setState({ setActive(!active);
active: !this.state.active, e.stopPropagation();
}); props.onClick();
if (this.props.onClick) {
e.stopPropagation();
this.props.onClick();
}
}; };
if ( if (props.confirmationDialogParams && props.confirmationDialogParams.shouldShowConfirm()) {
this.props.confirmationDialogParams &&
this.props.updateConfirmModal &&
this.props.confirmationDialogParams.shouldShowConfirm()
) {
// If item needs a confirmation dialog to turn ON, render it // If item needs a confirmation dialog to turn ON, render it
const closeConfirmModal = () => { const closeConfirmModal = () => {
this.props.updateConfirmModal(null); dispatch(updateConfirmModal(null));
}; };
this.props.updateConfirmModal({ dispatch(
onClickOk: () => { updateConfirmModal({
stateManager(event); onClickOk: () => {
closeConfirmModal(); stateManager(event);
}, closeConfirmModal();
onClickClose: () => { },
this.props.updateConfirmModal(null); onClickClose: () => {
}, updateConfirmModal(null);
...this.props.confirmationDialogParams, },
updateConfirmModal, ...props.confirmationDialogParams,
}); updateConfirmModal,
})
);
return; return;
} }
stateManager(event); stateManager(event);
} };
}
return (
<div
className={classNames('session-toggle', active ? 'active' : '')}
role="button"
onClick={clickHandler}
>
<div className="knob" />
</div>
);
};

@ -25,6 +25,7 @@ import {
showUpdateGroupNameByConvoId, showUpdateGroupNameByConvoId,
unblockConvoById, unblockConvoById,
} from '../../../interactions/conversationInteractions'; } from '../../../interactions/conversationInteractions';
import { SessionButtonColor } from '../SessionButton';
function showTimerOptions( function showTimerOptions(
isPublic: boolean, isPublic: boolean,
@ -162,9 +163,9 @@ export function getDeleteContactMenuItem(
? window.i18n('leaveGroupConfirmation') ? window.i18n('leaveGroupConfirmation')
: window.i18n('deleteContactConfirmation'), : window.i18n('deleteContactConfirmation'),
onClickClose, onClickClose,
onClickOk: () => { okTheme: SessionButtonColor.Danger,
void getConversationController().deleteContact(conversationId); onClickOk: async () => {
onClickClose(); await getConversationController().deleteContact(conversationId);
}, },
}) })
); );

@ -1,4 +1,4 @@
import React from 'react'; import React, { useState } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import Slider from 'rc-slider'; import Slider from 'rc-slider';
@ -9,7 +9,7 @@ import { SessionSettingType } from './SessionSettings';
import { SessionRadioGroup } from '../SessionRadioGroup'; import { SessionRadioGroup } from '../SessionRadioGroup';
import { SessionConfirmDialogProps } from '../SessionConfirm'; import { SessionConfirmDialogProps } from '../SessionConfirm';
interface Props { type Props = {
title?: string; title?: string;
description?: string; description?: string;
type: SessionSettingType | undefined; type: SessionSettingType | undefined;
@ -19,112 +19,79 @@ interface Props {
onSliderChange?: any; onSliderChange?: any;
content: any; content: any;
confirmationDialogParams?: SessionConfirmDialogProps; confirmationDialogParams?: SessionConfirmDialogProps;
};
// for updating modal in redux export const SessionSettingListItem = (props: Props) => {
updateConfirmModal?: any; const handleSlider = (value: any) => {
} if (props.onSliderChange) {
props.onSliderChange(value);
interface State { }
sliderValue: number | null;
}
export class SessionSettingListItem extends React.Component<Props, State> { setSliderValue(value);
public static defaultProps = {
inline: true,
}; };
public constructor(props: Props) { const [sliderValue, setSliderValue] = useState(null);
super(props);
this.state = {
sliderValue: null,
};
this.handleClick = this.handleClick.bind(this);
}
public render(): JSX.Element {
const { title, description, type, value, content } = this.props;
const inline =
!!type && ![SessionSettingType.Options, SessionSettingType.Slider].includes(type);
const currentSliderValue = const { title, description, type, value, content } = props;
type === SessionSettingType.Slider && (this.state.sliderValue || value); const inline = !!type && ![SessionSettingType.Options, SessionSettingType.Slider].includes(type);
return ( const currentSliderValue = type === SessionSettingType.Slider && (sliderValue || value);
<div className={classNames('session-settings-item', inline && 'inline')}>
<div className="session-settings-item__info">
<div className="session-settings-item__title">{title}</div>
{description && <div className="session-settings-item__description">{description}</div>} return (
</div> <div className={classNames('session-settings-item', inline && 'inline')}>
<div className="session-settings-item__info">
<div className="session-settings-item__title">{title}</div>
<div className="session-settings-item__content"> {description && <div className="session-settings-item__description">{description}</div>}
{type === SessionSettingType.Toggle && ( </div>
<div className="session-settings-item__selection">
<SessionToggle
active={Boolean(value)}
onClick={this.handleClick}
confirmationDialogParams={this.props.confirmationDialogParams}
updateConfirmModal={this.props.updateConfirmModal}
/>
</div>
)}
{type === SessionSettingType.Button && ( <div className="session-settings-item__content">
<SessionButton {type === SessionSettingType.Toggle && (
text={content.buttonText} <div className="session-settings-item__selection">
buttonColor={content.buttonColor} <SessionToggle
onClick={this.handleClick} active={Boolean(value)}
onClick={() => props.onClick?.()}
confirmationDialogParams={props.confirmationDialogParams}
/> />
)} </div>
)}
{type === SessionSettingType.Options && (
<SessionRadioGroup {type === SessionSettingType.Button && (
initialItem={content.options.initalItem} <SessionButton
group={content.options.group} text={content.buttonText}
items={content.options.items} buttonColor={content.buttonColor}
onClick={(selectedRadioValue: string) => { onClick={() => props.onClick?.()}
this.props.onClick(selectedRadioValue); />
}} )}
{type === SessionSettingType.Options && (
<SessionRadioGroup
initialItem={content.options.initalItem}
group={content.options.group}
items={content.options.items}
onClick={(selectedRadioValue: string) => {
props.onClick(selectedRadioValue);
}}
/>
)}
{type === SessionSettingType.Slider && (
<div className="slider-wrapper">
<Slider
dots={true}
step={content.step}
min={content.min}
max={content.max}
defaultValue={currentSliderValue}
onAfterChange={handleSlider}
/> />
)}
{type === SessionSettingType.Slider && ( <div className="slider-info">
<div className="slider-wrapper"> <p>{content.info(currentSliderValue)}</p>
<Slider
dots={true}
step={content.step}
min={content.min}
max={content.max}
defaultValue={currentSliderValue}
onAfterChange={sliderValue => {
this.handleSlider(sliderValue);
}}
/>
<div className="slider-info">
<p>{content.info(currentSliderValue)}</p>
</div>
</div> </div>
)} </div>
</div> )}
</div> </div>
); </div>
} );
};
private handleClick() {
if (this.props.onClick) {
this.props.onClick();
}
}
private handleSlider(value: any) {
if (this.props.onSliderChange) {
this.props.onSliderChange(value);
}
this.setState({
sliderValue: value,
});
}
}

@ -40,7 +40,6 @@ export interface SettingsViewProps {
// pass the conversation as props, so our render is called everytime they change. // pass the conversation as props, so our render is called everytime they change.
// we have to do this to make the list refresh on unblock() // we have to do this to make the list refresh on unblock()
conversations?: ConversationLookupType; conversations?: ConversationLookupType;
updateConfirmModal?: any;
} }
interface State { interface State {
@ -156,7 +155,6 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
onSliderChange={sliderFn} onSliderChange={sliderFn}
content={content} content={content}
confirmationDialogParams={setting.confirmationDialogParams} confirmationDialogParams={setting.confirmationDialogParams}
updateConfirmModal={this.props.updateConfirmModal}
/> />
)} )}
</div> </div>

@ -36,6 +36,7 @@ import { getDecryptedMediaUrl } from '../session/crypto/DecryptedAttachmentsMana
import { IMAGE_JPEG } from '../types/MIME'; import { IMAGE_JPEG } from '../types/MIME';
import { FSv2 } from '../fileserver'; import { FSv2 } from '../fileserver';
import { fromBase64ToArray, toHex } from '../session/utils/String'; import { fromBase64ToArray, toHex } from '../session/utils/String';
import { SessionButtonColor } from '../components/session/SessionButton';
export const getCompleteUrlForV2ConvoId = async (convoId: string) => { export const getCompleteUrlForV2ConvoId = async (convoId: string) => {
if (convoId.match(openGroupV2ConversationIdRegex)) { if (convoId.match(openGroupV2ConversationIdRegex)) {
@ -219,8 +220,8 @@ export function showLeaveGroupByConvoId(conversationId: string) {
updateConfirmModal({ updateConfirmModal({
title, title,
message, message,
onClickOk: () => { onClickOk: async () => {
void conversation.leaveClosedGroup(); await conversation.leaveClosedGroup();
onClickClose(); onClickClose();
}, },
onClickClose, onClickClose,
@ -302,8 +303,8 @@ export function deleteMessagesByConvoIdWithConfirmation(conversationId: string)
window?.inboxStore?.dispatch(updateConfirmModal(null)); window?.inboxStore?.dispatch(updateConfirmModal(null));
}; };
const onClickOk = () => { const onClickOk = async () => {
void deleteMessagesByConvoIdNoConfirmation(conversationId); await deleteMessagesByConvoIdNoConfirmation(conversationId);
onClickClose(); onClickClose();
}; };
@ -312,6 +313,7 @@ export function deleteMessagesByConvoIdWithConfirmation(conversationId: string)
title: window.i18n('deleteMessages'), title: window.i18n('deleteMessages'),
message: window.i18n('deleteConversationConfirmation'), message: window.i18n('deleteConversationConfirmation'),
onClickOk, onClickOk,
okTheme: SessionButtonColor.Danger,
onClickClose, onClickClose,
}) })
); );

@ -173,7 +173,9 @@ const acceptOpenGroupInvitationV2 = (completeUrl: string, roomName?: string) =>
updateConfirmModal({ updateConfirmModal({
title: window.i18n('joinOpenGroupAfterInvitationConfirmationTitle', roomName), title: window.i18n('joinOpenGroupAfterInvitationConfirmationTitle', roomName),
message: window.i18n('joinOpenGroupAfterInvitationConfirmationDesc', roomName), message: window.i18n('joinOpenGroupAfterInvitationConfirmationDesc', roomName),
onClickOk: () => joinOpenGroupV2WithUIEvents(completeUrl, true, false), onClickOk: async () => {
await joinOpenGroupV2WithUIEvents(completeUrl, true, false);
},
onClickClose, onClickClose,
}) })

Loading…
Cancel
Save