Users.vue 3.6 KB

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