Skip to content

Commit e675206

Browse files
authored
feat: Bring shopping list integration (#335)
* feat: bring shopping list integration * Migrate to backend supplying html * Style bring button * fix test errors * adjust styling
1 parent 0c08de0 commit e675206

File tree

7 files changed

+53
-1
lines changed

7 files changed

+53
-1
lines changed

assets/Bring_Logo_big.png

20.7 KB
Loading

nginx/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ http {
3030
listen 80;
3131
client_max_body_size 10M;
3232
location / {
33+
add_header Access-Control-Allow-Origin https://api.getbring.com;
3334
root /usr/share/nginx/html;
3435
index index.html index.htm;
3536
try_files $uri /index.html;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import {useTranslation} from 'react-i18next';
3+
import {Linking, Platform, View} from 'react-native';
4+
import {Avatar, Button} from 'react-native-paper';
5+
import RestAPI from '../dao/RestAPI';
6+
import axios from 'axios';
7+
import AppPersistence from '../AppPersistence';
8+
9+
type Props = {
10+
recipeId: number;
11+
}
12+
13+
export const BringImportButton = (props: React.ComponentPropsWithRef<typeof View> & Props ) => {
14+
const {t} = useTranslation('translation');
15+
16+
const startBringImport = async () => {
17+
const exportId = await RestAPI.createBringExport(props.recipeId);
18+
const exportUrl = (await AppPersistence.getBackendURL()) + AppPersistence.getApiRoute() + '/bringexport?exportId=' + exportId;
19+
20+
if (Platform.OS === 'web') {
21+
Linking.openURL('https://api.getbring.com/rest/bringrecipes/deeplink?source=web&url=' + encodeURIComponent(exportUrl));
22+
} else {
23+
const bringResponse = await axios.post<{deeplink: string}>('https://api.getbring.com/rest/bringrecipes/deeplink', {
24+
url: exportUrl,
25+
});
26+
27+
Linking.openURL(bringResponse.data.deeplink);
28+
}
29+
};
30+
31+
return (
32+
<Button {...props} contentStyle={{height: 42}} style={[{width: 400, height: 42}, props.style]}icon={() => <Avatar.Image size={24} source={require('../../assets/Bring_Logo_big.png')}/>} color="#324047" mode="contained" onPress={() => startBringImport()} >{t('common.bringimport')}</Button>
33+
);
34+
};

src/dao/RestAPI.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ export interface UserInfo {
5353
export interface InstanceInfo {
5454
termsOfService: string;
5555
}
56+
57+
export interface BringExportData {
58+
baseAmount: number;
59+
ingredients: string[];
60+
}
61+
5662
/**
5763
* RESTApi for communication with opencookbook backend
5864
*/
@@ -83,6 +89,10 @@ class RestAPI {
8389
});
8490
}
8591

92+
static async createBringExport(recipeId: number): Promise<string> {
93+
return (await this.post('/bringexport', {recipeId: recipeId})).data.exportId;
94+
}
95+
8696
static async getInstanceInfo(): Promise<InstanceInfo> {
8797
return (await this.get('/instance')).data;
8898
}

src/i18n/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"email": "E-Mail",
2424
"selected": "Ausgewählt",
2525
"offlinemode": "Offlinemodus",
26+
"bringimport": "Import zu Bring®",
2627
"offline": {
2728
"notavailable": "Nicht verfügbar wenn du offline bist",
2829
"notavailabletitle": "Offline"

src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"email": "E-mail",
2424
"selected": "selected",
2525
"offlinemode": "Offline mode",
26+
"bringimport": "Import in Bring®",
2627
"offline": {
2728
"notavailable": "Not available when you are offline",
2829
"notavailabletitle": "Offline"

src/screens/RecipeScreen.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {fetchSingleRecipe} from '../redux/features/recipesSlice';
1414
import {useAppDispatch, useAppSelector} from '../redux/hooks';
1515
import CentralStyles from '../styles/CentralStyles';
1616
import {useKeepAwake} from 'expo-keep-awake';
17-
import { PromptUtil } from '../helper/Prompt';
17+
import {PromptUtil} from '../helper/Prompt';
18+
import {BringImportButton} from '../components/BringExportButton';
1819

1920

2021
type Props = NativeStackScreenProps<MainNavigationProps, 'RecipeScreen'>;
@@ -119,6 +120,10 @@ export const RecipeScreen = (props: Props) => {
119120
onPress={() => displayedRecipe && props.navigation.navigate('GuidedCookingScreen', {recipe: displayedRecipe, scaledServings: scaledServings})}>
120121
{t('screens.recipe.startCookingButton')}
121122
</Button>
123+
<Spacer height={30}/>
124+
{displayedRecipe?.id && <View style={{alignItems: 'center'}}>
125+
<BringImportButton style={{maxWidth: '90%'}}recipeId={displayedRecipe.id} />
126+
</View>}
122127
<Spacer height={20} />
123128

124129
{displayedRecipe && renderStepsSection()}

0 commit comments

Comments
 (0)