2022-01-13 21:45:55 +00:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2021-10-06 20:30:10 +00:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { Switch } from 'react-native';
|
|
|
|
import { RadioButton } from 'react-native-ui-lib';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
|
|
|
|
import { setPreference } from '../actions/sortPreferences';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { DisplayMode, SortBy, themes } from '../lib/constants';
|
2021-10-06 20:30:10 +00:00
|
|
|
import * as HeaderButton from '../containers/HeaderButton';
|
2022-01-13 21:45:55 +00:00
|
|
|
import * as List from '../containers/List';
|
2021-10-06 20:30:10 +00:00
|
|
|
import { ICON_SIZE } from '../containers/List/constants';
|
2022-01-13 21:45:55 +00:00
|
|
|
import SafeAreaView from '../containers/SafeAreaView';
|
|
|
|
import StatusBar from '../containers/StatusBar';
|
2022-01-18 14:38:29 +00:00
|
|
|
import { IApplicationState, IPreferences } from '../definitions';
|
2022-01-13 21:45:55 +00:00
|
|
|
import I18n from '../i18n';
|
2022-01-11 14:47:23 +00:00
|
|
|
import { SettingsStackParamList } from '../stacks/types';
|
2022-01-13 21:45:55 +00:00
|
|
|
import { useTheme } from '../theme';
|
2022-03-09 19:41:26 +00:00
|
|
|
import { events, logEvent } from '../utils/log';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { saveSortPreference } from '../lib/methods';
|
2022-01-11 14:47:23 +00:00
|
|
|
|
|
|
|
interface IDisplayPrefsView {
|
|
|
|
navigation: StackNavigationProp<SettingsStackParamList, 'DisplayPrefsView'>;
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DisplayPrefsView = (props: IDisplayPrefsView): JSX.Element => {
|
2021-10-06 20:30:10 +00:00
|
|
|
const { theme } = useTheme();
|
|
|
|
|
2022-01-11 14:47:23 +00:00
|
|
|
const { sortBy, groupByType, showFavorites, showUnread, showAvatar, displayMode } = useSelector(
|
2022-01-18 14:38:29 +00:00
|
|
|
(state: IApplicationState) => state.sortPreferences
|
2022-01-11 14:47:23 +00:00
|
|
|
);
|
|
|
|
const { isMasterDetail } = useSelector((state: any) => state.app);
|
2021-10-06 20:30:10 +00:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-11-22 16:19:49 +00:00
|
|
|
const { navigation } = props;
|
2021-10-06 20:30:10 +00:00
|
|
|
navigation.setOptions({
|
2021-11-22 16:19:49 +00:00
|
|
|
title: I18n.t('Display')
|
2021-10-06 20:30:10 +00:00
|
|
|
});
|
2021-11-22 16:19:49 +00:00
|
|
|
if (!isMasterDetail) {
|
|
|
|
navigation.setOptions({
|
|
|
|
headerLeft: () => <HeaderButton.Drawer navigation={navigation} testID='display-view-drawer' />
|
|
|
|
});
|
|
|
|
}
|
2021-10-06 20:30:10 +00:00
|
|
|
}, []);
|
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
const setSortPreference = (param: Partial<IPreferences>) => {
|
|
|
|
dispatch(setPreference(param));
|
2022-04-28 20:37:25 +00:00
|
|
|
saveSortPreference(param);
|
2021-10-06 20:30:10 +00:00
|
|
|
};
|
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
const sortByName = () => {
|
2021-10-06 20:30:10 +00:00
|
|
|
logEvent(events.DP_SORT_CHANNELS_BY_NAME);
|
2022-03-09 19:41:26 +00:00
|
|
|
setSortPreference({ sortBy: SortBy.Alphabetical });
|
2021-10-06 20:30:10 +00:00
|
|
|
};
|
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
const sortByActivity = () => {
|
2021-10-06 20:30:10 +00:00
|
|
|
logEvent(events.DP_SORT_CHANNELS_BY_ACTIVITY);
|
2022-03-09 19:41:26 +00:00
|
|
|
setSortPreference({ sortBy: SortBy.Activity });
|
2021-10-06 20:30:10 +00:00
|
|
|
};
|
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
const toggleGroupByType = () => {
|
2021-10-06 20:30:10 +00:00
|
|
|
logEvent(events.DP_GROUP_CHANNELS_BY_TYPE);
|
2022-03-09 19:41:26 +00:00
|
|
|
setSortPreference({ groupByType: !groupByType });
|
2021-10-06 20:30:10 +00:00
|
|
|
};
|
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
const toggleGroupByFavorites = () => {
|
2021-10-06 20:30:10 +00:00
|
|
|
logEvent(events.DP_GROUP_CHANNELS_BY_FAVORITE);
|
2022-03-09 19:41:26 +00:00
|
|
|
setSortPreference({ showFavorites: !showFavorites });
|
2021-10-06 20:30:10 +00:00
|
|
|
};
|
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
const toggleUnread = () => {
|
2021-10-06 20:30:10 +00:00
|
|
|
logEvent(events.DP_GROUP_CHANNELS_BY_UNREAD);
|
2022-03-09 19:41:26 +00:00
|
|
|
setSortPreference({ showUnread: !showUnread });
|
2021-10-06 20:30:10 +00:00
|
|
|
};
|
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
const toggleAvatar = () => {
|
2021-10-06 20:30:10 +00:00
|
|
|
logEvent(events.DP_TOGGLE_AVATAR);
|
2022-03-09 19:41:26 +00:00
|
|
|
setSortPreference({ showAvatar: !showAvatar });
|
2021-10-06 20:30:10 +00:00
|
|
|
};
|
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
const displayExpanded = () => {
|
2021-10-06 20:30:10 +00:00
|
|
|
logEvent(events.DP_DISPLAY_EXPANDED);
|
2022-03-09 19:41:26 +00:00
|
|
|
setSortPreference({ displayMode: DisplayMode.Expanded });
|
2021-10-06 20:30:10 +00:00
|
|
|
};
|
|
|
|
|
2022-03-09 19:41:26 +00:00
|
|
|
const displayCondensed = () => {
|
2021-10-06 20:30:10 +00:00
|
|
|
logEvent(events.DP_DISPLAY_CONDENSED);
|
2022-03-09 19:41:26 +00:00
|
|
|
setSortPreference({ displayMode: DisplayMode.Condensed });
|
2021-10-06 20:30:10 +00:00
|
|
|
};
|
|
|
|
|
2022-01-11 14:47:23 +00:00
|
|
|
const renderCheckBox = (value: boolean) => (
|
2021-10-06 20:30:10 +00:00
|
|
|
<List.Icon name={value ? 'checkbox-checked' : 'checkbox-unchecked'} color={value ? themes[theme].actionTintColor : null} />
|
|
|
|
);
|
|
|
|
|
2022-01-11 14:47:23 +00:00
|
|
|
const renderAvatarSwitch = (value: boolean) => (
|
2021-10-06 20:30:10 +00:00
|
|
|
<Switch value={value} onValueChange={() => toggleAvatar()} testID='display-pref-view-avatar-switch' />
|
|
|
|
);
|
|
|
|
|
2022-01-11 14:47:23 +00:00
|
|
|
const renderRadio = (value: boolean) => (
|
2021-10-06 20:30:10 +00:00
|
|
|
<RadioButton
|
|
|
|
selected={!!value}
|
|
|
|
color={value ? themes[theme].actionTintColor : themes[theme].auxiliaryText}
|
|
|
|
size={ICON_SIZE}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SafeAreaView>
|
|
|
|
<StatusBar />
|
|
|
|
<List.Container testID='display-view-list'>
|
|
|
|
<List.Section title='Display'>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
left={() => <List.Icon name='view-extended' />}
|
|
|
|
title='Expanded'
|
|
|
|
testID='display-pref-view-expanded'
|
2022-01-11 14:47:23 +00:00
|
|
|
right={() => renderRadio(displayMode === DisplayMode.Expanded)}
|
2021-10-06 20:30:10 +00:00
|
|
|
onPress={displayExpanded}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
left={() => <List.Icon name='view-medium' />}
|
|
|
|
title='Condensed'
|
|
|
|
testID='display-pref-view-condensed'
|
2022-01-11 14:47:23 +00:00
|
|
|
right={() => renderRadio(displayMode === DisplayMode.Condensed)}
|
2021-10-06 20:30:10 +00:00
|
|
|
onPress={displayCondensed}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
left={() => <List.Icon name='avatar' />}
|
|
|
|
title='Avatars'
|
|
|
|
testID='display-pref-view-avatars'
|
|
|
|
right={() => renderAvatarSwitch(showAvatar)}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
|
|
|
|
<List.Section title='Sort_by'>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Activity'
|
|
|
|
testID='display-pref-view-activity'
|
|
|
|
left={() => <List.Icon name='clock' />}
|
|
|
|
onPress={sortByActivity}
|
2022-01-11 14:47:23 +00:00
|
|
|
right={() => renderRadio(sortBy === SortBy.Activity)}
|
2021-10-06 20:30:10 +00:00
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Name'
|
|
|
|
testID='display-pref-view-name'
|
|
|
|
left={() => <List.Icon name='sort-az' />}
|
|
|
|
onPress={sortByName}
|
2022-01-11 14:47:23 +00:00
|
|
|
right={() => renderRadio(sortBy === SortBy.Alphabetical)}
|
2021-10-06 20:30:10 +00:00
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
|
|
|
|
<List.Section title='Group_by'>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Unread_on_top'
|
|
|
|
testID='display-pref-view-unread'
|
|
|
|
left={() => <List.Icon name='flag' />}
|
|
|
|
onPress={toggleUnread}
|
|
|
|
right={() => renderCheckBox(showUnread)}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Favorites'
|
|
|
|
testID='display-pref-view-favorites'
|
|
|
|
left={() => <List.Icon name='star' />}
|
|
|
|
onPress={toggleGroupByFavorites}
|
|
|
|
right={() => renderCheckBox(showFavorites)}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Types'
|
|
|
|
testID='display-pref-view-types'
|
|
|
|
left={() => <List.Icon name='group-by-type' />}
|
|
|
|
onPress={toggleGroupByType}
|
|
|
|
right={() => renderCheckBox(groupByType)}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
</List.Container>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-01-11 14:47:23 +00:00
|
|
|
DisplayPrefsView.propTypes = {};
|
2021-10-06 20:30:10 +00:00
|
|
|
|
|
|
|
export default DisplayPrefsView;
|