index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. Template Controllers
  3. @module Templates
  4. */
  5. /**
  6. The body template
  7. @class [template] body
  8. @constructor
  9. */
  10. import React from 'react';
  11. import { render } from 'react-dom';
  12. import About from '../../components/About';
  13. import RequestAccount from '../../components/RequestAccount';
  14. const COMPONENTS = {
  15. About,
  16. RequestAccount
  17. };
  18. function renderReactComponentPopup(component) {
  19. const Component = COMPONENTS[component];
  20. if (!!Component) {
  21. render(<Component />, document.getElementById('react-entry'));
  22. }
  23. }
  24. // NOTE: While in the process of converting the Meteor codebase to React,
  25. // generic windows reuse electron windows by replacing either the
  26. // component or the template
  27. ipc.on('uiAction_switchTemplate', (e, templateName) => {
  28. const componentName =
  29. templateName.charAt(0).toUpperCase() + templateName.slice(1);
  30. // If a React component exists, render it
  31. if (!!COMPONENTS[componentName]) {
  32. TemplateVar.setTo(
  33. '#generic-body',
  34. 'MainRenderTemplate',
  35. `popupWindows_generic`
  36. );
  37. renderReactComponentPopup(componentName);
  38. } else {
  39. // Otherwise, use the meteor template
  40. renderReactComponentPopup('');
  41. TemplateVar.setTo(
  42. '#generic-body',
  43. 'MainRenderTemplate',
  44. `popupWindows_${templateName}`
  45. );
  46. }
  47. });
  48. Template.body.helpers({
  49. /**
  50. Chooses the view to render at start
  51. @method renderApp
  52. */
  53. renderApp: function() {
  54. // Generic windows return the TemplateVar if set in the ipc call above
  55. const template = TemplateVar.get('MainRenderTemplate');
  56. if (template) {
  57. return template;
  58. }
  59. if (_.isEmpty(location.hash)) {
  60. $('title').text('Mist');
  61. return 'layout_main';
  62. } else {
  63. const renderWindow = location.hash.match(/#([a-zA-Z]*)_?/);
  64. // TODO: handle React components
  65. const REACT_COMPONENTS = ['about', 'requestAccount'];
  66. if (REACT_COMPONENTS.includes(renderWindow[1])) {
  67. return false;
  68. }
  69. if (renderWindow.length > 0) {
  70. return 'popupWindows_' + renderWindow[1];
  71. } else {
  72. return false;
  73. }
  74. }
  75. }
  76. });
  77. /*
  78. Template.body.events({
  79. /**
  80. On drag over prevent redirect
  81. @event dragover body > *, drop body > *
  82. *
  83. 'dragover body > *, drop body > *': function(e){
  84. e.preventDefault();
  85. },
  86. });*/