Users.vue 3.5 KB

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