Removed unused code and some arrow functions

This commit is contained in:
keplyx 2020-03-08 14:43:02 +01:00
parent d514d70126
commit 8b8afd69eb
2 changed files with 37 additions and 80 deletions

View file

@ -7,7 +7,7 @@ import ThemeManager from "../utils/ThemeManager";
import HTML from "react-native-render-html"; import HTML from "react-native-render-html";
import {LinearGradient} from "expo-linear-gradient"; import {LinearGradient} from "expo-linear-gradient";
import i18n from "i18n-js"; import i18n from "i18n-js";
import {Avatar, Card, Text, Title} from 'react-native-paper'; import {Avatar, Card, Text} from 'react-native-paper';
type Props = { type Props = {
isAvailable: boolean, isAvailable: boolean,
@ -28,6 +28,13 @@ export default class DashboardItem extends React.Component<Props> {
displayEvent: undefined, displayEvent: undefined,
}; };
getIcon: Function;
constructor() {
super();
this.getIcon = this.getIcon.bind(this);
}
/** /**
* Convert the date string given by in the event list json to a date object * Convert the date string given by in the event list json to a date object
* @param dateString * @param dateString
@ -64,18 +71,17 @@ export default class DashboardItem extends React.Component<Props> {
getEventPreviewContainer() { getEventPreviewContainer() {
if (this.props.displayEvent !== undefined && this.props.displayEvent !== null) { if (this.props.displayEvent !== undefined && this.props.displayEvent !== null) {
const hasImage = this.props.displayEvent['logo'] !== '' && this.props.displayEvent['logo'] !== null; const hasImage = this.props.displayEvent['logo'] !== '' && this.props.displayEvent['logo'] !== null;
const getImage = () => <Avatar.Image
source={{uri: this.props.displayEvent['logo']}}
size={60}
style={{backgroundColor: 'transparent'}}/>;
return ( return (
<Card style={{marginBottom: 10}}> <Card style={{marginBottom: 10}}>
{hasImage ? {hasImage ?
<Card.Title <Card.Title
title={this.props.displayEvent['title']} title={this.props.displayEvent['title']}
subtitle={this.getFormattedEventTime(this.props.displayEvent)} subtitle={this.getFormattedEventTime(this.props.displayEvent)}
left={() => left={getImage}
<Avatar.Image
source={{uri: this.props.displayEvent['logo']}}
size={60}
style={{backgroundColor: 'transparent'}}/>
}
/> : /> :
<Card.Title <Card.Title
title={this.props.displayEvent['title']} title={this.props.displayEvent['title']}
@ -137,58 +143,14 @@ export default class DashboardItem extends React.Component<Props> {
getIcon() { getIcon() {
return ( return (
<MaterialCommunityIcons <Avatar.Icon
name={this.props.icon} icon={this.props.icon}
color={ color={this.props.isAvailable ? this.props.color : ThemeManager.getCurrentThemeVariables().textDisabled}
this.props.isAvailable ? size={60}
this.props.color : style={{backgroundColor: 'transparent'}}/>
ThemeManager.getCurrentThemeVariables().textDisabled
}
size={this.props.isSquare ? 50 : 40}/>
); );
} }
getText() {
return (
<View style={{
width: this.props.isSquare ? '100%' : 'auto',
}}>
<Title style={{
color: this.props.isAvailable ?
ThemeManager.getCurrentThemeVariables().text :
ThemeManager.getCurrentThemeVariables().textDisabled,
textAlign: this.props.isSquare ? 'center' : 'left',
width: this.props.isSquare ? '100%' : 'auto',
}}>
{this.props.title}
</Title>
<Text style={{
color: this.props.isAvailable ?
ThemeManager.getCurrentThemeVariables().text :
ThemeManager.getCurrentThemeVariables().textDisabled,
textAlign: this.props.isSquare ? 'center' : 'left',
width: this.props.isSquare ? '100%' : 'auto',
}}>
{this.props.subtitle}
</Text>
</View>
);
}
getContent() {
if (this.props.isSquare) {
return (
<View>
<View style={{marginLeft: 'auto', marginRight: 'auto'}}>
{this.getIcon()}
</View>
{this.getText()}
</View>
);
}
}
render() { render() {
// console.log("rendering DashboardItem " + this.props.title); // console.log("rendering DashboardItem " + this.props.title);
let marginRight = 10; let marginRight = 10;
@ -211,28 +173,17 @@ export default class DashboardItem extends React.Component<Props> {
overflow: 'hidden', overflow: 'hidden',
}} }}
onPress={this.props.clickAction}> onPress={this.props.clickAction}>
{this.props.isSquare ?
<Card.Content>
{this.getContent()}
</Card.Content>
:
<View>
<Card.Title <Card.Title
title={this.props.title} title={this.props.title}
titleStyle={{color: color}} titleStyle={{color: color}}
subtitle={this.props.subtitle} subtitle={this.props.subtitle}
subtitleStyle={{color: color}} subtitleStyle={{color: color}}
left={(props) => <Avatar.Icon left={this.getIcon}
{...props}
icon={this.props.icon}
color={this.props.isAvailable ? this.props.color : ThemeManager.getCurrentThemeVariables().textDisabled}
size={60}
style={{backgroundColor: 'transparent'}}/>}
/> />
<Card.Content> <Card.Content>
{this.getEventPreviewContainer()} {this.getEventPreviewContainer()}
</Card.Content> </Card.Content>
</View>}
</Card> </Card>
); );
} }

View file

@ -6,6 +6,13 @@ import i18n from "i18n-js";
const ICON_AMICALE = require('../assets/amicale.png'); const ICON_AMICALE = require('../assets/amicale.png');
function getAvatar() {
return (
<Avatar.Image size={48} source={ICON_AMICALE}
style={{backgroundColor: 'transparent'}}/>
);
}
function FeedItem(props) { function FeedItem(props) {
const {colors} = props.theme; const {colors} = props.theme;
return ( return (
@ -13,8 +20,7 @@ function FeedItem(props) {
<Card.Title <Card.Title
title={props.title} title={props.title}
subtitle={props.subtitle} subtitle={props.subtitle}
left={props => <Avatar.Image size={48} source={ICON_AMICALE} left={getAvatar}
style={{backgroundColor: 'transparent'}}/>}
/> />
{props.full_picture !== '' && props.full_picture !== undefined ? {props.full_picture !== '' && props.full_picture !== undefined ?
<TouchableOpacity onPress={props.onImagePress}> <TouchableOpacity onPress={props.onImagePress}>