mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
add a toastUtils file and replace all pushToast calls in ts files
This commit is contained in:
parent
08433aa676
commit
d108630f22
|
@ -4,6 +4,7 @@ import { QRCode } from 'react-qr-svg';
|
|||
import { SessionModal } from './session/SessionModal';
|
||||
import { SessionButton, SessionButtonColor } from './session/SessionButton';
|
||||
import { SessionSpinner } from './session/SessionSpinner';
|
||||
import { ToastUtils } from '../session/utils';
|
||||
|
||||
interface Props {
|
||||
onClose: any;
|
||||
|
@ -280,7 +281,7 @@ export class DevicePairingDialog extends React.Component<Props, State> {
|
|||
errors: null,
|
||||
});
|
||||
this.closeDialog();
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('devicePairedSuccessfully'),
|
||||
type: 'success',
|
||||
});
|
||||
|
@ -365,7 +366,7 @@ export class DevicePairingDialog extends React.Component<Props, State> {
|
|||
|
||||
private triggerUnpairDevice() {
|
||||
const deviceUnpaired = () => {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('deviceUnpaired'),
|
||||
});
|
||||
this.closeDialog();
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
} from './session/icon';
|
||||
import { SessionModal } from './session/SessionModal';
|
||||
import { PillDivider } from './session/PillDivider';
|
||||
import { ToastUtils } from '../session/utils';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
@ -304,7 +305,7 @@ export class EditProfileDialog extends React.Component<Props, State> {
|
|||
private copySessionID(sessionID: string) {
|
||||
window.clipboard.writeText(sessionID);
|
||||
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('copiedSessionID'),
|
||||
type: 'success',
|
||||
id: 'copiedSessionID',
|
||||
|
|
|
@ -15,6 +15,7 @@ export const MainViewController = {
|
|||
};
|
||||
|
||||
import { ContactType } from './session/SessionMemberListItem';
|
||||
import { ToastUtils } from '../session/utils';
|
||||
|
||||
export class MessageView extends React.Component {
|
||||
public render() {
|
||||
|
@ -52,7 +53,7 @@ async function createClosedGroup(
|
|||
groupName.length === 0 ||
|
||||
groupName.length > window.CONSTANTS.MAX_GROUP_NAME_LENGTH
|
||||
) {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n(
|
||||
'invalidGroupName',
|
||||
window.CONSTANTS.MAX_GROUP_NAME_LENGTH
|
||||
|
@ -69,7 +70,7 @@ async function createClosedGroup(
|
|||
groupMembers.length === 0 ||
|
||||
groupMembers.length >= window.CONSTANTS.SMALL_GROUP_SIZE_LIMIT
|
||||
) {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n(
|
||||
'invalidGroupSize',
|
||||
window.CONSTANTS.SMALL_GROUP_SIZE_LIMIT
|
||||
|
|
|
@ -22,6 +22,7 @@ import {
|
|||
SessionClosableOverlayType,
|
||||
} from './SessionClosableOverlay';
|
||||
import { MainViewController } from '../MainViewController';
|
||||
import { ToastUtils } from '../../session/utils';
|
||||
|
||||
export interface Props {
|
||||
searchTerm: string;
|
||||
|
@ -192,7 +193,7 @@ export class LeftPaneContactSection extends React.Component<Props, State> {
|
|||
const error = validateNumber(sessionID, window.i18n);
|
||||
|
||||
if (error) {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: error,
|
||||
type: 'error',
|
||||
id: 'addContact',
|
||||
|
|
|
@ -30,6 +30,7 @@ import {
|
|||
SessionButtonType,
|
||||
} from './SessionButton';
|
||||
import { OpenGroup } from '../../session/types';
|
||||
import { ToastUtils } from '../../session/utils';
|
||||
|
||||
export interface Props {
|
||||
searchTerm: string;
|
||||
|
@ -416,7 +417,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
|
|||
const { openConversationInternal } = this.props;
|
||||
|
||||
if (!this.state.valuePasted && !this.props.searchTerm) {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('invalidNumberError'),
|
||||
type: 'error',
|
||||
id: 'invalidPubKey',
|
||||
|
@ -432,7 +433,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
|
|||
if (!error) {
|
||||
openConversationInternal(pubkey);
|
||||
} else {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: error,
|
||||
type: 'error',
|
||||
id: 'invalidPubKey',
|
||||
|
@ -454,7 +455,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
|
|||
|
||||
// Server URL valid?
|
||||
if (!OpenGroup.validate(serverUrl)) {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('noServerURL'),
|
||||
id: 'connectToServer',
|
||||
type: 'error',
|
||||
|
@ -465,7 +466,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
|
|||
|
||||
// Already connected?
|
||||
if (Boolean(await OpenGroup.getConversation(serverUrl))) {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('publicChatExists'),
|
||||
id: 'publicChatExists',
|
||||
type: 'error',
|
||||
|
@ -476,14 +477,14 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
|
|||
|
||||
// Connect to server
|
||||
try {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('connectingToServer'),
|
||||
id: 'connectToServer',
|
||||
type: 'success',
|
||||
});
|
||||
await OpenGroup.join(serverUrl, async () => {
|
||||
if (await OpenGroup.serverExists(serverUrl)) {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('connectToServerSuccess'),
|
||||
id: 'connectToServer',
|
||||
type: 'success',
|
||||
|
@ -507,7 +508,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
|
|||
}
|
||||
} catch (e) {
|
||||
window.console.error('Failed to connect to server:', e);
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('connectToServerFail'),
|
||||
id: 'connectToServer',
|
||||
type: 'error',
|
||||
|
@ -532,7 +533,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
|
|||
() => {
|
||||
this.handleToggleOverlay(undefined);
|
||||
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('closedGroupCreatedToastTitle'),
|
||||
type: 'success',
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@ import { trigger } from '../../shims/events';
|
|||
import { SessionHtmlRenderer } from './SessionHTMLRenderer';
|
||||
import { SessionIdEditable } from './SessionIdEditable';
|
||||
import { SessionSpinner } from './SessionSpinner';
|
||||
import { StringUtils } from '../../session/utils';
|
||||
import { StringUtils, ToastUtils } from '../../session/utils';
|
||||
|
||||
enum SignInMode {
|
||||
Default,
|
||||
|
@ -803,7 +803,7 @@ export class RegistrationTabs extends React.Component<{}, State> {
|
|||
|
||||
if (!trimName) {
|
||||
window.log.warn('invalid trimmed name for registration');
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('displayNameEmpty'),
|
||||
type: 'error',
|
||||
id: 'invalidDisplayName',
|
||||
|
@ -814,7 +814,7 @@ export class RegistrationTabs extends React.Component<{}, State> {
|
|||
|
||||
if (passwordErrorString) {
|
||||
window.log.warn('invalid password for registration');
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('invalidPassword'),
|
||||
type: 'error',
|
||||
id: 'invalidPassword',
|
||||
|
@ -826,7 +826,7 @@ export class RegistrationTabs extends React.Component<{}, State> {
|
|||
if (!!password && !passwordFieldsMatch) {
|
||||
window.log.warn('passwords does not match for registration');
|
||||
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('passwordsDoNotMatch'),
|
||||
type: 'error',
|
||||
id: 'invalidPassword',
|
||||
|
@ -864,7 +864,7 @@ export class RegistrationTabs extends React.Component<{}, State> {
|
|||
);
|
||||
trigger('openInbox');
|
||||
} catch (e) {
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: `Error: ${e.message || 'Something went wrong'}`,
|
||||
type: 'error',
|
||||
id: 'registrationError',
|
||||
|
@ -895,7 +895,7 @@ export class RegistrationTabs extends React.Component<{}, State> {
|
|||
// tslint:disable-next-line: no-backbone-get-set-outside-model
|
||||
if (window.textsecure.storage.get('secondaryDeviceStatus') === 'ongoing') {
|
||||
window.log.warn('registering secondary device already ongoing');
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('pairingOngoing'),
|
||||
type: 'error',
|
||||
id: 'pairingOngoing',
|
||||
|
@ -938,7 +938,7 @@ export class RegistrationTabs extends React.Component<{}, State> {
|
|||
const validationError = c.validateNumber();
|
||||
if (validationError) {
|
||||
onError('Invalid public key').ignore();
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('invalidNumberError'),
|
||||
type: 'error',
|
||||
id: 'invalidNumberError',
|
||||
|
|
|
@ -3,6 +3,7 @@ import React from 'react';
|
|||
import { SessionModal } from './SessionModal';
|
||||
import { SessionButton, SessionButtonColor } from './SessionButton';
|
||||
import { PasswordUtil } from '../../util/';
|
||||
import { ToastUtils } from '../../session/utils';
|
||||
export enum PasswordAction {
|
||||
Set = 'set',
|
||||
Change = 'change',
|
||||
|
@ -232,16 +233,12 @@ export class SessionPasswordModal extends React.Component<Props, State> {
|
|||
throw new Error(`Invalid action ${action}`);
|
||||
}
|
||||
|
||||
const toastParams = {
|
||||
ToastUtils.push({
|
||||
id: 'set-password-success-toast',
|
||||
type: action !== Remove ? 'success' : 'warning',
|
||||
title: title,
|
||||
description: description,
|
||||
type: action !== Remove ? 'success' : 'warning',
|
||||
icon: action !== Remove ? 'lock' : undefined,
|
||||
};
|
||||
|
||||
window.pushToast({
|
||||
id: 'set-password-success-toast',
|
||||
...toastParams,
|
||||
});
|
||||
|
||||
onSuccess(this.props.action);
|
||||
|
@ -265,7 +262,7 @@ export class SessionPasswordModal extends React.Component<Props, State> {
|
|||
)
|
||||
);
|
||||
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title,
|
||||
type: 'warning',
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||
|
||||
import { SessionModal } from './SessionModal';
|
||||
import { SessionButton } from './SessionButton';
|
||||
import { ToastUtils } from '../../session/utils';
|
||||
|
||||
interface Props {
|
||||
onClose: any;
|
||||
|
@ -212,7 +213,7 @@ export class SessionSeedModal extends React.Component<Props, State> {
|
|||
private copySeed(seed: string) {
|
||||
window.clipboard.writeText(seed);
|
||||
|
||||
window.pushToast({
|
||||
ToastUtils.push({
|
||||
title: window.i18n('copiedMnemonic'),
|
||||
type: 'success',
|
||||
id: 'copySeedToast',
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
import { BlockedNumberController, UserUtil } from '../../../util';
|
||||
import { MultiDeviceProtocol } from '../../../session/protocols';
|
||||
import { PubKey } from '../../../session/types';
|
||||
import { NumberUtils } from '../../../session/utils';
|
||||
import { NumberUtils, ToastUtils } from '../../../session/utils';
|
||||
|
||||
export enum SessionSettingCategory {
|
||||
Appearance = 'appearance',
|
||||
|
@ -103,7 +103,7 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
|
|||
if (category === SessionSettingCategory.Devices) {
|
||||
// special case for linked devices
|
||||
settings = this.getLinkedDeviceSettings();
|
||||
} else if(category === SessionSettingCategory.Blocked) {
|
||||
} else if (category === SessionSettingCategory.Blocked) {
|
||||
// special case for blocked user
|
||||
settings = this.getBlockedUserSettings();
|
||||
} else {
|
||||
|
|
10
ts/session/utils/Toast.ts
Normal file
10
ts/session/utils/Toast.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
export function push(options: {
|
||||
title: string;
|
||||
id?: string;
|
||||
description?: string;
|
||||
type?: 'success' | 'info' | 'warning' | 'error';
|
||||
icon?: string;
|
||||
shouldFade?: boolean;
|
||||
}) {
|
||||
window.pushToast(options);
|
||||
}
|
|
@ -6,6 +6,7 @@ import * as NumberUtils from './Number';
|
|||
import * as PromiseUtils from './Promise';
|
||||
import * as ProtobufUtils from './Protobuf';
|
||||
import * as MenuUtils from './Menu';
|
||||
import * as ToastUtils from './Toast';
|
||||
|
||||
export * from './Attachments';
|
||||
export * from './TypedEmitter';
|
||||
|
@ -20,4 +21,5 @@ export {
|
|||
PromiseUtils,
|
||||
ProtobufUtils,
|
||||
MenuUtils,
|
||||
ToastUtils,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue