App.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div id="toasts">
  3. <span v-for="toast in toasts" v-bind:class="toast.class">{{toast.text}}</span>
  4. </div>
  5. <div>
  6. <router-view></router-view>
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. replace: false,
  12. data() {
  13. return {
  14. home: {
  15. visible: true
  16. },
  17. station: {
  18. visible: false
  19. },
  20. register: {
  21. email: "",
  22. username: "",
  23. password: ""
  24. },
  25. login: {
  26. email: "",
  27. password: ""
  28. },
  29. likes: [],
  30. dislikes: [],
  31. loggedIn: true,
  32. groups: [
  33. {
  34. id: "lu08gw56571r4497wrk9",
  35. name: "Official Rooms",
  36. rooms: [
  37. { id: "73qvw65746acvo8yqfr", thumbnail: "https://lh6.googleusercontent.com/-ghASz3s6yL4/AAAAAAAAAAI/AAAAAAAAALc/tFblPp2myu0/s0-c-k-no-ns/photo.jpg", name: "Country", description: "Johnny Cash - I Walk The Line", users: 10 },
  38. { id: "enxcysmhn1k7ld56ogvi", thumbnail: "http://66.media.tumblr.com/1734069af425e491fae7deae0a19869f/tumblr_o0i0xmIYrF1v421f2o1_1280.jpg", name: "Pop", description: "Sia - Cheap Thrills", users: 14 },
  39. { id: "kqa99gbva7lij05dn29", thumbnail: "http://www.youredm.com/wp-content/uploads/2014/09/taking-you-higher.jpg", name: "Chill", description: "MrSuicideSheep - Taking you higher", users: 13 },
  40. { id: "w19hu791iiub6wmjf9a4i", thumbnail: "http://edmsauce.wpengine.netdna-cdn.com/wp-content/uploads/2012/12/Deadmau5-album-title-goes-here.jpg", name: "EDM", description: "Deadmau5 - There Might Be Coffee", users: 13 }
  41. ]
  42. },
  43. {
  44. id: "g2b8v03xaedj8ht1emi",
  45. name: "Trending Rooms",
  46. rooms: [
  47. { id: "73qvw65746acvo8yqfr", thumbnail: "https://lh6.googleusercontent.com/-ghASz3s6yL4/AAAAAAAAAAI/AAAAAAAAALc/tFblPp2myu0/s0-c-k-no-ns/photo.jpg", name: "Country", description: "Johnny Cash - I Walk The Line", users: 10 },
  48. { id: "enxcysmhn1k7ld56ogvi", thumbnail: "http://66.media.tumblr.com/1734069af425e491fae7deae0a19869f/tumblr_o0i0xmIYrF1v421f2o1_1280.jpg", name: "Pop", description: "Sia - Cheap Thrills", users: 14 },
  49. { id: "kqa99gbva7lij05dn29", thumbnail: "http://www.youredm.com/wp-content/uploads/2014/09/taking-you-higher.jpg", name: "Chill", description: "MrSuicideSheep - Taking you higher", users: 13 },
  50. { id: "w19hu791iiub6wmjf9a4i", thumbnail: "http://edmsauce.wpengine.netdna-cdn.com/wp-content/uploads/2012/12/Deadmau5-album-title-goes-here.jpg", name: "EDM", description: "Deadmau5 - There Might Be Coffee", users: 13 }
  51. ]
  52. }
  53. ],
  54. toastCount: 0,
  55. toasts: []
  56. }
  57. },
  58. methods: {
  59. logout() {
  60. $.ajax({
  61. method: "GET",
  62. url: "/users/logout",
  63. dataType: "json",
  64. complete: function (msg) {
  65. alert("Logged in!");
  66. location.reload();
  67. }
  68. });
  69. },
  70. toast(text, duration) {
  71. let local = this;
  72. let id = local.toastCount++;
  73. this.toasts.push({id: id, text: text, class: "toast toast-add"});
  74. if (duration > 250) {
  75. setTimeout(function() {
  76. local.toasts = local.toasts.map(function(toast) {
  77. if (toast.id === id) {
  78. toast.class = "toast";
  79. }
  80. return toast;
  81. });
  82. }, 250);
  83. }
  84. setTimeout(function() {
  85. local.toasts = local.toasts.map(function(toast) {
  86. if (toast.id === id) {
  87. toast.class = "toast toast-remove";
  88. }
  89. return toast;
  90. });
  91. setTimeout(function() {
  92. local.toasts = local.toasts.filter(function(toast) {
  93. return toast.id !== id;
  94. });
  95. }, 250);
  96. }, duration);
  97. }
  98. },
  99. ready: function () {
  100. let local = this;
  101. local.socket = io();
  102. local.socket.on("ready", status => {
  103. local.loggedIn = status;
  104. local.socket.emit("/user/ratings", result => {
  105. if (!result.err) {
  106. local.likes = result.likes;
  107. local.dislikes = result.dislikes;
  108. }
  109. });
  110. });
  111. },
  112. events: {
  113. 'register': function() {
  114. console.log('registered');
  115. $.ajax({
  116. method: "POST",
  117. url: "/users/register",
  118. data: JSON.stringify({
  119. email: this.register.email,
  120. username: this.register.username,
  121. password: this.register.password,
  122. recaptcha: grecaptcha.getResponse()
  123. }),
  124. contentType: "application/json; charset=utf-8",
  125. dataType: "json",
  126. success: function (msg) {
  127. if (msg) console.log(msg);
  128. alert("Registered!");
  129. //do something
  130. },
  131. error: function (err) {
  132. if (err) console.log(err);
  133. alert("Not registered!");
  134. //do something else
  135. }
  136. });
  137. },
  138. 'login': function() {
  139. console.log('login');
  140. $.ajax({
  141. method: "POST",
  142. url: "/users/login",
  143. data: JSON.stringify({
  144. email: this.login.email,
  145. password: this.login.password
  146. }),
  147. contentType: "application/json; charset=utf-8",
  148. dataType: "json",
  149. success: function (msg) {
  150. if (msg) console.log(msg);
  151. alert("Logged in!");
  152. //do something
  153. },
  154. error: function (err) {
  155. if (err) console.log(err);
  156. alert("Not logged in!");
  157. //do something else
  158. }
  159. });
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="sass" scoped>
  165. #toasts {
  166. position: fixed;
  167. z-index: 100000;
  168. right: 5%;
  169. top: 10%;
  170. max-width: 90%;
  171. .toast {
  172. width: 100%;
  173. height: auto;
  174. padding: 10px 20px;
  175. border-radius: 3px;
  176. color: white;
  177. background-color: #424242;
  178. display: -webkit-flex;
  179. display: -ms-flexbox;
  180. display: flex;
  181. margin-bottom: 10px;
  182. font-size: 1.18em;
  183. font-weight: 400;
  184. box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16), 0 2px 10px 0 rgba(0,0,0,0.12);
  185. transition: all 0.25s ease;
  186. }
  187. .toast-remove {
  188. opacity: 0;
  189. margin-top: -50px;
  190. }
  191. .toast-add {
  192. opacity: 0;
  193. margin-top: 50px;
  194. }
  195. }
  196. </style>