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.tsx 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. import * as React from 'react';
  20. import {Avatar, Text, withTheme} from 'react-native-paper';
  21. import {StyleSheet, View} from 'react-native';
  22. import i18n from 'i18n-js';
  23. type PropsType = {
  24. theme: ReactNativePaper.Theme;
  25. title: string;
  26. isDryer: boolean;
  27. nbAvailable: number;
  28. };
  29. const styles = StyleSheet.create({
  30. container: {
  31. flexDirection: 'row',
  32. marginLeft: 5,
  33. marginRight: 5,
  34. marginBottom: 10,
  35. marginTop: 20,
  36. },
  37. icon: {
  38. backgroundColor: 'transparent',
  39. },
  40. text: {
  41. fontSize: 20,
  42. fontWeight: 'bold',
  43. },
  44. });
  45. /**
  46. * Component used to display a proxiwash item, showing machine progression and state
  47. */
  48. class ProxiwashListItem extends React.Component<PropsType> {
  49. shouldComponentUpdate(nextProps: PropsType): boolean {
  50. const {props} = this;
  51. return (
  52. nextProps.theme.dark !== props.theme.dark ||
  53. nextProps.nbAvailable !== props.nbAvailable
  54. );
  55. }
  56. render() {
  57. const {props} = this;
  58. const subtitle = `${props.nbAvailable} ${
  59. props.nbAvailable <= 1
  60. ? i18n.t('screens.proxiwash.numAvailable')
  61. : i18n.t('screens.proxiwash.numAvailablePlural')
  62. }`;
  63. const iconColor =
  64. props.nbAvailable > 0
  65. ? props.theme.colors.success
  66. : props.theme.colors.primary;
  67. return (
  68. <View style={styles.container}>
  69. <Avatar.Icon
  70. icon={props.isDryer ? 'tumble-dryer' : 'washing-machine'}
  71. color={iconColor}
  72. style={styles.icon}
  73. />
  74. <View style={{justifyContent: 'center'}}>
  75. <Text style={styles.text}>{props.title}</Text>
  76. <Text style={{color: props.theme.colors.subtitle}}>{subtitle}</Text>
  77. </View>
  78. </View>
  79. );
  80. }
  81. }
  82. export default withTheme(ProxiwashListItem);