Users.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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, index) in users.loggedIn" :key="index">
  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"
  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/ui/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({
  91. content: "Failed to copy to clipboard.",
  92. timeout: 8000
  93. });
  94. }
  95. }
  96. }
  97. };
  98. </script>
  99. <style lang="scss" scoped>
  100. @import "../../../../styles/global.scss";
  101. .night-mode {
  102. #users {
  103. background-color: $night-mode-bg-secondary !important;
  104. border: 0 !important;
  105. }
  106. a {
  107. color: $night-mode-text;
  108. background-color: $dark-grey-2 !important;
  109. border: 0 !important;
  110. &:hover {
  111. color: lighten($night-mode-text, 10%) !important;
  112. }
  113. }
  114. }
  115. .notification-box-enter-active,
  116. .fade-leave-active {
  117. transition: opacity 0.5s;
  118. }
  119. .notification-box-enter,
  120. .notification-box-leave-to {
  121. opacity: 0;
  122. }
  123. #users {
  124. background-color: #fff;
  125. margin-bottom: 20px;
  126. border-radius: 0 0 5px 5px;
  127. max-height: 100%;
  128. .menu {
  129. padding: 0 10px;
  130. margin-top: 20px;
  131. width: 100%;
  132. overflow: auto;
  133. height: calc(100% - 20px - 40px);
  134. .menu-list {
  135. padding: 0 10px;
  136. }
  137. li {
  138. &:not(:first-of-type) {
  139. margin-top: 10px;
  140. }
  141. a {
  142. display: flex;
  143. align-items: center;
  144. padding: 5px 10px;
  145. border: 0.5px $light-grey-2 solid;
  146. border-radius: 3px;
  147. cursor: pointer;
  148. &:hover {
  149. background-color: #eee;
  150. color: #000;
  151. }
  152. .profile-picture {
  153. margin-right: 10px;
  154. width: 35px;
  155. height: 35px;
  156. font-size: 15px;
  157. }
  158. }
  159. }
  160. }
  161. h5 {
  162. font-size: 20px;
  163. margin-top: 20px;
  164. }
  165. }
  166. </style>