bookmarks.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Template.bookmarks.helpers({
  2. hasStarredBoards() {
  3. const user = ReactiveCache.getCurrentUser();
  4. if (!user) return false;
  5. const { starredBoards = [] } = user.profile || {};
  6. return Array.isArray(starredBoards) && starredBoards.length > 0;
  7. },
  8. starredBoards() {
  9. const user = ReactiveCache.getCurrentUser();
  10. if (!user) return [];
  11. const { starredBoards = [] } = user.profile || {};
  12. if (!Array.isArray(starredBoards) || starredBoards.length === 0) return [];
  13. return Boards.find({ _id: { $in: starredBoards } }, { sort: { sort: 1 } });
  14. },
  15. });
  16. Template.bookmarks.events({
  17. 'click .js-toggle-star'(e) {
  18. e.preventDefault();
  19. const boardId = this._id;
  20. const user = ReactiveCache.getCurrentUser();
  21. if (user && boardId) {
  22. user.toggleBoardStar(boardId);
  23. }
  24. },
  25. });
  26. Template.bookmarksPopup.helpers({
  27. hasStarredBoards() {
  28. const user = ReactiveCache.getCurrentUser();
  29. if (!user) return false;
  30. const { starredBoards = [] } = user.profile || {};
  31. return Array.isArray(starredBoards) && starredBoards.length > 0;
  32. },
  33. starredBoards() {
  34. const user = ReactiveCache.getCurrentUser();
  35. if (!user) return [];
  36. const { starredBoards = [] } = user.profile || {};
  37. if (!Array.isArray(starredBoards) || starredBoards.length === 0) return [];
  38. return Boards.find({ _id: { $in: starredBoards } }, { sort: { sort: 1 } });
  39. },
  40. });
  41. Template.bookmarksPopup.events({
  42. 'click .js-toggle-star'(e) {
  43. e.preventDefault();
  44. const boardId = this._id;
  45. const user = ReactiveCache.getCurrentUser();
  46. if (user && boardId) {
  47. user.toggleBoardStar(boardId);
  48. }
  49. },
  50. });