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