Notifications: Various fixes for toasts
This commit is contained in:
parent
fe5bb69e1a
commit
1a7cce4e42
@ -67,3 +67,27 @@ export type ApiNotifyException = {
|
|||||||
isSilent?: boolean;
|
isSilent?: boolean;
|
||||||
shouldShowPreviews?: boolean;
|
shouldShowPreviews?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ApiNotification = {
|
||||||
|
localId: string;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ApiError = {
|
||||||
|
message: string;
|
||||||
|
hasErrorKey?: boolean;
|
||||||
|
isSlowMode?: boolean;
|
||||||
|
textParams?: Record<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ApiFieldError = {
|
||||||
|
field: string;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ApiInviteInfo = {
|
||||||
|
title: string;
|
||||||
|
hash: string;
|
||||||
|
isChannel?: boolean;
|
||||||
|
participantsCount?: number;
|
||||||
|
};
|
||||||
|
|||||||
@ -9,7 +9,9 @@ import {
|
|||||||
ApiFormattedText, ApiMessage, ApiPhoto, ApiPoll, ApiStickerSet, ApiThreadInfo,
|
ApiFormattedText, ApiMessage, ApiPhoto, ApiPoll, ApiStickerSet, ApiThreadInfo,
|
||||||
} from './messages';
|
} from './messages';
|
||||||
import { ApiUser, ApiUserFullInfo, ApiUserStatus } from './users';
|
import { ApiUser, ApiUserFullInfo, ApiUserStatus } from './users';
|
||||||
import { ApiNotifyException, ApiSessionData } from './misc';
|
import {
|
||||||
|
ApiError, ApiInviteInfo, ApiNotifyException, ApiSessionData,
|
||||||
|
} from './misc';
|
||||||
|
|
||||||
export type ApiUpdateReady = {
|
export type ApiUpdateReady = {
|
||||||
'@type': 'updateApiReady';
|
'@type': 'updateApiReady';
|
||||||
@ -307,29 +309,6 @@ export type ApiUpdateMessageImage = {
|
|||||||
dataUri: string;
|
dataUri: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ApiNotification = {
|
|
||||||
message: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ApiError = {
|
|
||||||
message: string;
|
|
||||||
hasErrorKey?: boolean;
|
|
||||||
isSlowMode?: boolean;
|
|
||||||
textParams?: Record<string, string>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ApiFieldError = {
|
|
||||||
field: string;
|
|
||||||
message: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ApiInviteInfo = {
|
|
||||||
title: string;
|
|
||||||
hash: string;
|
|
||||||
isChannel?: boolean;
|
|
||||||
participantsCount?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ApiUpdateError = {
|
export type ApiUpdateError = {
|
||||||
'@type': 'error';
|
'@type': 'error';
|
||||||
error: ApiError;
|
error: ApiError;
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import { GlobalActions } from '../../global/types';
|
|||||||
import { ApiNotification } from '../../api/types';
|
import { ApiNotification } from '../../api/types';
|
||||||
|
|
||||||
import { pick } from '../../util/iteratees';
|
import { pick } from '../../util/iteratees';
|
||||||
|
import renderText from '../common/helpers/renderText';
|
||||||
|
|
||||||
import Notification from '../ui/Notification';
|
import Notification from '../ui/Notification';
|
||||||
import renderText from '../common/helpers/renderText';
|
|
||||||
|
|
||||||
type StateProps = {
|
type StateProps = {
|
||||||
notifications: ApiNotification[];
|
notifications: ApiNotification[];
|
||||||
@ -22,10 +22,10 @@ const Notifications: FC<StateProps & DispatchProps> = ({ notifications, dismissN
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="Notifications">
|
<div id="Notifications">
|
||||||
{notifications.map(({ message }) => (
|
{notifications.map(({ message, localId }) => (
|
||||||
<Notification
|
<Notification
|
||||||
message={renderText(message, ['emoji', 'br', 'links', 'simple_markdown'])}
|
message={renderText(message, ['emoji', 'br', 'links', 'simple_markdown'])}
|
||||||
onDismiss={dismissNotification}
|
onDismiss={() => dismissNotification({ localId })}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import React, {
|
import React, {
|
||||||
FC,
|
FC,
|
||||||
memo,
|
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
useRef,
|
useRef,
|
||||||
@ -81,4 +80,4 @@ const Notification: FC<OwnProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(Notification);
|
export default Notification;
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
import { addReducer } from '../../../lib/teact/teactn';
|
import { addReducer } from '../../../lib/teact/teactn';
|
||||||
|
|
||||||
import { GlobalState } from '../../../global/types';
|
import { GlobalState } from '../../../global/types';
|
||||||
|
import { ApiError } from '../../../api/types';
|
||||||
|
|
||||||
import { IS_SINGLE_COLUMN_LAYOUT, IS_TABLET_COLUMN_LAYOUT } from '../../../util/environment';
|
import { IS_SINGLE_COLUMN_LAYOUT, IS_TABLET_COLUMN_LAYOUT } from '../../../util/environment';
|
||||||
import getReadableErrorText from '../../../util/getReadableErrorText';
|
import getReadableErrorText from '../../../util/getReadableErrorText';
|
||||||
import { selectCurrentMessageList } from '../../selectors';
|
import { selectCurrentMessageList } from '../../selectors';
|
||||||
import { ApiError } from '../../../api/types';
|
import generateIdFor from '../../../util/generateIdFor';
|
||||||
|
|
||||||
const MAX_STORED_EMOJIS = 18; // Represents two rows of recent emojis
|
const MAX_STORED_EMOJIS = 18; // Represents two rows of recent emojis
|
||||||
|
|
||||||
@ -131,6 +132,7 @@ addReducer('addRecentSticker', (global, action, payload) => {
|
|||||||
|
|
||||||
addReducer('showNotification', (global, actions, payload) => {
|
addReducer('showNotification', (global, actions, payload) => {
|
||||||
const notification = payload!;
|
const notification = payload!;
|
||||||
|
notification.localId = generateIdFor({});
|
||||||
|
|
||||||
const newNotifications = [...global.notifications];
|
const newNotifications = [...global.notifications];
|
||||||
const existingNotificationIndex = newNotifications.findIndex((n) => n.message === notification.message);
|
const existingNotificationIndex = newNotifications.findIndex((n) => n.message === notification.message);
|
||||||
@ -146,10 +148,8 @@ addReducer('showNotification', (global, actions, payload) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
addReducer('dismissNotification', (global) => {
|
addReducer('dismissNotification', (global, actions, payload) => {
|
||||||
const newNotifications = [...global.notifications];
|
const newNotifications = global.notifications.filter(({ localId }) => localId !== payload.localId);
|
||||||
|
|
||||||
newNotifications.pop();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...global,
|
...global,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user