From 3679f652addca0eed67da3e2d0b95b0c68c0c2e2 Mon Sep 17 00:00:00 2001 From: Martin Bauer Date: Thu, 3 Sep 2020 19:06:31 +0200 Subject: [PATCH] Cleanup - removed old files --- App.js | 65 ++++++++++++++++++---- components/HomeView.js | 56 ------------------- {views => components}/ImageHeader.js | 0 components/LiveTrainingView.js | 82 ---------------------------- components/NewAppMain.js | 46 ---------------- components/ThemedStackNavigation.js | 70 ------------------------ components/Themes.js | 10 ---- {views => components}/themeColors.js | 0 package-lock.json | 13 +++++ package.json | 4 +- views/LastSessionsView.js | 4 +- views/MainMenuView.js | 2 +- views/SettingsView.js | 7 +-- views/TrainingView.js | 7 +-- 14 files changed, 78 insertions(+), 288 deletions(-) delete mode 100644 components/HomeView.js rename {views => components}/ImageHeader.js (100%) delete mode 100644 components/LiveTrainingView.js delete mode 100644 components/NewAppMain.js delete mode 100644 components/ThemedStackNavigation.js delete mode 100644 components/Themes.js rename {views => components}/themeColors.js (100%) diff --git a/App.js b/App.js index f4c6ba8..d2ae54d 100644 --- a/App.js +++ b/App.js @@ -3,16 +3,37 @@ import { AppLoading } from 'expo'; import { Ionicons } from '@expo/vector-icons'; import * as Font from 'expo-font'; -// Redux +// Redux + Storage import swimtrackerReducer from './state/Reducer'; import { createStore } from 'redux'; import { DeviceReduxCoupling } from './state/DeviceReduxCoupling'; import { Provider } from 'react-redux'; +import AsyncStorage from '@react-native-community/async-storage'; +import { persistStore, persistReducer } from 'redux-persist' +import hardSet from 'redux-persist/lib/stateReconciler/hardSet' +import { PersistGate } from 'redux-persist/integration/react' -import ThemedStackNavigation from './components/ThemedStackNavigation'; -import NewAppMain from "./components/NewAppMain"; +// Navigation +import { NavigationContainer } from '@react-navigation/native'; +import { createStackNavigator } from '@react-navigation/stack'; -const store = createStore(swimtrackerReducer); +// Own views +import MainMenuView from "./views/MainMenuView"; +import SettingsView from "./views/SettingsView"; +import TrainingView from "./views/TrainingView"; +import LastSessionsView from "./views/LastSessionsView"; + + +const persistConfig = { + key: 'root', + storage: AsyncStorage, + stateReconciler: hardSet, +}; + +const persistedReducer = persistReducer(persistConfig, swimtrackerReducer) +const store = createStore(persistedReducer); +const persistor = persistStore(store); +const Stack = createStackNavigator(); export default class App extends React.Component { constructor(props) { @@ -36,15 +57,37 @@ export default class App extends React.Component { if (!this.state.isReady) { return ; } - /* + const screenOptions = { + headerShown: false, + }; return ( - - - );*/ - return ( - - + } persistor={persistor}> + + + + + + + + + ); } diff --git a/components/HomeView.js b/components/HomeView.js deleted file mode 100644 index 427edba..0000000 --- a/components/HomeView.js +++ /dev/null @@ -1,56 +0,0 @@ -import React from 'react'; -import { Content, Card, CardItem, Body, Text, Button } from 'native-base'; -import { Image, ScrollView } from 'react-native'; -import { connect } from 'react-redux'; -import { ConnState, startSession } from '../state/DeviceReduxCoupling'; - -function HomeView(props) { - const buttonText = props.running ? "View Swim Session" : "Start swimming"; - - const onButtonPress = () => { - if(!props.running) { - props.dispatch(startSession()); - } - props.navigation.navigate('Training') - }; - - return ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - ); -} - -const mapStateToProps = (state) => { - return { running: state.deviceState.connState === ConnState.CONNECTED_RUNNING }; -}; - -export default connect(mapStateToProps)(HomeView); diff --git a/views/ImageHeader.js b/components/ImageHeader.js similarity index 100% rename from views/ImageHeader.js rename to components/ImageHeader.js diff --git a/components/LiveTrainingView.js b/components/LiveTrainingView.js deleted file mode 100644 index 30dcde4..0000000 --- a/components/LiveTrainingView.js +++ /dev/null @@ -1,82 +0,0 @@ -import React, { useRef, useState } from 'react'; -import { StyleSheet, Animated } from 'react-native'; -import { Button, Content, Text, View } from 'native-base'; -import { LinearGradient } from 'expo-linear-gradient'; -import IconCard from './IconCard'; -import Graph from './Graph'; -import { connect } from 'react-redux'; -import backgroundColors from './Themes'; -import { useKeepAwake } from 'expo-keep-awake'; -import { stopSession } from '../state/DeviceReduxCoupling'; -import CycleView from './CycleView'; - - -function LiveTrainingView(props) { - const analysis = props.session.analysis; - const onStopClick = () => { - props.dispatch(stopSession()); - props.navigation.navigate('Home'); - }; - const laps = (analysis.peaks.size / props.peaksPerLap).toFixed(1); - const totalMomentum = Math.trunc(analysis.totalMomentum * props.kgFactor / 10 / 60); - - const toTimeStr = seconds => { - let minuteStr = String(Math.floor(seconds / 60)); - if(minuteStr.length < 2) - minuteStr = "0" + minuteStr; - let secondStr = String(Math.floor(seconds % 60)); - if(secondStr.length < 2) - secondStr = "0" + secondStr; - return minuteStr + ":" + secondStr; - } - console.log("Active", analysis.activeTime); - useKeepAwake(); - - return ( - - - - - - - - - - - - - - - - - - - ); -} - -const styles = StyleSheet.create({ - card: { - flexDirection: 'row', - backgroundColor: 'rgba(0, 0, 0, 0.2)', - margin: 5, - padding: 5, - borderRadius: 3, - justifyContent: 'space-between', - } -}); - -const mapStateToProps = (state) => { - return { - session: state.deviceState, - peaksPerLap: state.settings.analysis.peaksPerLap, - theme: state.settings.theme, - kgFactor: state.settings.analysis.kgFactor, - }; -}; - -export default connect(mapStateToProps)(LiveTrainingView); diff --git a/components/NewAppMain.js b/components/NewAppMain.js deleted file mode 100644 index 7c39ab5..0000000 --- a/components/NewAppMain.js +++ /dev/null @@ -1,46 +0,0 @@ -import React from 'react'; -import { NavigationContainer } from '@react-navigation/native'; -import { createStackNavigator } from '@react-navigation/stack'; - -// Own views -import MainMenuView from "../views/MainMenuView"; -import SettingsView from "../views/SettingsView"; -import TrainingView from "../views/TrainingView"; -import LastSessionsView from "../views/LastSessionsView"; -const Stack = createStackNavigator(); - -function NewAppMain(props) { - - const screenOptions = { - headerShown: false, - } - - return ( - - - - - - - - - ) -}; - -export default NewAppMain; diff --git a/components/ThemedStackNavigation.js b/components/ThemedStackNavigation.js deleted file mode 100644 index 214eb1a..0000000 --- a/components/ThemedStackNavigation.js +++ /dev/null @@ -1,70 +0,0 @@ -import React from 'react'; -import { LinearGradient } from 'expo-linear-gradient'; -import { NavigationContainer } from '@react-navigation/native'; -import { createStackNavigator } from '@react-navigation/stack'; -import { BlurView } from 'expo-blur'; -import { StyleSheet } from 'react-native'; -import backgroundColors from './Themes'; - -// Own views -import LiveTrainingView from './LiveTrainingView'; -import HomeView from './HomeView'; -import { connect } from 'react-redux'; - - -const Stack = createStackNavigator(); - - -function ThemedStackNavigation(props) { - - const screenOptions = { - cardStyle: { - backgroundColor: "transparent", - opacity: 1 - }, - headerTransparent: "true", - headerTitleStyle: { - color: 'white', - fontWeight: 'bold', - fontSize: 20, - }, - headerTintColor: "white", - headerBackground: () => ( - - ), - } - - return ( - - - - - - - - - ) -}; - -const mapStateToProps = (state) => { - return { themeName: state.settings.theme }; -}; - -export default connect(mapStateToProps)(ThemedStackNavigation); diff --git a/components/Themes.js b/components/Themes.js deleted file mode 100644 index ccb1365..0000000 --- a/components/Themes.js +++ /dev/null @@ -1,10 +0,0 @@ - -const backgroundColors = { - 'hot': ['#830e5f', '#fd5139'], - 'darkBlue': ['#4265a3', '#cfada7'], - //'lightBlue': ['#50a4db', '#74bbe2'], - 'lightBlue': ['#24acdc ', '#65fae6'], - 'foggy': ['#bc8db8', '#5d5e90'], -}; - -export default backgroundColors; \ No newline at end of file diff --git a/views/themeColors.js b/components/themeColors.js similarity index 100% rename from views/themeColors.js rename to components/themeColors.js diff --git a/package-lock.json b/package-lock.json index a4c48f5..b1ae2ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1603,6 +1603,14 @@ "@types/yargs": "^13.0.0" } }, + "@react-native-community/async-storage": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/@react-native-community/async-storage/-/async-storage-1.12.0.tgz", + "integrity": "sha512-y3zVxuVyiOxI8TXrvajmYfDbIt2vFNxzV5MiA28v15DQTxDk6uJH3rpc9my+la7u2Tiwt3PpdU2+59ZgZ4h7wA==", + "requires": { + "deep-assign": "^3.0.0" + } + }, "@react-native-community/cli-debugger-ui": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@react-native-community/cli-debugger-ui/-/cli-debugger-ui-3.0.0.tgz", @@ -8241,6 +8249,11 @@ } } }, + "redux-persist": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/redux-persist/-/redux-persist-6.0.0.tgz", + "integrity": "sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==" + }, "regenerate": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", diff --git a/package.json b/package.json index b506b49..7be1052 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ ] }, "dependencies": { + "@react-native-community/async-storage": "^1.12.0", "@react-native-community/masked-view": "0.1.6", "@react-navigation/native": "^5.4.2", "@react-navigation/stack": "^5.3.9", @@ -44,7 +45,8 @@ "react-redux": "^7.2.0", "react-xml-parser": "^1.1.6", "reconnecting-websocket": "^4.4.0", - "redux": "^4.0.5" + "redux": "^4.0.5", + "redux-persist": "^6.0.0" }, "devDependencies": { "babel-preset-expo": "^8.1.0", diff --git a/views/LastSessionsView.js b/views/LastSessionsView.js index bceebad..27a7384 100644 --- a/views/LastSessionsView.js +++ b/views/LastSessionsView.js @@ -8,11 +8,11 @@ import { TouchableOpacity, RefreshControl, } from "react-native"; -import themeColors from './themeColors'; +import themeColors from '../components/themeColors'; import EntypoIcon from "react-native-vector-icons/Entypo"; import AntDesignIcon from "react-native-vector-icons/AntDesign"; import FaIcon from "react-native-vector-icons/FontAwesome5"; -import ImageHeader from "./ImageHeader"; +import ImageHeader from "../components/ImageHeader"; import { SwipeListView } from 'react-native-swipe-list-view'; import { connect } from 'react-redux'; import request from '../utility/PromiseRequest'; diff --git a/views/MainMenuView.js b/views/MainMenuView.js index d858293..d59f43b 100644 --- a/views/MainMenuView.js +++ b/views/MainMenuView.js @@ -7,7 +7,7 @@ import { Text, TouchableOpacity, } from "react-native"; -import themeColors from './themeColors'; +import themeColors from '../components/themeColors'; import MaterialIcon from "react-native-vector-icons/MaterialCommunityIcons"; import EntypoIcon from "react-native-vector-icons/Entypo"; diff --git a/views/SettingsView.js b/views/SettingsView.js index a5d7b6e..2565313 100644 --- a/views/SettingsView.js +++ b/views/SettingsView.js @@ -4,17 +4,14 @@ import { View, StatusBar, TextInput, - ImageBackground, Text, - TouchableOpacity, - SafeAreaView, Slider, Switch, } from "react-native"; -import themeColors from './themeColors'; +import themeColors from '../components/themeColors'; import MaterialIcon from "react-native-vector-icons/MaterialCommunityIcons"; import EntypoIcon from "react-native-vector-icons/Entypo"; -import ImageHeader from "./ImageHeader"; +import ImageHeader from "../components/ImageHeader"; // --------------------------------------------------------------------------------------------- diff --git a/views/TrainingView.js b/views/TrainingView.js index 0648b9d..b8bfc05 100644 --- a/views/TrainingView.js +++ b/views/TrainingView.js @@ -1,13 +1,12 @@ -import React, { Component } from "react"; +import React from "react"; import { StyleSheet, View, StatusBar, Text, - TouchableOpacity, - SafeAreaView + TouchableOpacity } from "react-native"; -import themeColors from './themeColors'; +import themeColors from '../components/themeColors'; import EntypoIcon from "react-native-vector-icons/Entypo"; import { connect } from 'react-redux';