Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EquipmentListScreen.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // @flow
  2. import * as React from 'react';
  3. import {Animated} from "react-native";
  4. import {Avatar, Card, Paragraph, withTheme} from 'react-native-paper';
  5. import AuthenticatedScreen from "../../../components/Amicale/AuthenticatedScreen";
  6. import {Collapsible} from "react-navigation-collapsible";
  7. import {withCollapsible} from "../../../utils/withCollapsible";
  8. import {StackNavigationProp} from "@react-navigation/stack";
  9. import type {CustomTheme} from "../../../managers/ThemeManager";
  10. import i18n from "i18n-js";
  11. import type {club} from "../Clubs/ClubListScreen";
  12. import EquipmentListItem from "../../../components/Lists/Equipment/EquipmentListItem";
  13. type Props = {
  14. navigation: StackNavigationProp,
  15. theme: CustomTheme,
  16. collapsibleStack: Collapsible,
  17. }
  18. export type Device = {
  19. id: number,
  20. name: string,
  21. caution: number,
  22. booked_at: Array<{begin: string, end: string}>,
  23. };
  24. const ICON_AMICALE = require('../../../../assets/amicale.png');
  25. const LIST_ITEM_HEIGHT = 64;
  26. class EquipmentListScreen extends React.Component<Props> {
  27. data: Array<Device>;
  28. getRenderItem = ({item}: { item: Device }) => {
  29. return (
  30. <EquipmentListItem
  31. onPress={() => this.props.navigation.navigate('equipment-lend', {item: item})}
  32. item={item}
  33. height={LIST_ITEM_HEIGHT}/>
  34. );
  35. };
  36. /**
  37. * Gets the list header, with explains this screen's purpose
  38. *
  39. * @returns {*}
  40. */
  41. getListHeader() {
  42. return <Card style={{margin: 5}}>
  43. <Card.Title
  44. title={i18n.t('equipmentScreen.title')}
  45. left={(props) => <Avatar.Image
  46. {...props}
  47. source={ICON_AMICALE}
  48. style={{backgroundColor: 'transparent'}}
  49. />}
  50. />
  51. <Card.Content>
  52. <Paragraph>
  53. {i18n.t('equipmentScreen.message')}
  54. </Paragraph>
  55. </Card.Content>
  56. </Card>;
  57. }
  58. keyExtractor = (item: club) => item.id.toString();
  59. /**
  60. * Gets the main screen component with the fetched data
  61. *
  62. * @param data The data fetched from the server
  63. * @returns {*}
  64. */
  65. getScreen = (data: Array<{ [key: string]: any } | null>) => {
  66. if (data[0] != null) {
  67. const fetchedData = data[0];
  68. if (fetchedData != null)
  69. this.data = fetchedData["devices"];
  70. }
  71. const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack;
  72. return (
  73. <Animated.FlatList
  74. keyExtractor={this.keyExtractor}
  75. renderItem={this.getRenderItem}
  76. ListHeaderComponent={this.getListHeader()}
  77. data={this.data}
  78. // Animations
  79. onScroll={onScroll}
  80. contentContainerStyle={{
  81. paddingTop: containerPaddingTop,
  82. minHeight: '100%'
  83. }}
  84. scrollIndicatorInsets={{top: scrollIndicatorInsetTop}}
  85. />
  86. )
  87. };
  88. render() {
  89. return (
  90. <AuthenticatedScreen
  91. {...this.props}
  92. requests={[
  93. {
  94. link: 'location/all',
  95. params: {},
  96. mandatory: true,
  97. }
  98. ]}
  99. renderFunction={this.getScreen}
  100. />
  101. );
  102. }
  103. }
  104. export default withCollapsible(withTheme(EquipmentListScreen));