Users.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 class="optional-desktop-only-text">
  58. Share (copy to clipboard)
  59. </span>
  60. </button>
  61. </div>
  62. </template>
  63. <script>
  64. import { mapState } from "vuex";
  65. import Toast from "toasters";
  66. import ProfilePicture from "@/components/ProfilePicture.vue";
  67. export default {
  68. components: { ProfilePicture },
  69. data() {
  70. return {
  71. notesUri: "",
  72. frontendDomain: ""
  73. };
  74. },
  75. computed: mapState({
  76. users: state => state.station.users,
  77. userCount: state => state.station.userCount
  78. }),
  79. async mounted() {
  80. this.frontendDomain = await lofig.get("frontendDomain");
  81. this.notesUri = encodeURI(`${this.frontendDomain}/assets/notes.png`);
  82. },
  83. methods: {
  84. async copyToClipboard() {
  85. try {
  86. await navigator.clipboard.writeText(
  87. this.frontendDomain + this.$route.fullPath
  88. );
  89. } catch (err) {
  90. new Toast("Failed to copy to clipboard.");
  91. }
  92. }
  93. }
  94. };
  95. </script>
  96. <style lang="scss" scoped>
  97. .night-mode {
  98. #users {
  99. background-color: var(--dark-grey-3) !important;
  100. border: 0 !important;
  101. }
  102. a {
  103. color: var(--light-grey-2);
  104. background-color: var(--dark-grey-2) !important;
  105. border: 0 !important;
  106. &:hover {
  107. color: var(--light-grey) !important;
  108. }
  109. }
  110. }
  111. .notification-box-enter-active,
  112. .fade-leave-active {
  113. transition: opacity 0.5s;
  114. }
  115. .notification-box-enter,
  116. .notification-box-leave-to {
  117. opacity: 0;
  118. }
  119. #users {
  120. background-color: var(--white);
  121. margin-bottom: 20px;
  122. border-radius: 0 0 5px 5px;
  123. max-height: 100%;
  124. .menu {
  125. padding: 0 10px;
  126. margin-top: 20px;
  127. width: 100%;
  128. overflow: auto;
  129. height: calc(100% - 20px - 40px);
  130. .menu-list {
  131. padding: 0 10px;
  132. }
  133. li {
  134. &:not(:first-of-type) {
  135. margin-top: 10px;
  136. }
  137. a {
  138. display: flex;
  139. align-items: center;
  140. padding: 5px 10px;
  141. border: 0.5px var(--light-grey-3) solid;
  142. border-radius: 3px;
  143. cursor: pointer;
  144. &:hover {
  145. background-color: var(--light-grey);
  146. color: var(--black);
  147. }
  148. .profile-picture {
  149. margin-right: 10px;
  150. width: 35px;
  151. height: 35px;
  152. font-size: 15px;
  153. }
  154. }
  155. }
  156. }
  157. h5 {
  158. font-size: 20px;
  159. margin-top: 20px;
  160. }
  161. }
  162. </style>