* 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>
102 lines
3.9 KiB
TypeScript
102 lines
3.9 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 {savePreference} from '@actions/remote/preference';
|
|
import {Preferences} from '@constants';
|
|
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 {getSaveButton} from '../config';
|
|
import SettingBlock from '../setting_block';
|
|
import SettingContainer from '../setting_container';
|
|
import SettingOption from '../setting_option';
|
|
import SettingSeparator from '../settings_separator';
|
|
|
|
const CLOCK_TYPE = {
|
|
NORMAL: 'NORMAL',
|
|
MILITARY: 'MILITARY',
|
|
} as const;
|
|
|
|
const SAVE_CLOCK_BUTTON_ID = 'settings_display.clock.save.button';
|
|
|
|
type DisplayClockProps = {
|
|
componentId: string;
|
|
currentUserId: string;
|
|
hasMilitaryTimeFormat: boolean;
|
|
}
|
|
const DisplayClock = ({componentId, currentUserId, hasMilitaryTimeFormat}: DisplayClockProps) => {
|
|
const theme = useTheme();
|
|
const [isMilitaryTimeFormat, setIsMilitaryTimeFormat] = useState(hasMilitaryTimeFormat);
|
|
const serverUrl = useServerUrl();
|
|
const intl = useIntl();
|
|
|
|
const saveButton = useMemo(() => getSaveButton(SAVE_CLOCK_BUTTON_ID, intl, theme.sidebarHeaderTextColor), [theme.sidebarHeaderTextColor]);
|
|
|
|
const onSelectClockPreference = useCallback((clockType: keyof typeof CLOCK_TYPE) => {
|
|
setIsMilitaryTimeFormat(clockType === CLOCK_TYPE.MILITARY);
|
|
}, []);
|
|
|
|
const close = () => popTopScreen(componentId);
|
|
|
|
const saveClockDisplayPreference = () => {
|
|
const timePreference: PreferenceType = {
|
|
category: Preferences.CATEGORY_DISPLAY_SETTINGS,
|
|
name: 'use_military_time',
|
|
user_id: currentUserId,
|
|
value: `${isMilitaryTimeFormat}`,
|
|
};
|
|
|
|
savePreference(serverUrl, [timePreference]);
|
|
close();
|
|
};
|
|
|
|
useEffect(() => {
|
|
const buttons = {
|
|
rightButtons: [{
|
|
...saveButton,
|
|
enabled: hasMilitaryTimeFormat !== isMilitaryTimeFormat,
|
|
}],
|
|
};
|
|
setButtons(componentId, buttons);
|
|
}, [componentId, saveButton, isMilitaryTimeFormat]);
|
|
|
|
useAndroidHardwareBackHandler(componentId, close);
|
|
useNavButtonPressed(SAVE_CLOCK_BUTTON_ID, componentId, saveClockDisplayPreference, [isMilitaryTimeFormat]);
|
|
|
|
return (
|
|
<SettingContainer>
|
|
<SettingBlock
|
|
disableHeader={true}
|
|
>
|
|
<SettingOption
|
|
action={onSelectClockPreference}
|
|
label={intl.formatMessage({id: 'settings_display.clock.standard', defaultMessage: '12-hour clock'})}
|
|
description={intl.formatMessage({id: 'settings_display.clock.normal.desc', defaultMessage: 'Example: 4:00 PM'})}
|
|
selected={!isMilitaryTimeFormat}
|
|
testID='clock_display_settings.normal_clock.action'
|
|
type='select'
|
|
value={CLOCK_TYPE.NORMAL}
|
|
/>
|
|
<SettingSeparator/>
|
|
<SettingOption
|
|
action={onSelectClockPreference}
|
|
label={intl.formatMessage({id: 'settings_display.clock.mz', defaultMessage: '24-hour clock'})}
|
|
description={intl.formatMessage({id: 'settings_display.clock.mz.desc', defaultMessage: 'Example: 16:00'})}
|
|
selected={isMilitaryTimeFormat}
|
|
testID='clock_display_settings.military_clock.action'
|
|
type='select'
|
|
value={CLOCK_TYPE.MILITARY}
|
|
/>
|
|
<SettingSeparator/>
|
|
</SettingBlock>
|
|
</SettingContainer>
|
|
);
|
|
};
|
|
|
|
export default DisplayClock;
|