114 lines
2.9 KiB
JavaScript
114 lines
2.9 KiB
JavaScript
import React from 'react';
|
|
import {
|
|
View,
|
|
StyleSheet,
|
|
ScrollView,
|
|
TouchableOpacity,
|
|
Text,
|
|
} from 'react-native';
|
|
import {connect} from 'react-redux';
|
|
import TreeView from 'react-native-animated-tree-view';
|
|
import Icon from 'react-native-vector-icons/FontAwesome5';
|
|
|
|
function mapStateToProps(state) {
|
|
return {
|
|
documents: state.documents,
|
|
};
|
|
}
|
|
|
|
class DirectoriesScreen extends React.Component {
|
|
state = {
|
|
documents: [],
|
|
};
|
|
|
|
showDocuments(folder) {
|
|
const documents = this.props.documents.filter(
|
|
tmp => tmp.directory === folder.id,
|
|
);
|
|
this.setState({documents: documents});
|
|
}
|
|
|
|
openDocument(document) {
|
|
this.props.dispatch({type: 'SET_CURRENT_OPENED_DOC', data: document});
|
|
if (document.type === 'pdf') {
|
|
this.props.navigation.navigate('PDFScreen', {uuid: document.uuid});
|
|
} else if (document.type === 'mp4') {
|
|
this.props.navigation.navigate('VideoScreen', {uuid: document.uuid});
|
|
} else {
|
|
console.log('Inconnu');
|
|
}
|
|
}
|
|
|
|
render() {
|
|
const {folder} = this.props.route.params;
|
|
let documentList = this.state.documents.map(document => {
|
|
return (
|
|
<TouchableOpacity
|
|
key={document.id.toString()}
|
|
style={styles.file}
|
|
onPress={() => this.openDocument(document)}>
|
|
{document.type === 'pdf' ? (
|
|
<Icon name="file-pdf" color={'white'} size={60}/>
|
|
) : (
|
|
<Icon name="file-video" color={'white'} size={60}/>
|
|
)}
|
|
<Text style={styles.fileTxt}>{document.title}</Text>
|
|
</TouchableOpacity>
|
|
);
|
|
});
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
<View
|
|
style={{width: 290, borderRightWidth: 1, borderColor: 'lightgrey'}}>
|
|
<TreeView
|
|
data={folder}
|
|
leftImage={{}}
|
|
rightImage={require('../assets/img/arrow_down.png')}
|
|
containerStyle={styles.treeviewContainer}
|
|
onClick={tmp => this.showDocuments(tmp)}
|
|
/>
|
|
</View>
|
|
<ScrollView style={styles.scrollview}>
|
|
<View style={styles.filesContainer}>{documentList}</View>
|
|
</ScrollView>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
flexDirection: 'row',
|
|
},
|
|
treeviewContainer: {
|
|
width: 290,
|
|
},
|
|
scrollview: {
|
|
flex: 2,
|
|
},
|
|
filesContainer: {
|
|
flex: 1,
|
|
flexDirection: 'row',
|
|
flexWrap: 'wrap',
|
|
justifyContent: 'center',
|
|
},
|
|
file: {
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
height: 200,
|
|
width: 180,
|
|
backgroundColor: '#ea4f52',
|
|
margin: 10,
|
|
},
|
|
fileTxt: {
|
|
textAlign: 'center',
|
|
color: 'white',
|
|
fontWeight: 'bold',
|
|
fontSize: 18,
|
|
padding: 5
|
|
}
|
|
});
|
|
|
|
export default connect(mapStateToProps)(DirectoriesScreen);
|