DayNightStatus.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { View } from "@tarojs/components";
  2. import './DayNightStatus.scss'
  3. import { useTranslation } from "react-i18next";
  4. import { ColorType } from "@/context/themes/color";
  5. export default function DayNightStatus(props: { authInfo: any, isNight: boolean, sunset_ts: number, sunrise_ts: number }) {
  6. const { t } = useTranslation()
  7. //ongoing //wfs //ended //completed
  8. function status() {
  9. if (props.isNight) {
  10. if (props.authInfo && props.authInfo.day_completed && new Date().getTime() > props.authInfo.day_completed.sunset_ts) {
  11. return 'completed'
  12. }
  13. if (props.authInfo && props.authInfo.night_completed && new Date().getTime() > props.authInfo.night_completed.sunrise_ts) {
  14. return 'ended'
  15. }
  16. if (props.sunset_ts < new Date().getTime()) {
  17. return 'ongoing'
  18. }
  19. return 'wait_for_start'
  20. }
  21. if (props.authInfo && props.authInfo.day_completed && new Date().getTime() > props.authInfo.day_completed.sunset_ts) {
  22. return 'completed'
  23. }
  24. if (props.sunrise_ts < new Date().getTime()) {
  25. return 'ongoing'
  26. }
  27. return 'wait_for_start'
  28. }
  29. if (status() == 'wait_for_start') {
  30. return <View className="day_night_status"
  31. style={{ backgroundColor: props.isNight ? ColorType.night + '66' : ColorType.day + '66', color: props.isNight ? ColorType.night : ColorType.day }}
  32. >{t('feature.day_night.upcoming')}</View>
  33. }
  34. if (status() == 'ongoing') {
  35. return <View className="day_night_status"
  36. style={{ backgroundColor: props.isNight ? ColorType.night : ColorType.day, color: props.isNight ? '#fff' : '#000' }}
  37. >{t('feature.day_night.in_real_time')}</View>
  38. }
  39. if (status() == 'ended') {
  40. return <View className="day_night_status"
  41. style={{ backgroundColor: props.isNight ? ColorType.night : ColorType.day, color: props.isNight ? '#fff' : '#000' }}
  42. >{t('feature.day_night.ended')}</View>
  43. }
  44. return <View className="day_night_status"
  45. style={{ backgroundColor: props.isNight ? ColorType.night : ColorType.day, color: '#FA5151' }}
  46. >{t('feature.day_night.last_updated')}</View>
  47. }