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

Refactor settings screen #99

Merged
merged 4 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions components/AppInfoFooter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { colors, Text } from 'react-native-elements';
import Constants from 'expo-constants';

import { getAppName } from '../utils/Device';

const AppInfoFooter = () => (
<View style={styles.container}>
<Text style={styles.text}>{`${getAppName()}`}</Text>
<Text style={styles.text}>{`${Constants.nativeAppVersion} (${Constants.nativeBuildVersion})`}</Text>
<Text style={styles.text}>{`Expo Version: ${Constants.expoVersion}`}</Text>
</View>
);

const styles = StyleSheet.create({
container: {
margin: 15
},
text: {
color: colors.grey4,
fontSize: 15
}
});

export default AppInfoFooter;
34 changes: 34 additions & 0 deletions components/BrowserListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React from 'react';
import { ListItem } from 'react-native-elements';
import PropTypes from 'prop-types';

import { openBrowser } from '../utils/WebBrowser';

const BrowserListItem = ({item, index}) => (
<ListItem
title={item.name}
leftIcon={item.icon}
topDivider={index === 0}
bottomDivider
chevron
onPress={() => {
openBrowser(item.url);
}}
/>
);

BrowserListItem.propTypes = {
item: PropTypes.shape({
name: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
url: PropTypes.string.isRequired
}).isRequired,
index: PropTypes.number.isRequired
};

export default BrowserListItem;
25 changes: 25 additions & 0 deletions components/ButtonListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React from 'react';
import { StyleSheet } from 'react-native';
import { Button } from 'react-native-elements';
import PropTypes from 'prop-types';

const ButtonListItem = ({item}) => (
<Button {...item} buttonStyle={{ ...styles.button, ...item.buttonStyle }} />
);

ButtonListItem.propTypes = {
item: PropTypes.object.isRequired
};

const styles = StyleSheet.create({
button: {
margin: 15
}
});

export default ButtonListItem;
79 changes: 79 additions & 0 deletions components/ServerListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React from 'react';
import { StyleSheet, View, Platform } from 'react-native';
import { Button, Icon, ListItem, colors } from 'react-native-elements';
import PropTypes from 'prop-types';

import { getIconName } from '../utils/Icons';

const ServerListItem = ({item, index, activeServer, onDelete, onPress}) => {
let title;
let subtitle;
if (item.info) {
title = item.info.ServerName;
subtitle = `Version: ${item.info.Version}\n${item.urlString}`;
} else {
title = item.url.host;
subtitle = `Version: unknown\n${item.urlString}`;
}

return (
<ListItem
title={title}
titleStyle={styles.title}
subtitle={subtitle}
leftElement={(
index === activeServer ? (
<Icon
name={getIconName('checkmark')}
type='ionicon'
size={24}
containerStyle={styles.leftElement}
/>
) : (
<View style={styles.leftElement} />
)
)}
rightElement={(
<Button
type='clear'
icon={{
name: getIconName('trash'),
type: 'ionicon',
iconStyle: styles.deleteButton
}}
onPress={() => onDelete(index)}
/>
)}
topDivider={index === 0}
bottomDivider
onPress={() => onPress(index)}
/>
);
};

ServerListItem.propTypes = {
item: PropTypes.object.isRequired,
index: PropTypes.number.isRequired,
activeServer: PropTypes.number.isRequired,
onDelete: PropTypes.func.isRequired,
onPress: PropTypes.func.isRequired
};

const styles = StyleSheet.create({
title: {
marginBottom: 2
},
leftElement: {
width: 12
},
deleteButton: {
color: Platform.OS === 'ios' ? colors.platform.ios.error : colors.platform.android.error
}
});

export default ServerListItem;
42 changes: 0 additions & 42 deletions components/SettingsSection.js

This file was deleted.

5 changes: 5 additions & 0 deletions constants/Links.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Platform } from 'react-native';

export default [
{
key: 'links-website',
name: 'Jellyfin Website',
url: 'https://jellyfin.org/',
icon: {
Expand All @@ -15,6 +16,7 @@ export default [
}
},
{
key: 'links-documentation',
name: 'Documentation',
url: 'https://docs.jellyfin.org',
icon: {
Expand All @@ -23,6 +25,7 @@ export default [
}
},
{
key: 'links-source',
name: 'Source Code',
url: 'https:/jellyfin/jellyfin-expo',
icon: {
Expand All @@ -31,6 +34,7 @@ export default [
}
},
{
key: 'links-feature',
name: 'Request a Feature',
url: 'https://features.jellyfin.org/',
icon: {
Expand All @@ -39,6 +43,7 @@ export default [
}
},
{
key: 'links-issue',
name: 'Report an Issue',
url: 'https:/jellyfin/jellyfin-expo/issues',
icon: {
Expand Down
53 changes: 53 additions & 0 deletions models/ServerModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { action, autorun, computed, observable } from 'mobx';
import { ignore } from 'mobx-sync';
import { task } from 'mobx-task';

import JellyfinValidator from '../utils/JellyfinValidator';

export default class ServerModel {
@observable
id

@observable
url

@ignore
@observable
online = false

@observable
info

constructor(id, url, info) {
this.id = id;
this.url = url;
this.info = info;

autorun(() => {
this.urlString = this.parseUrlString;
});
}

@computed
get parseUrlString() {
try {
return JellyfinValidator.getServerUrl(this);
} catch (ex) {
return '';
}
}

@task
async fetchInfo() {
return await JellyfinValidator.fetchServerInfo(this)
.then(action(info => {
this.online = true;
this.info = info;
}));
}
}
4 changes: 2 additions & 2 deletions navigation/AppNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const AppNavigator = observer(() => {
return (
<NavigationContainer theme={theme}>
<Stack.Navigator
initialRouteName={(rootStore.serverStore.servers.length > 0) ? 'Main' : 'AddServer'}
initialRouteName={(rootStore.serverStore.servers?.length > 0) ? 'Main' : 'AddServer'}
headerMode='screen'
screenOptions={{ headerShown: false }}
>
Expand All @@ -95,7 +95,7 @@ const AppNavigator = observer(() => {
name='AddServer'
component={AddServerScreen}
options={{
headerShown: rootStore.serverStore.servers.length > 0,
headerShown: rootStore.serverStore.servers?.length > 0,
title: 'Add Server'
}}
/>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"mobx": "^5.15.4",
"mobx-react": "^6.2.2",
"mobx-sync": "^3.0.0",
"mobx-task": "^2.0.1",
"prop-types": "^15.7.2",
"react": "16.9.0",
"react-lifecycles-compat": "^3.0.4",
Expand Down
Loading