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.

functions.native.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { NavigateSectionList } from '../base/react';
  2. import { toDisplayableItem } from './functions.any';
  3. /**
  4. * Transforms the history list to a displayable list
  5. * with sections.
  6. *
  7. * @private
  8. * @param {Array<Object>} recentList - The recent list form the redux store.
  9. * @param {Function} t - The translate function.
  10. * @param {string} defaultServerURL - The default server URL.
  11. * @returns {Array<Object>}
  12. */
  13. export function toDisplayableList(recentList, t, defaultServerURL) {
  14. const { createSection } = NavigateSectionList;
  15. const todaySection = createSection(t('dateUtils.today'), 'today');
  16. const yesterdaySection
  17. = createSection(t('dateUtils.yesterday'), 'yesterday');
  18. const earlierSection
  19. = createSection(t('dateUtils.earlier'), 'earlier');
  20. const today = new Date();
  21. const todayString = today.toDateString();
  22. const yesterday = new Date();
  23. yesterday.setDate(yesterday.getDate() - 1);
  24. const yesterdayString = yesterday.toDateString();
  25. for (const item of recentList) {
  26. const itemDateString = new Date(item.date).toDateString();
  27. const displayableItem = toDisplayableItem(item, defaultServerURL, t);
  28. if (itemDateString === todayString) {
  29. todaySection.data.push(displayableItem);
  30. } else if (itemDateString === yesterdayString) {
  31. yesterdaySection.data.push(displayableItem);
  32. } else {
  33. earlierSection.data.push(displayableItem);
  34. }
  35. }
  36. const displayableList = [];
  37. // the recent list in the redux store has the latest date in the last index
  38. // therefore all the sectionLists' data that was created by parsing through
  39. // the recent list is in reverse order and must be reversed for the most
  40. // item to show first
  41. if (todaySection.data.length) {
  42. todaySection.data.reverse();
  43. displayableList.push(todaySection);
  44. }
  45. if (yesterdaySection.data.length) {
  46. yesterdaySection.data.reverse();
  47. displayableList.push(yesterdaySection);
  48. }
  49. if (earlierSection.data.length) {
  50. earlierSection.data.reverse();
  51. displayableList.push(earlierSection);
  52. }
  53. return displayableList;
  54. }
  55. /**
  56. * Returns <tt>true</tt> if recent list is enabled and <tt>false</tt> otherwise.
  57. *
  58. * @returns {boolean} <tt>true</tt> if recent list is enabled and <tt>false</tt>
  59. * otherwise.
  60. */
  61. export function isRecentListEnabled() {
  62. return true;
  63. }