Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replace share text with an image on iOS #242

Merged
merged 17 commits into from
Oct 3, 2019
Merged
Prev Previous commit
Next Next commit
Moved frequency from Home state to global context
  • Loading branch information
James Pearson committed Oct 3, 2019
commit acf6590dc3f15bb675818138cdb49acab007187f
5 changes: 4 additions & 1 deletion App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Background as LoadingBackground } from './Screens/Loading/Background';
import {
ApiContextProvider,
ErrorContextProvider,
FrequencyContextProvider,
LocationContextProvider
} from './stores';
import { setupAmplitude, track } from './util/amplitude';
Expand Down Expand Up @@ -71,7 +72,9 @@ export function App () {
<ErrorContextProvider>
<LocationContextProvider>
<ApiContextProvider>
<Screens />
<FrequencyContextProvider>
<Screens />
</FrequencyContextProvider>
</ApiContextProvider>
</LocationContextProvider>
</ErrorContextProvider>
Expand Down
15 changes: 6 additions & 9 deletions App/Screens/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,29 @@
// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.

import React, { useContext, useState } from 'react';
import React, { useContext } from 'react';
import { ScrollView, StyleSheet, View } from 'react-native';
import { NavigationInjectedProps } from 'react-navigation';

import { AdditionalInfo } from './AdditionalInfo';
import { CigaretteBlock, getCigaretteCount } from '../../components';
import { Footer } from './Footer';
import { Header } from './Header';
import { Frequency, SelectFrequency } from './SelectFrequency';
import { SelectFrequency } from './SelectFrequency';
import { SmokeVideo } from './SmokeVideo';
import { ApiContext } from '../../stores';
import { Api } from '../../stores/fetchApi';
import { ApiContext, FrequencyContext } from '../../stores';
import { track, trackScreen } from '../../util/amplitude';
import * as theme from '../../util/theme';

interface HomeProps extends NavigationInjectedProps {}
interface HomeProps extends NavigationInjectedProps { }

export function Home (props: HomeProps) {
const { api } = useContext(ApiContext);
const [frequency, setFrenquency] = useState<Frequency>('daily');

const cigaretteCount = getCigaretteCount(frequency, api!);
const { currentFrequency: frequency, setFrequency } = useContext(FrequencyContext);

trackScreen('HOME');

const cigarettesPerDay = api!.shootISmoke.cigarettes
const cigarettesPerDay = api!.shootISmoke.cigarettes;

return (
<View style={styles.container}>
Expand Down
39 changes: 39 additions & 0 deletions App/stores/frequency.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 <http:https://www.gnu.org/licenses/>.

import React, { createContext, useState } from 'react';
import { Frequency } from '../Screens/Home/SelectFrequency';

export const FrequencyContext = createContext();

export function FrequencyContextProvider ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a good idea, thanks!

children
}: {
children: JSX.Element;
}) {
const [currentFrequency, setFrequency] = useState<Frequency>('daily');
jamespearson marked this conversation as resolved.
Show resolved Hide resolved

return (
<FrequencyContext.Provider
value={{
currentFrequency,
setFrequency
}}
>
{children}
</FrequencyContext.Provider>
);
}
1 change: 1 addition & 0 deletions App/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

export * from './api';
export * from './error';
export * from './frequency';
export * from './location';