From 00daef7a0ec2bf40435d1877c916a8938446d1e3 Mon Sep 17 00:00:00 2001 From: keplyx Date: Fri, 20 Sep 2019 11:05:34 +0200 Subject: [PATCH] Added ability to edit preferences from debug menu --- components/CustomIntroSlider.js | 19 ++++- screens/DebugScreen.js | 132 +++++++++++++++++++++++++++++--- translations/en.json | 11 ++- translations/fr.json | 9 +++ 4 files changed, 158 insertions(+), 13 deletions(-) diff --git a/components/CustomIntroSlider.js b/components/CustomIntroSlider.js index 4109a69..4550a4b 100644 --- a/components/CustomIntroSlider.js +++ b/components/CustomIntroSlider.js @@ -89,6 +89,13 @@ export default class CustomIntroSlider extends React.Component { key: '6', title: i18n.t('intro.slide6.title'), text: i18n.t('intro.slide6.text'), + icon: 'silverware-fork-knife', + colors: ['#ec1213', '#ff372f'], + }, + { + key: '7', + title: i18n.t('intro.slide7.title'), + text: i18n.t('intro.slide7.text'), icon: 'cogs', colors: ['#37c13e', '#26852b'], }, @@ -135,8 +142,16 @@ export default class CustomIntroSlider extends React.Component { render() { return ( - CustomIntroSlider.getIntroRenderItem(item, dimensions)} - slides={this.props.isUpdate ? this.updateSlides : this.introSlides} onDone={() => this.props.onDone()} bottomButton showSkipButton/> + CustomIntroSlider.getIntroRenderItem(item, dimensions)} + slides={this.props.isUpdate ? this.updateSlides : this.introSlides} + onDone={() => this.props.onDone()} + bottomButton + showSkipButton + skipLabel={i18n.t('intro.buttons.skip')} + doneLabel={i18n.t('intro.buttons.done')} + nextLabel={i18n.t('intro.buttons.next')} + /> ); } diff --git a/screens/DebugScreen.js b/screens/DebugScreen.js index e6ecfab..0e73ba7 100644 --- a/screens/DebugScreen.js +++ b/screens/DebugScreen.js @@ -1,24 +1,61 @@ // @flow import * as React from 'react'; -import {Body, Card, CardItem, Container, Content, Left, List, ListItem, Right, Text,} from "native-base"; +import { + Body, + Card, + CardItem, + Container, + Content, + H1, + H3, + Left, + List, + ListItem, + Right, + Text, + Form, + Item, + Label, + Input, + Button +} from "native-base"; import CustomHeader from "../components/CustomHeader"; import ThemeManager from '../utils/ThemeManager'; import i18n from "i18n-js"; import CustomMaterialIcon from "../components/CustomMaterialIcon"; import Touchable from "react-native-platform-touchable"; -import {Alert, Platform, Clipboard} from "react-native"; +import {Alert, View, Clipboard, Image} from "react-native"; import AsyncStorageManager from "../utils/AsyncStorageManager"; import NotificationsManager from "../utils/NotificationsManager"; +import Modalize from "react-native-modalize"; type Props = { navigation: Object, }; +type State = { + modalCurrentDisplayItem: Object, + currentPreferences: Object, +} + /** * Class defining the Debug screen. This screen allows the user to get detailed information on the app/device. */ -export default class DebugScreen extends React.Component { +export default class DebugScreen extends React.Component { + + modalRef: { current: null | Modalize }; + modalInputValue = ''; + + constructor(props: any) { + super(props); + this.modalRef = React.createRef(); + } + + state = { + modalCurrentDisplayItem: {}, + currentPreferences: JSON.parse(JSON.stringify(AsyncStorageManager.getInstance().preferences)) + }; alertCurrentExpoToken() { let token = AsyncStorageManager.getInstance().preferences.expoToken.current; @@ -39,15 +76,19 @@ export default class DebugScreen extends React.Component { } - static getGeneralItem(onPressCallback: Function, icon: string, title: string, subtitle: string) { + static getGeneralItem(onPressCallback: Function, icon: ?string, title: string, subtitle: string) { return ( - - - - + {icon !== undefined ? + + + + : + } {title} @@ -57,14 +98,71 @@ export default class DebugScreen extends React.Component { - + ); } + showEditModal(item: Object) { + this.setState({ + modalCurrentDisplayItem: item + }); + if (this.modalRef.current) { + this.modalRef.current.open(); + } + } + + getModalContent() { + return ( + +

{this.state.modalCurrentDisplayItem.key}

+

Default: {this.state.modalCurrentDisplayItem.default}

+

Current: {this.state.modalCurrentDisplayItem.current}

+
+ + + this.modalInputValue = text}/> + +
+ + + + + +
+ ); + } + + saveNewPrefs(key: string, value: string) { + this.setState((prevState) => { + let currentPreferences = {...prevState.currentPreferences}; + currentPreferences[key].current = value; + return {currentPreferences}; + }); + AsyncStorageManager.getInstance().savePref(key, value); + } + render() { const nav = this.props.navigation; return ( + + {this.getModalContent()} + @@ -75,7 +173,21 @@ export default class DebugScreen extends React.Component { {DebugScreen.getGeneralItem(() => this.alertCurrentExpoToken(), 'bell', 'Get current Expo Token', '')} - {DebugScreen.getGeneralItem(() => this.forceExpoTokenUpdate(),'bell-ring', 'Force Expo token update', '')} + {DebugScreen.getGeneralItem(() => this.forceExpoTokenUpdate(), 'bell-ring', 'Force Expo token update', '')} + + + + + + Preferences + + + + {Object.values(this.state.currentPreferences).map((object) => + + {DebugScreen.getGeneralItem(() => this.showEditModal(object), undefined, object.key, 'Click to edit')} + + )} diff --git a/translations/en.json b/translations/en.json index 8fceb33..6404f41 100644 --- a/translations/en.json +++ b/translations/en.json @@ -16,7 +16,7 @@ }, "slide2": { "title": "Stay up to date", - "text": "CAMPUS will soon allow you to be aware of any event occurring on the campus, from pancake sales to Enfoiros concerts!" + "text": "CAMPUS allows you to be aware of any event occurring on the campus, from pancake sales to Enfoiros concerts!" }, "slide3": { "title": "Never forget your laundry", @@ -31,12 +31,21 @@ "text": "Lookup your timetable on CAMPUS" }, "slide6": { + "title": "RU Menu", + "text": "For the hungry, check this week's menu!" + }, + "slide7": { "title": "More to come...", "text": "New features are coming soon, do not hesitate to give us feedback to improve the app" }, "updateSlide": { "title": "New in this update!", "text": "The RU menu is now working!\nAvailable in the left side menu!" + }, + "buttons": { + "next": "Next", + "skip": "Skip", + "done": "Done" } }, "settingsScreen": { diff --git a/translations/fr.json b/translations/fr.json index 2eb20af..9c2bc55 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -31,12 +31,21 @@ "text": "Consultez votre emploi du temps sur CAMPUS" }, "slide6": { + "title": "Menu du RU", + "text": "Pour ceux qui ont faim, vérifiez le menu du RU de la semaine!" + }, + "slide7": { "title": "Plus à venir...", "text": "D'autres fonctionnalités arrivent bientôt, n'hésitez pas à nous donner votre avis pour améliorer l'appli" }, "updateSlide": { "title": "Nouveau dans cette mise à jour !", "text": "Le menu du RU marche enfin !\nAccessible depuis le menu à gauche" + }, + "buttons": { + "next": "Suivant", + "skip": "Passer", + "done": "Commencer" } }, "settingsScreen": {