Verified Commit e13eda68 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Open photos deeplink with slug

parent faf5955a
......@@ -5,7 +5,7 @@ exports[`LoadingScreen component renders correctly 1`] = `
style={
Object {
"alignItems": "center",
"backgroundColor": "#FFFFFF",
"backgroundColor": "#FAFAFA",
"flex": 1,
"justifyContent": "center",
}
......
......@@ -472,7 +472,7 @@ exports[`Sidebar component renders correctly 1`] = `
]
}
>
</Text>
<Text
style={
......@@ -489,7 +489,7 @@ exports[`Sidebar component renders correctly 1`] = `
]
}
>
Settings
Photos
</Text>
</View>
</View>
......@@ -537,10 +537,7 @@ exports[`Sidebar component renders correctly 1`] = `
}
>
<Text
accessible={true}
allowFontScaling={false}
ellipsizeMode="tail"
onPress={[Function]}
style={
Array [
Object {
......@@ -562,19 +559,19 @@ exports[`Sidebar component renders correctly 1`] = `
"fontStyle": "normal",
"fontWeight": "normal",
},
Object {},
]
}
>
</Text>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
style={
Array [
Object {
"backgroundColor": "transparent",
"color": "#313131",
"fontFamily": "System",
"fontSize": 14,
"fontWeight": "600",
},
Object {
......@@ -583,20 +580,13 @@ exports[`Sidebar component renders correctly 1`] = `
]
}
>
Photos
Settings
</Text>
</View>
</View>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hasTVPreferredFocus={undefined}
hitSlop={undefined}
isTVSelectable={true}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
......@@ -614,8 +604,6 @@ exports[`Sidebar component renders correctly 1`] = `
},
]
}
testID={undefined}
tvParallaxProperties={undefined}
>
<View
style={
......
......@@ -36,6 +36,7 @@
<data android:host="thalia.nu" />
<data android:path="/pizzas/" />
<data android:pathPattern="/events/.*/" />
<data android:pathPattern="/photos/.*/" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
......
......@@ -46,6 +46,13 @@ export function openAlbum(pk) {
};
}
export function openAlbumWithSlug(slug) {
return {
type: PHOTOS_ALBUM_OPEN,
payload: { slug },
};
}
export function successAlbum(album) {
return {
type: PHOTOS_ALBUM_SUCCESS,
......
import React, { Component } from 'react';
import {
Linking, Platform, NativeModules, Alert,
Alert, Linking, NativeModules, Platform,
} from 'react-native';
import { applyMiddleware, createStore } from 'redux';
import { Provider } from 'react-redux';
import { I18nextProvider, withTranslation } from 'react-i18next';
import { I18nextProvider } from 'react-i18next';
import createSagaMiddleware from 'redux-saga';
import firebase from 'react-native-firebase';
import DeviceInfo from 'react-native-device-info';
import Moment from 'moment';
import 'moment/locale/nl';
import PropTypes from 'prop-types';
import { i18n as i18next } from 'i18next';
import reducers from './reducers';
import i18n from './utils/i18n';
......@@ -74,12 +74,13 @@ class Main extends Component {
};
showNotification = (notification) => {
const t = i18next.getFixedT(undefined, 'app');
let buttons;
if (notification.data.url) {
buttons = [
{ text: this.props.t('Dismiss') },
{ text: t('Dismiss') },
{
text: this.props.t('Open'),
text: t('Open'),
onPress: () => store.dispatch(
deepLinkingActions.deepLink(notification.data.url, false),
),
......@@ -128,8 +129,4 @@ class Main extends Component {
}
}
Main.propTypes = {
t: PropTypes.func.isRequired,
};
export default withTranslation('app')(Main);
export default Main;
......@@ -67,8 +67,8 @@ const deepLink = function* deepLink(action) {
args: [],
},
{
regexp: new RegExp('^/photos/([0-9]+)/$'),
action: photosActions.openAlbum,
regexp: new RegExp('^/photos/([-\\w]+)/$'),
action: photosActions.openAlbumWithSlug,
args: [],
},
{
......
......@@ -35,7 +35,7 @@ function* loadAlbums() {
}
function* loadAlbum(action) {
const { pk } = action.payload;
const { pk, slug } = action.payload;
const token = yield select(tokenSelector);
yield put(photosActions.fetchingAlbum());
......@@ -50,9 +50,21 @@ function* loadAlbum(action) {
};
try {
const album = yield call(apiRequest, `photos/albums/${pk}`, data);
let album;
if (pk !== undefined) {
album = yield call(apiRequest, `photos/albums/${pk}`, data);
} else {
const albums = yield call(apiRequest, 'photos/albums', data, {
search: slug,
});
album = yield call(apiRequest, `photos/albums/${albums[0].pk}`, data);
}
yield put(photosActions.successAlbum(album));
if (album !== undefined) {
yield put(photosActions.successAlbum(album));
} else {
yield put(photosActions.failureAlbum());
}
} catch (error) {
yield put(photosActions.failureAlbum());
}
......
......@@ -3,7 +3,7 @@ import DeviceInfo from 'react-native-device-info';
let server = 'https://thalia.nu';
/* istanbul ignore next line */
if (__DEV__) { // eslint-disable-line no-undef
// server = 'http://localhost:8000';
server = 'http://localhost:8000';
}
export const url = server;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment