mattermost-mobile/app/screens/settings/settings.tsx
Avinash Lingaloo adde833ea9
MM-45221 - Gekidou Settings fixes - part 2 (#6491)
* 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>
2022-07-27 22:35:57 +04:00

156 lines
4.8 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useEffect, useMemo} from 'react';
import {useIntl} from 'react-intl';
import {Alert, Platform, View} from 'react-native';
import CompassIcon from '@components/compass_icon';
import {Screens} from '@constants';
import {useServerDisplayName} from '@context/server';
import {useTheme} from '@context/theme';
import useAndroidHardwareBackHandler from '@hooks/android_back_handler';
import useNavButtonPressed from '@hooks/navigation_button_pressed';
import {dismissModal, goToScreen, setButtons} from '@screens/navigation';
import SettingContainer from '@screens/settings/setting_container';
import {preventDoubleTap} from '@utils/tap';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import {tryOpenURL} from '@utils/url';
import SettingItem from './setting_item';
const CLOSE_BUTTON_ID = 'close-settings';
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
return {
containerStyle: {
paddingLeft: 8,
marginTop: 12,
},
helpGroup: {
width: '91%',
backgroundColor: changeOpacity(theme.centerChannelColor, 0.08),
height: 1,
alignSelf: 'center',
// marginTop: 20,
},
};
});
type SettingsProps = {
componentId: string;
helpLink: string;
showHelp: boolean;
siteName: string;
}
//todo: Profile the whole feature - https://mattermost.atlassian.net/browse/MM-39711
const Settings = ({componentId, helpLink, showHelp, siteName}: SettingsProps) => {
const theme = useTheme();
const intl = useIntl();
const serverDisplayName = useServerDisplayName();
const serverName = siteName || serverDisplayName;
const styles = getStyleSheet(theme);
const closeButton = useMemo(() => {
return {
id: CLOSE_BUTTON_ID,
icon: CompassIcon.getImageSourceSync('close', 24, theme.centerChannelColor),
testID: CLOSE_BUTTON_ID,
};
}, [theme.centerChannelColor]);
const close = () => {
dismissModal({componentId});
};
useEffect(() => {
setButtons(componentId, {
leftButtons: [closeButton],
});
}, []);
useAndroidHardwareBackHandler(componentId, close);
useNavButtonPressed(CLOSE_BUTTON_ID, componentId, close, []);
const goToNotifications = preventDoubleTap(() => {
const screen = Screens.SETTINGS_NOTIFICATION;
const title = intl.formatMessage({id: 'settings.notifications', defaultMessage: 'Notifications'});
goToScreen(screen, title);
});
const goToDisplaySettings = preventDoubleTap(() => {
const screen = Screens.SETTINGS_DISPLAY;
const title = intl.formatMessage({id: 'settings.display', defaultMessage: 'Display'});
goToScreen(screen, title);
});
const goToAbout = preventDoubleTap(() => {
const screen = Screens.ABOUT;
const title = intl.formatMessage({id: 'settings.about', defaultMessage: 'About {appTitle}'}, {appTitle: serverName});
goToScreen(screen, title);
});
const goToAdvancedSettings = preventDoubleTap(() => {
const screen = Screens.SETTINGS_ADVANCED;
const title = intl.formatMessage({id: 'settings.advanced_settings', defaultMessage: 'Advanced Settings'});
goToScreen(screen, title);
});
const openHelp = preventDoubleTap(() => {
const link = helpLink ? helpLink.toLowerCase() : '';
if (link) {
const onError = () => {
Alert.alert(
intl.formatMessage({id: 'mobile.link.error.title', defaultMessage: 'Error'}),
intl.formatMessage({id: 'mobile.link.error.text', defaultMessage: 'Unable to open the link.'}),
);
};
tryOpenURL(link, onError);
}
});
return (
<SettingContainer>
<SettingItem
onPress={goToNotifications}
optionName='notification'
/>
<SettingItem
onPress={goToDisplaySettings}
optionName='display'
/>
<SettingItem
onPress={goToAdvancedSettings}
optionName='advanced_settings'
/>
<SettingItem
messageValues={{appTitle: serverName}}
onPress={goToAbout}
optionName='about'
/>
{Platform.OS === 'android' && <View style={styles.helpGroup}/>}
{showHelp &&
<SettingItem
containerStyle={styles.containerStyle}
isLink={true}
onPress={openHelp}
optionName='help'
separator={false}
/>
}
</SettingContainer>
);
};
export default Settings;