// @flow import * as React from 'react'; import {StackNavigationProp} from '@react-navigation/stack'; import {Button, Card, Paragraph, withTheme} from 'react-native-paper'; import {FlatList} from 'react-native'; import {View} from 'react-native-animatable'; import i18n from 'i18n-js'; import type { ServiceCategoryType, ServiceItemType, } from '../../../managers/ServicesManager'; import DashboardManager from '../../../managers/DashboardManager'; import DashboardItem from '../../../components/Home/EventDashboardItem'; import DashboardEditAccordion from '../../../components/Lists/DashboardEdit/DashboardEditAccordion'; import DashboardEditPreviewItem from '../../../components/Lists/DashboardEdit/DashboardEditPreviewItem'; import AsyncStorageManager from '../../../managers/AsyncStorageManager'; import CollapsibleFlatList from '../../../components/Collapsible/CollapsibleFlatList'; type PropsType = { navigation: StackNavigationProp, }; type StateType = { currentDashboard: Array, currentDashboardIdList: Array, activeItem: number, }; /** * Class defining the Settings screen. This screen shows controls to modify app preferences. */ class DashboardEditScreen extends React.Component { content: Array; initialDashboard: Array; initialDashboardIdList: Array; constructor(props: PropsType) { super(props); const dashboardManager = new DashboardManager(props.navigation); this.initialDashboardIdList = AsyncStorageManager.getObject( AsyncStorageManager.PREFERENCES.dashboardItems.key, ); this.initialDashboard = dashboardManager.getCurrentDashboard(); this.state = { currentDashboard: [...this.initialDashboard], currentDashboardIdList: [...this.initialDashboardIdList], activeItem: 0, }; this.content = dashboardManager.getCategories(); } getDashboardRowRenderItem = ({ item, index, }: { item: DashboardItem, index: number, }): React.Node => { const {activeItem} = this.state; return ( { this.setState({activeItem: index}); }} isActive={activeItem === index} /> ); }; getDashboard(content: Array): React.Node { return ( ); } getRenderItem = ({item}: {item: ServiceCategoryType}): React.Node => { const {currentDashboardIdList} = this.state; return ( ); }; getListHeader(): React.Node { const {currentDashboard} = this.state; return ( {this.getDashboard(currentDashboard)} {i18n.t('screens.settings.dashboardEdit.message')} ); } updateDashboard = (service: ServiceItemType) => { const {currentDashboard, currentDashboardIdList, activeItem} = this.state; currentDashboard[activeItem] = service; currentDashboardIdList[activeItem] = service.key; this.setState({ currentDashboard, currentDashboardIdList, }); AsyncStorageManager.set( AsyncStorageManager.PREFERENCES.dashboardItems.key, currentDashboardIdList, ); }; undoDashboard = () => { this.setState({ currentDashboard: [...this.initialDashboard], currentDashboardIdList: [...this.initialDashboardIdList], }); AsyncStorageManager.set( AsyncStorageManager.PREFERENCES.dashboardItems.key, this.initialDashboardIdList, ); }; render(): React.Node { return ( ); } } export default withTheme(DashboardEditScreen);