* modifying setting option * navigates to email screen * UI construction [in progress] * hooking up withObservables * email settings - need to save now * adding a bit of paddings * setting initial value * Update notification_email.tsx * UI Polish - main setting screen * UI Polish - Mention * UI Polish - Notification main screen * code clean up * code clean up * UI Polish Notification * UI Polish * code clean up * UI Polish - OOO * fix observable for email interval * fix ooo * fix ooo * added setting_row_label component * further clean up * UI Polish - Display - [ IN PROGRESS ] * UI Polish - Display - [ IN PROGRESS ] * UI Polish - Timezone Select [ IN PROGRESS ] * Update index.test.tsx.snap * Update app/screens/settings/notification_email/notification_email.tsx Co-authored-by: Daniel Espino García <larkox@gmail.com> * refactor after review * update option_item so that action can accept type React.Dispatch<React.SetStateAction * UI - Polish - Display Theme UI Polish - Display/Theme [ IN PROGRESS ] UI - Polish - Display Save button * UI - Polish - Display Clock UI - Polish - Display Clock * UI Polish - Display - Timezone UI Polish - Display Timezone added the save button UI Polish - Display/TZ UI Polish - Display Timezone minor refactoring code clean up code clean up * UI Polish - Adv Settings * UI Polish - Settings/About UI Polish - Settings/About * UI Polish - Radio Button UI Polish - Radio Button * UI Polish - Android Polishing [ IN PROGRESS ] * UI Polish - Timezone fix timezone fix timezone select fix timezone select ui Update index.tsx * UI Polish - Display/Theme UI Polish - Custom Theme - Checked Radio btn * Update en.json * tweaks to settings styles * further tweaks to spacing * Revert "Merge branch 'gekidou-settings-finale' of https://github.com/mattermost/mattermost-mobile into gekidou-settings-finale" This reverts commit f1fd26987ee5b1854366573b5822c9d0b919d83a, reversing changes made to 684ba6a19c5962353ce61add2cc9cf10c8f9d3d4. * added space before 'default' * Update index.test.tsx.snap * Revert "Revert "Merge branch 'gekidou-settings-finale' of https://github.com/mattermost/mattermost-mobile into gekidou-settings-finale"" This reverts commit ce77127cb20a3668510a82122325f1642ec7bb60. Co-authored-by: Daniel Espino García <larkox@gmail.com> Co-authored-by: Matthew Birtch <mattbirtch@gmail.com>
111 lines
4.1 KiB
TypeScript
111 lines
4.1 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
import {useIntl} from 'react-intl';
|
|
import {Platform} from 'react-native';
|
|
|
|
import {updateMe} from '@actions/remote/user';
|
|
import {useServerUrl} from '@context/server';
|
|
import {useTheme} from '@context/theme';
|
|
import useAndroidHardwareBackHandler from '@hooks/android_back_handler';
|
|
import useNavButtonPressed from '@hooks/navigation_button_pressed';
|
|
import {popTopScreen, setButtons} from '@screens/navigation';
|
|
import SettingSeparator from '@screens/settings/settings_separator';
|
|
import {getNotificationProps} from '@utils/user';
|
|
|
|
import {getSaveButton} from '../config';
|
|
import SettingContainer from '../setting_container';
|
|
|
|
import MobileSendPush from './push_send';
|
|
import MobilePushStatus from './push_status';
|
|
import MobilePushThread from './push_thread';
|
|
|
|
import type UserModel from '@typings/database/models/servers/user';
|
|
|
|
const SAVE_NOTIF_BUTTON_ID = 'SAVE_NOTIF_BUTTON_ID';
|
|
|
|
type NotificationMobileProps = {
|
|
componentId: string;
|
|
currentUser: UserModel;
|
|
isCRTEnabled: boolean;
|
|
sendPushNotifications: boolean;
|
|
};
|
|
const NotificationPush = ({componentId, currentUser, isCRTEnabled, sendPushNotifications}: NotificationMobileProps) => {
|
|
const serverUrl = useServerUrl();
|
|
|
|
const notifyProps = useMemo(() => getNotificationProps(currentUser), [currentUser.notifyProps]);
|
|
|
|
const [pushSend, setPushSend] = useState<PushStatus>(notifyProps.push);
|
|
const [pushStatus, setPushStatus] = useState<PushStatus>(notifyProps.push_status);
|
|
const [pushThread, setPushThreadPref] = useState<PushStatus>(notifyProps?.push_threads || 'all');
|
|
|
|
const intl = useIntl();
|
|
const theme = useTheme();
|
|
|
|
const onMobilePushThreadChanged = useCallback(() => {
|
|
setPushThreadPref(pushThread === 'all' ? 'mention' : 'all');
|
|
}, [pushThread]);
|
|
|
|
const saveButton = useMemo(() => getSaveButton(SAVE_NOTIF_BUTTON_ID, intl, theme.sidebarHeaderTextColor), [theme.sidebarHeaderTextColor]);
|
|
|
|
const close = useCallback(() => popTopScreen(componentId), [componentId]);
|
|
|
|
const saveNotificationSettings = useCallback(() => {
|
|
const notify_props = {...notifyProps, push: pushSend, push_status: pushStatus, push_threads: pushThread};
|
|
updateMe(serverUrl, {notify_props} as unknown as UserNotifyProps);
|
|
close();
|
|
}, [serverUrl, notifyProps, pushSend, pushStatus, pushThread, close]);
|
|
|
|
useEffect(() => {
|
|
const p = pushSend !== notifyProps.push;
|
|
const pT = pushThread !== notifyProps.push_threads;
|
|
const pS = pushStatus !== notifyProps.push_status;
|
|
|
|
const enabled = p || pT || pS;
|
|
|
|
const buttons = {
|
|
rightButtons: [{
|
|
...saveButton,
|
|
enabled,
|
|
}],
|
|
};
|
|
setButtons(componentId, buttons);
|
|
}, [
|
|
componentId,
|
|
notifyProps,
|
|
pushSend,
|
|
pushStatus,
|
|
pushThread,
|
|
]);
|
|
|
|
useNavButtonPressed(SAVE_NOTIF_BUTTON_ID, componentId, saveNotificationSettings, [saveNotificationSettings]);
|
|
|
|
useAndroidHardwareBackHandler(componentId, close);
|
|
|
|
return (
|
|
<SettingContainer>
|
|
<MobileSendPush
|
|
pushStatus={pushSend}
|
|
sendPushNotifications={sendPushNotifications}
|
|
setMobilePushPref={setPushSend}
|
|
/>
|
|
{Platform.OS === 'android' && (<SettingSeparator isGroupSeparator={true}/>)}
|
|
{isCRTEnabled && pushSend === 'mention' && (
|
|
<MobilePushThread
|
|
pushThread={pushThread}
|
|
onMobilePushThreadChanged={onMobilePushThreadChanged}
|
|
/>
|
|
)}
|
|
{Platform.OS === 'android' && (<SettingSeparator isGroupSeparator={true}/>)}
|
|
{sendPushNotifications && pushSend !== 'none' && (
|
|
<MobilePushStatus
|
|
pushStatus={pushStatus}
|
|
setMobilePushStatus={setPushStatus}
|
|
/>
|
|
)}
|
|
</SettingContainer>
|
|
);
|
|
};
|
|
|
|
export default NotificationPush;
|