Chore: Evaluate NotificationPreferencesView - Typescript (#4099)
This commit is contained in:
parent
43e9964b7b
commit
b63f514df7
|
@ -213,6 +213,7 @@ export interface IServerRoom extends IRocketChatRecord {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRoomNotifications {
|
export interface IRoomNotifications {
|
||||||
|
[key: string]: any;
|
||||||
disableNotifications?: boolean;
|
disableNotifications?: boolean;
|
||||||
muteGroupMentions?: boolean;
|
muteGroupMentions?: boolean;
|
||||||
hideUnreadStatus?: boolean;
|
hideUnreadStatus?: boolean;
|
||||||
|
@ -221,3 +222,5 @@ export interface IRoomNotifications {
|
||||||
mobilePushNotifications?: TNotifications;
|
mobilePushNotifications?: TNotifications;
|
||||||
emailNotifications?: TNotifications;
|
emailNotifications?: TNotifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type TRoomNotificationsModel = IRoomNotifications & Model;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { NavigatorScreenParams } from '@react-navigation/core';
|
import { NavigatorScreenParams } from '@react-navigation/core';
|
||||||
import { TextInputProps } from 'react-native';
|
import { TextInputProps } from 'react-native';
|
||||||
import Model from '@nozbe/watermelondb/Model';
|
|
||||||
|
|
||||||
import { IOptionsField } from '../views/NotificationPreferencesView/options';
|
import { IOptionsField } from '../views/NotificationPreferencesView/options';
|
||||||
import { IServer } from '../definitions/IServer';
|
import { IServer } from '../definitions/IServer';
|
||||||
|
@ -101,7 +100,7 @@ export type ChatsStackParamList = {
|
||||||
DirectoryView: undefined;
|
DirectoryView: undefined;
|
||||||
NotificationPrefView: {
|
NotificationPrefView: {
|
||||||
rid: string;
|
rid: string;
|
||||||
room: Model;
|
room: TSubscriptionModel;
|
||||||
};
|
};
|
||||||
ForwardLivechatView: {
|
ForwardLivechatView: {
|
||||||
rid: string;
|
rid: string;
|
||||||
|
|
|
@ -2,7 +2,6 @@ import React from 'react';
|
||||||
import { StyleSheet, Switch, Text } from 'react-native';
|
import { StyleSheet, Switch, Text } from 'react-native';
|
||||||
import { RouteProp } from '@react-navigation/core';
|
import { RouteProp } from '@react-navigation/core';
|
||||||
import { StackNavigationProp } from '@react-navigation/stack';
|
import { StackNavigationProp } from '@react-navigation/stack';
|
||||||
import Model from '@nozbe/watermelondb/Model';
|
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import { Observable, Subscription } from 'rxjs';
|
||||||
|
|
||||||
import database from '../../lib/database';
|
import database from '../../lib/database';
|
||||||
|
@ -17,7 +16,7 @@ import log, { events, logEvent } from '../../utils/log';
|
||||||
import sharedStyles from '../Styles';
|
import sharedStyles from '../Styles';
|
||||||
import { IOptionsField, OPTIONS } from './options';
|
import { IOptionsField, OPTIONS } from './options';
|
||||||
import { ChatsStackParamList } from '../../stacks/types';
|
import { ChatsStackParamList } from '../../stacks/types';
|
||||||
import { IRoomNotifications } from '../../definitions';
|
import { IRoomNotifications, TRoomNotificationsModel } from '../../definitions';
|
||||||
import { Services } from '../../lib/services';
|
import { Services } from '../../lib/services';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
@ -27,23 +26,27 @@ const styles = StyleSheet.create({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
interface INotificationPreferencesView {
|
interface INotificationPreferencesViewProps {
|
||||||
navigation: StackNavigationProp<ChatsStackParamList, 'NotificationPrefView'>;
|
navigation: StackNavigationProp<ChatsStackParamList, 'NotificationPrefView'>;
|
||||||
route: RouteProp<ChatsStackParamList, 'NotificationPrefView'>;
|
route: RouteProp<ChatsStackParamList, 'NotificationPrefView'>;
|
||||||
theme: TSupportedThemes;
|
theme: TSupportedThemes;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NotificationPreferencesView extends React.Component<INotificationPreferencesView, any> {
|
interface INotificationPreferencesViewState {
|
||||||
|
room: TRoomNotificationsModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
class NotificationPreferencesView extends React.Component<INotificationPreferencesViewProps, INotificationPreferencesViewState> {
|
||||||
static navigationOptions = () => ({
|
static navigationOptions = () => ({
|
||||||
title: I18n.t('Notification_Preferences')
|
title: I18n.t('Notification_Preferences')
|
||||||
});
|
});
|
||||||
|
|
||||||
private mounted: boolean;
|
private mounted: boolean;
|
||||||
private rid: string;
|
private rid: string;
|
||||||
private roomObservable?: Observable<Model>;
|
private roomObservable?: Observable<TRoomNotificationsModel>;
|
||||||
private subscription?: Subscription;
|
private subscription?: Subscription;
|
||||||
|
|
||||||
constructor(props: INotificationPreferencesView) {
|
constructor(props: INotificationPreferencesViewProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.mounted = false;
|
this.mounted = false;
|
||||||
this.rid = props.route.params?.rid ?? '';
|
this.rid = props.route.params?.rid ?? '';
|
||||||
|
@ -53,7 +56,7 @@ class NotificationPreferencesView extends React.Component<INotificationPreferenc
|
||||||
};
|
};
|
||||||
if (room && room.observe) {
|
if (room && room.observe) {
|
||||||
this.roomObservable = room.observe();
|
this.roomObservable = room.observe();
|
||||||
this.subscription = this.roomObservable.subscribe((changes: any) => {
|
this.subscription = this.roomObservable.subscribe(changes => {
|
||||||
if (this.mounted) {
|
if (this.mounted) {
|
||||||
this.setState({ room: changes });
|
this.setState({ room: changes });
|
||||||
} else {
|
} else {
|
||||||
|
@ -83,7 +86,7 @@ class NotificationPreferencesView extends React.Component<INotificationPreferenc
|
||||||
try {
|
try {
|
||||||
await db.write(async () => {
|
await db.write(async () => {
|
||||||
await room.update(
|
await room.update(
|
||||||
protectedFunction((r: any) => {
|
protectedFunction((r: IRoomNotifications) => {
|
||||||
r[key] = value;
|
r[key] = value;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -100,7 +103,7 @@ class NotificationPreferencesView extends React.Component<INotificationPreferenc
|
||||||
|
|
||||||
await db.write(async () => {
|
await db.write(async () => {
|
||||||
await room.update(
|
await room.update(
|
||||||
protectedFunction((r: any) => {
|
protectedFunction((r: IRoomNotifications) => {
|
||||||
r[key] = room[key];
|
r[key] = room[key];
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue