Users.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div id="users">
  3. <h5 class="has-text-centered">Total users: {{ userCount }}</h5>
  4. <transition-group name="notification-box">
  5. <h6
  6. class="has-text-centered"
  7. v-if="
  8. users.loggedIn &&
  9. users.loggedOut &&
  10. ((users.loggedIn.length === 1 &&
  11. users.loggedOut.length === 0) ||
  12. (users.loggedIn.length === 0 &&
  13. users.loggedOut.length === 1))
  14. "
  15. key="only-me"
  16. >
  17. It's just you in the station!
  18. </h6>
  19. <h6
  20. class="has-text-centered"
  21. v-else-if="
  22. users.loggedIn &&
  23. users.loggedOut &&
  24. users.loggedOut.length > 0
  25. "
  26. key="logged-out-users"
  27. >
  28. {{ users.loggedOut.length }}
  29. {{ users.loggedOut.length > 1 ? "users are" : "user is" }}
  30. logged-out.
  31. </h6>
  32. </transition-group>
  33. <aside class="menu">
  34. <ul class="menu-list scrollable-list">
  35. <li v-for="user in users.loggedIn" :key="user.username">
  36. <router-link
  37. :to="{
  38. name: 'profile',
  39. params: { username: user.username }
  40. }"
  41. target="_blank"
  42. >
  43. <profile-picture
  44. :avatar="user.avatar"
  45. :name="user.name ? user.name : user.username"
  46. />
  47. {{ user.username }}
  48. </router-link>
  49. </li>
  50. </ul>
  51. </aside>
  52. <button
  53. class="button is-primary tab-actionable-button"
  54. @click="copyToClipboard()"
  55. >
  56. <i class="material-icons icon-with-button">share</i>
  57. <span> Share (copy to clipboard) </span>
  58. </button>
  59. </div>
  60. </template>
  61. <script>
  62. import { mapState } from "vuex";
  63. import Toast from "toasters";
  64. import ProfilePicture from "@/components/ProfilePicture.vue";
  65. export default {
  66. components: { ProfilePicture },
  67. data() {
  68. return {
  69. notesUri: "",
  70. frontendDomain: ""
  71. };
  72. },
  73. computed: mapState({
  74. users: state => state.station.users,
  75. userCount: state => state.station.userCount
  76. }),
  77. async mounted() {
  78. this.frontendDomain = await lofig.get("frontendDomain");
  79. this.notesUri = encodeURI(`${this.frontendDomain}/assets/notes.png`);
  80. },
  81. methods: {
  82. async copyToClipboard() {
  83. try {
  84. await navigator.clipboard.writeText(
  85. this.frontendDomain + this.$route.fullPath
  86. );
  87. } catch (err) {
  88. new Toast("Failed to copy to clipboard.");
  89. }
  90. }
  91. }
  92. };
  93. </script>
  94. <style lang="less" scoped>
  95. .night-mode {
  96. #users {
  97. background-color: var(--dark-grey-3) !important;
  98. border: 0 !important;
  99. }
  100. a {
  101. color: var(--light-grey-2);
  102. background-color: var(--dark-grey-2) !important;
  103. border: 0 !important;
  104. &:hover {
  105. color: var(--light-grey) !important;
  106. }
  107. }
  108. }
  109. .notification-box-enter-active,
  110. .fade-leave-active {
  111. transition: opacity 0.5s;
  112. }
  113. .notification-box-enter,
  114. .notification-box-leave-to {
  115. opacity: 0;
  116. }
  117. #users {
  118. background-color: var(--white);
  119. margin-bottom: 20px;
  120. border-radius: 0 0 5px 5px;
  121. max-height: 100%;
  122. .menu {
  123. padding: 0 10px;
  124. margin-top: 20px;
  125. width: 100%;
  126. overflow: auto;
  127. height: calc(100% - 20px - 40px);
  128. .menu-list {
  129. padding: 0 10px;
  130. margin-left: 0;
  131. }
  132. li {
  133. &:not(:first-of-type) {
  134. margin-top: 10px;
  135. }
  136. a {
  137. display: flex;
  138. align-items: center;
  139. padding: 5px 10px;
  140. border: 0.5px var(--light-grey-3) solid;
  141. border-radius: 3px;
  142. cursor: pointer;
  143. &:hover {
  144. background-color: var(--light-grey);
  145. color: var(--black);
  146. }
  147. .profile-picture {
  148. margin-right: 10px;
  149. width: 35px;
  150. height: 35px;
  151. }
  152. /deep/ .profile-picture.using-initials span {
  153. font-size: calc(
  154. 35px / 5 * 2
  155. ); // 2/5th of .profile-picture height/width
  156. }
  157. }
  158. }
  159. }
  160. h5 {
  161. font-size: 20px;
  162. margin-top: 20px;
  163. }
  164. }
  165. </style>