diff --git a/App/Screens/About/About.tsx b/App/Screens/About/About.tsx index 6984df95..83412eb9 100644 --- a/App/Screens/About/About.tsx +++ b/App/Screens/About/About.tsx @@ -30,7 +30,6 @@ import { NavigationInjectedProps } from 'react-navigation'; import { Box } from './Box'; import { BackButton } from '../../components'; -import { Dev } from './Dev'; import { i18n } from '../../localization'; import * as theme from '../../util/theme'; @@ -186,7 +185,6 @@ export function About (props: AboutProps) { {/* Add languages https://github.com/amaurymartiny/shoot-i-smoke/issues/73 */} - ); } diff --git a/App/Screens/About/Dev/Dev.tsx b/App/Screens/About/Dev/Dev.tsx deleted file mode 100644 index 01b529b1..00000000 --- a/App/Screens/About/Dev/Dev.tsx +++ /dev/null @@ -1,130 +0,0 @@ -// Sh**t! I Smoke -// Copyright (C) 2018-2019 Marcelo S. Coelho, Amaury Martiny - -// Sh**t! I Smoke is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Sh**t! I Smoke is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Sh**t! I Smoke. If not, see . - -import * as BackgroundFetch from 'expo-background-fetch'; -import * as ExpoLocation from 'expo-location'; -import { pipe } from 'fp-ts/lib/pipeable'; -import * as T from 'fp-ts/lib/Task'; -import * as TE from 'fp-ts/lib/TaskEither'; -import React, { useEffect, useState } from 'react'; -import { AsyncStorage, Text, View } from 'react-native'; - -import { Button } from '../../../components'; -import { - AqiHistoryDbItem, - clearTable, - getData, - populateRandom -} from '../../../managers/AqiHistoryDb'; -import { - AQI_HISTORY_LAST_FETCH_ATTEMPT, - AQI_HISTORY_LAST_FETCH_RESULT -} from '../../../managers/AqiHistoryTask'; -import { getLastKnownGps, GPS_TASK } from '../../../managers/GpsTask'; -import { logFpError } from '../../../util/fp'; -import * as theme from '../../../util/theme'; - -export function Dev () { - const [allData, setAllData] = useState([]); - const [ - aqiHistoryTask, - setAqiHistoryTask - ] = useState(null); - const [bgLocation, setBgLocation] = useState(false); - const [startedBgLocation, setStartedBgLocation] = useState(false); - const [asyncStorageGps, setAsyncStorageGps] = useState(); - const [lastBgFetchAttempt, setLastBgFetchAttempt] = useState(); - const [lastBgFetchResult, setLastBgFetchResult] = useState(); - - useEffect(() => { - // Data in SQL db - const oneWeekAgo = new Date(); - oneWeekAgo.setHours(oneWeekAgo.getHours() - 24 * 7); - pipe( - getData(oneWeekAgo), - TE.fold( - err => { - console.log(` - getData - Error ${err.message}`); - - return T.of(undefined); - }, - data => { - setAllData(data); - return T.of(undefined); - } - ) - )().catch(logFpError); - - // GPS_TASK status - ExpoLocation.isBackgroundLocationAvailableAsync().then(setBgLocation); - ExpoLocation.hasStartedLocationUpdatesAsync(GPS_TASK).then( - setStartedBgLocation - ); - pipe( - getLastKnownGps(), - TE.fold( - err => { - console.log(` - getLastKnownGps - Error ${err.message}`); - - return T.of(undefined); - }, - data => { - setAsyncStorageGps(data); - return T.of(undefined); - } - ) - )().catch(logFpError); - - // AQI_HISTORY_TASK status - BackgroundFetch.getStatusAsync().then(setAqiHistoryTask); - AsyncStorage.getItem(AQI_HISTORY_LAST_FETCH_ATTEMPT).then( - setLastBgFetchAttempt - ); - AsyncStorage.getItem(AQI_HISTORY_LAST_FETCH_RESULT).then( - setLastBgFetchResult - ); - }, []); - - return ( - - - BackgroundFetch status:{' '} - {aqiHistoryTask && BackgroundFetch.Status[aqiHistoryTask]} - - - isBackgroundLocationAvailableAsync: {bgLocation.toString()} - - - hasStartedLocationUpdatesAsync: {startedBgLocation.toString()} - - - Last known GPS: {JSON.stringify(asyncStorageGps)} - - Last BackgroundFetch: {lastBgFetchAttempt} - - Last BackgroundFetch Result: {lastBgFetchResult} - - - All DB:{' '} - {JSON.stringify(allData.map(({ creationTime }) => creationTime))} - - - - - ); -} diff --git a/App/Screens/About/Dev/index.ts b/App/Screens/About/Dev/index.ts deleted file mode 100644 index 76637a08..00000000 --- a/App/Screens/About/Dev/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -// Sh**t! I Smoke -// Copyright (C) 2018-2019 Marcelo S. Coelho, Amaury Martiny - -// Sh**t! I Smoke is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Sh**t! I Smoke is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Sh**t! I Smoke. If not, see . - -export * from './Dev'; diff --git a/App/Screens/Details/Header/Header.tsx b/App/Screens/Details/Header/Header.tsx index 62f37905..2a335834 100644 --- a/App/Screens/Details/Header/Header.tsx +++ b/App/Screens/Details/Header/Header.tsx @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Sh**t! I Smoke. If not, see . -import { distanceInWords } from 'date-fns'; +import { formatDistanceToNow } from 'date-fns'; import React, { useContext } from 'react'; import { GestureResponderEvent, @@ -63,7 +63,7 @@ export function Header (props: HeaderProps) { {lastUpdated && renderInfo( i18n.t('details_header_latest_update_label'), - `${distanceInWords(lastUpdated, new Date())} ${i18n.t( + `${formatDistanceToNow(lastUpdated)} ${i18n.t( 'details_header_latest_update_ago' )}` )} diff --git a/App/Screens/Home/Footer/Footer.tsx b/App/Screens/Home/Footer/Footer.tsx index 3b4fb76c..b74ea778 100644 --- a/App/Screens/Home/Footer/Footer.tsx +++ b/App/Screens/Home/Footer/Footer.tsx @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Sh**t! I Smoke. If not, see . -import * as O from 'fp-ts/lib/Option'; -import { pipe } from 'fp-ts/lib/pipeable'; import React, { useContext } from 'react'; import { Share, StyleSheet, Text, View } from 'react-native'; import { NavigationInjectedProps } from 'react-navigation'; @@ -23,19 +21,17 @@ import { NavigationInjectedProps } from 'react-navigation'; import { aboutSections } from '../../About'; import { Button } from '../../../components'; import { i18n } from '../../../localization'; -import { AqiHistory } from '../../../managers'; import { Frequency } from '../SelectFrequency'; import { ApiContext, CurrentLocationContext } from '../../../stores'; import { isStationTooFar } from '../../../util/station'; import * as theme from '../../../util/theme'; interface FooterProps extends NavigationInjectedProps { - aqiHistory: O.Option; frequency: Frequency; } export function Footer (props: FooterProps) { - const { aqiHistory, frequency } = props; + const { frequency } = props; const { api } = useContext(ApiContext)!; const { currentLocation } = useContext(CurrentLocationContext); @@ -45,12 +41,6 @@ export function Footer (props: FooterProps) { props.navigation.navigate('About'); } - function goToAboutAqiHistory () { - props.navigation.navigate('About', { - scrollInto: aboutSections.about_how_results - }); - } - function goToAboutWhySoFar () { props.navigation.navigate('About', { scrollInto: aboutSections.about_why_is_the_station_so_far_title @@ -61,13 +51,6 @@ export function Footer (props: FooterProps) { props.navigation.navigate('Details'); } - function goToPastStations () { - props.navigation.navigate('PastStations', { - aqiHistory, - frequency - }); - } - function handleShare () { return Share.share({ title: i18n.t('home_share_title'), @@ -78,87 +61,34 @@ export function Footer (props: FooterProps) { } const renderBigButton = () => { - switch (frequency) { - case 'daily': { - return isTooFar ? ( - - ) : ( - - ); - } - case 'weekly': - case 'monthly': { - return pipe( - aqiHistory, - O.map(history => history[frequency]), - O.filter(({ isCorrect }) => isCorrect), - O.map(() => ( - - )), - O.getOrElse(() => ( - - )) - ); - } - } + return isTooFar ? ( + + ) : ( + + ); }; const renderSmallButtons = () => { - switch (frequency) { - case 'daily': { - return ( - - {isTooFar ? ( - - ) : ( - - )} - - - ); - } - case 'weekly': - case 'monthly': { - return pipe( - aqiHistory, - O.map(history => history[frequency]), - O.filter(({ isCorrect }) => isCorrect), - O.map(() => ( - - - - - )), - O.getOrElse(() => null) - ); - } - } + return ( + + {isTooFar ? ( + + ) : ( + + )} + + + ); }; return ( diff --git a/App/Screens/Home/Home.tsx b/App/Screens/Home/Home.tsx index 3c3686d2..aaf7e364 100644 --- a/App/Screens/Home/Home.tsx +++ b/App/Screens/Home/Home.tsx @@ -14,11 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Sh**t! I Smoke. If not, see . -import { pipe } from 'fp-ts/lib/pipeable'; -import * as O from 'fp-ts/lib/Option'; -import * as T from 'fp-ts/lib/Task'; -import * as TE from 'fp-ts/lib/TaskEither'; -import React, { useContext, useEffect, useState } from 'react'; +import React, { useContext, useState } from 'react'; import { ScrollView, StyleSheet, Text, View } from 'react-native'; import { NavigationInjectedProps } from 'react-navigation'; @@ -26,14 +22,11 @@ import { Cigarettes } from '../../components'; import { Footer } from './Footer'; import { Header } from './Header'; import { i18n } from '../../localization'; -import { AqiHistory, getAqiHistory } from '../../managers'; import { Frequency, SelectFrequency } from './SelectFrequency'; import { SmokeVideo } from './SmokeVideo'; import { ApiContext, CurrentLocationContext } from '../../stores'; import swearWords from './swearWords'; -import { logFpError } from '../../util/fp'; import * as theme from '../../util/theme'; -import { Wait } from './Wait'; interface HomeProps extends NavigationInjectedProps {} @@ -48,27 +41,6 @@ export function Home (props: HomeProps) { const { api } = useContext(ApiContext)!; const { isGps } = useContext(CurrentLocationContext)!; const [frequency, setFrenquency] = useState('daily'); - const [aqiHistory, setAqiHistory] = useState>(O.none); - - useEffect(() => { - pipe( - getAqiHistory(), - TE.fold( - err => { - console.log(` - getAqiHistory - ${err.message}`); - - return T.of(undefined); - }, - history => { - console.log(` - getAqiHistory - Got data from DB`); - - setAqiHistory(O.some(history)); - - return T.of(undefined); - } - ) - )().catch(logFpError); - }, []); function getCigaretteCount () { switch (frequency) { @@ -76,45 +48,16 @@ export function Home (props: HomeProps) { return api!.shootISmoke.cigarettes; } case 'weekly': + return api!.shootISmoke.cigarettes * 7; case 'monthly': { - return pipe( - aqiHistory, - O.map(history => history[frequency]), - O.map(({ sum }) => sum), - O.getOrElse(() => 0) - ); + return api!.shootISmoke.cigarettes * 30; } } } const cigaretteCount = getCigaretteCount(); function renderCigarettes () { - switch (frequency) { - case 'daily': { - return ( - - ); - } - case 'weekly': - case 'monthly': { - return pipe( - aqiHistory, - O.map(history => history[frequency]), - O.map(({ isCorrect }) => isCorrect), - O.map(isCorrect => - isCorrect ? ( - - ) : ( - - ) - ), - O.getOrElse(() => null) - ); - } - } + return ; } const renderCigarettesText = () => { @@ -123,9 +66,10 @@ export function Home (props: HomeProps) { const text = i18n.t('home_smoked_cigarette_title', { swearWord: getSwearWord(cigaretteCount), - presentPast: isGps - ? i18n.t('home_common_you_smoke') - : i18n.t('home_common_you_d_smoke'), + presentPast: + isGps && frequency === 'daily' + ? i18n.t('home_common_you_smoke') + : i18n.t('home_common_you_d_smoke'), singularPlural: cigarettes === 1 ? i18n.t('home_common_cigarette').toLowerCase() @@ -147,30 +91,6 @@ export function Home (props: HomeProps) { ); }; - function renderText () { - switch (frequency) { - case 'daily': { - return renderCigarettesText(); - } - case 'weekly': - case 'monthly': { - return pipe( - aqiHistory, - O.map(history => history[frequency]), - O.chain(({ daysToResults }) => daysToResults), - O.fold(renderCigarettesText, days => ( - - - {i18n.t('home_wait_more_days', { days: days + 1 })} - {' '} - {i18n.t('home_wait_until_results')} - - )) - ); - } - } - } - return ( @@ -184,26 +104,16 @@ export function Home (props: HomeProps) { > {renderCigarettes()} - {renderText()} - {isGps ? ( - { - setFrenquency(freq); - }} - style={styles.selectFrequency} - /> - ) : ( - - {i18n.t('home_smoked_there')}. - - )} + {renderCigarettesText()} + { + setFrenquency(freq); + }} + style={styles.selectFrequency} + /> -