Application Android et IOS pour l'amicale des élèves
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.

ProxiwashSectionHeader.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. // @flow
  20. import * as React from 'react';
  21. import {Avatar, Text, withTheme} from 'react-native-paper';
  22. import {StyleSheet, View} from 'react-native';
  23. import i18n from 'i18n-js';
  24. import type {CustomThemeType} from '../../../managers/ThemeManager';
  25. type PropsType = {
  26. theme: CustomThemeType,
  27. title: string,
  28. isDryer: boolean,
  29. nbAvailable: number,
  30. };
  31. const styles = StyleSheet.create({
  32. container: {
  33. flexDirection: 'row',
  34. marginLeft: 5,
  35. marginRight: 5,
  36. marginBottom: 10,
  37. marginTop: 20,
  38. },
  39. icon: {
  40. backgroundColor: 'transparent',
  41. },
  42. text: {
  43. fontSize: 20,
  44. fontWeight: 'bold',
  45. },
  46. });
  47. /**
  48. * Component used to display a proxiwash item, showing machine progression and state
  49. */
  50. class ProxiwashListItem extends React.Component<PropsType> {
  51. shouldComponentUpdate(nextProps: PropsType): boolean {
  52. const {props} = this;
  53. return (
  54. nextProps.theme.dark !== props.theme.dark ||
  55. nextProps.nbAvailable !== props.nbAvailable
  56. );
  57. }
  58. render(): React.Node {
  59. const {props} = this;
  60. const subtitle = `${props.nbAvailable} ${
  61. props.nbAvailable <= 1
  62. ? i18n.t('screens.proxiwash.numAvailable')
  63. : i18n.t('screens.proxiwash.numAvailablePlural')
  64. }`;
  65. const iconColor =
  66. props.nbAvailable > 0
  67. ? props.theme.colors.success
  68. : props.theme.colors.primary;
  69. return (
  70. <View style={styles.container}>
  71. <Avatar.Icon
  72. icon={props.isDryer ? 'tumble-dryer' : 'washing-machine'}
  73. color={iconColor}
  74. style={styles.icon}
  75. />
  76. <View style={{justifyContent: 'center'}}>
  77. <Text style={styles.text}>{props.title}</Text>
  78. <Text style={{color: props.theme.colors.subtitle}}>{subtitle}</Text>
  79. </View>
  80. </View>
  81. );
  82. }
  83. }
  84. export default withTheme(ProxiwashListItem);