Users.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <script setup lang="ts">
  2. import { useRoute } from "vue-router";
  3. import { defineAsyncComponent, ref, onMounted } from "vue";
  4. import Toast from "toasters";
  5. import { storeToRefs } from "pinia";
  6. import { useWebsocketsStore } from "@/stores/websockets";
  7. import { useStationStore } from "@/stores/station";
  8. import { useUserAuthStore } from "@/stores/userAuth";
  9. const ProfilePicture = defineAsyncComponent(
  10. () => import("@/components/ProfilePicture.vue")
  11. );
  12. const stationStore = useStationStore();
  13. const route = useRoute();
  14. const notesUri = ref("");
  15. const frontendDomain = ref("");
  16. const tab = ref("active");
  17. const tabs = ref([]);
  18. const { socket } = useWebsocketsStore();
  19. const { station, users, userCount } = storeToRefs(stationStore);
  20. const { hasPermission } = useUserAuthStore();
  21. const copyToClipboard = async () => {
  22. try {
  23. await navigator.clipboard.writeText(
  24. frontendDomain.value + route.fullPath
  25. );
  26. } catch (err) {
  27. new Toast("Failed to copy to clipboard.");
  28. }
  29. };
  30. const showTab = _tab => {
  31. tabs.value[`${_tab}-tab`].scrollIntoView({ block: "nearest" });
  32. tab.value = _tab;
  33. };
  34. const addDj = userId => {
  35. socket.dispatch("stations.addDj", station.value._id, userId, res => {
  36. new Toast(res.message);
  37. });
  38. };
  39. const removeDj = userId => {
  40. socket.dispatch("stations.removeDj", station.value._id, userId, res => {
  41. new Toast(res.message);
  42. });
  43. };
  44. onMounted(async () => {
  45. frontendDomain.value = await lofig.get("frontendDomain");
  46. notesUri.value = encodeURI(`${frontendDomain.value}/assets/notes.png`);
  47. });
  48. </script>
  49. <template>
  50. <div id="users">
  51. <div class="tabs-container">
  52. <div v-if="hasPermission('stations.update')" class="tab-selection">
  53. <button
  54. class="button is-default"
  55. :ref="el => (tabs['active-tab'] = el)"
  56. :class="{ selected: tab === 'active' }"
  57. @click="showTab('active')"
  58. >
  59. Active
  60. </button>
  61. <button
  62. class="button is-default"
  63. :ref="el => (tabs['djs-tab'] = el)"
  64. :class="{ selected: tab === 'djs' }"
  65. @click="showTab('djs')"
  66. >
  67. DJs
  68. </button>
  69. </div>
  70. <div class="tab" v-show="tab === 'active'">
  71. <h5 class="has-text-centered">Total users: {{ userCount }}</h5>
  72. <transition-group name="notification-box">
  73. <h6
  74. class="has-text-centered"
  75. v-if="
  76. users.loggedIn &&
  77. users.loggedOut &&
  78. ((users.loggedIn.length === 1 &&
  79. users.loggedOut.length === 0) ||
  80. (users.loggedIn.length === 0 &&
  81. users.loggedOut.length === 1))
  82. "
  83. key="only-me"
  84. >
  85. It's just you in the station!
  86. </h6>
  87. <h6
  88. class="has-text-centered"
  89. v-else-if="
  90. users.loggedIn &&
  91. users.loggedOut &&
  92. users.loggedOut.length > 0
  93. "
  94. key="logged-out-users"
  95. >
  96. {{ users.loggedOut.length }}
  97. {{
  98. users.loggedOut.length > 1 ? "users are" : "user is"
  99. }}
  100. logged-out.
  101. </h6>
  102. </transition-group>
  103. <aside class="menu">
  104. <ul class="menu-list scrollable-list">
  105. <li v-for="user in users.loggedIn" :key="user.username">
  106. <router-link
  107. :to="{
  108. name: 'profile',
  109. params: { username: user.username }
  110. }"
  111. target="_blank"
  112. >
  113. <profile-picture
  114. :avatar="user.avatar"
  115. :name="user.name || user.username"
  116. />
  117. {{ user.name || user.username }}
  118. <span
  119. v-if="user._id === station.owner"
  120. class="material-icons user-rank"
  121. content="Station Owner"
  122. v-tippy="{ theme: 'info' }"
  123. >local_police</span
  124. >
  125. <span
  126. v-else-if="
  127. station.djs.find(
  128. dj => dj._id === user._id
  129. )
  130. "
  131. class="material-icons user-rank"
  132. content="Station DJ"
  133. v-tippy="{ theme: 'info' }"
  134. >shield</span
  135. >
  136. <button
  137. v-if="
  138. hasPermission('stations.djs.add') &&
  139. !station.djs.find(
  140. dj => dj._id === user._id
  141. ) &&
  142. station.owner !== user._id
  143. "
  144. class="button is-primary material-icons"
  145. @click.prevent="addDj(user._id)"
  146. content="Promote user to DJ"
  147. v-tippy
  148. >
  149. add_moderator
  150. </button>
  151. <button
  152. v-else-if="
  153. hasPermission('stations.djs.remove') &&
  154. station.djs.find(
  155. dj => dj._id === user._id
  156. )
  157. "
  158. class="button is-danger material-icons"
  159. @click.prevent="removeDj(user._id)"
  160. content="Demote user from DJ"
  161. v-tippy
  162. >
  163. remove_moderator
  164. </button>
  165. </router-link>
  166. </li>
  167. </ul>
  168. </aside>
  169. </div>
  170. <div
  171. v-if="hasPermission('stations.update')"
  172. class="tab"
  173. v-show="tab === 'djs'"
  174. >
  175. <h5 class="has-text-centered">Station DJs</h5>
  176. <h6 class="has-text-centered">
  177. Add/remove DJs, who can manage the station and queue.
  178. </h6>
  179. <aside class="menu">
  180. <ul class="menu-list scrollable-list">
  181. <li v-for="dj in station.djs" :key="dj._id">
  182. <router-link
  183. :to="{
  184. name: 'profile',
  185. params: { username: dj.username }
  186. }"
  187. target="_blank"
  188. >
  189. <profile-picture
  190. :avatar="dj.avatar"
  191. :name="dj.name || dj.username"
  192. />
  193. {{ dj.name || dj.username }}
  194. <span
  195. class="material-icons user-rank"
  196. content="Station DJ"
  197. v-tippy="{ theme: 'info' }"
  198. >shield</span
  199. >
  200. <button
  201. v-if="hasPermission('stations.djs.remove')"
  202. class="button is-danger material-icons"
  203. @click.prevent="removeDj(dj._id)"
  204. content="Demote user from DJ"
  205. v-tippy
  206. >
  207. remove_moderator
  208. </button>
  209. </router-link>
  210. </li>
  211. </ul>
  212. </aside>
  213. </div>
  214. </div>
  215. <button
  216. class="button is-primary tab-actionable-button"
  217. @click="copyToClipboard()"
  218. >
  219. <i class="material-icons icon-with-button">share</i>
  220. <span> Share (copy to clipboard) </span>
  221. </button>
  222. </div>
  223. </template>
  224. <style lang="less" scoped>
  225. .night-mode {
  226. #users {
  227. background-color: var(--dark-grey-3) !important;
  228. border: 0 !important;
  229. }
  230. a {
  231. color: var(--light-grey-2);
  232. background-color: var(--dark-grey-2) !important;
  233. border: 0 !important;
  234. &:hover {
  235. color: var(--light-grey) !important;
  236. }
  237. }
  238. .tabs-container .tab-selection .button {
  239. background: var(--dark-grey) !important;
  240. color: var(--white) !important;
  241. }
  242. }
  243. .notification-box-enter-active,
  244. .fade-leave-active {
  245. transition: opacity 0.5s;
  246. }
  247. .notification-box-enter,
  248. .notification-box-leave-to {
  249. opacity: 0;
  250. }
  251. #users {
  252. background-color: var(--white);
  253. margin-bottom: 20px;
  254. border-radius: 0 0 @border-radius @border-radius;
  255. max-height: 100%;
  256. .tabs-container {
  257. padding: 10px;
  258. .tab-selection {
  259. display: flex;
  260. overflow-x: auto;
  261. margin-bottom: 20px;
  262. .button {
  263. border-radius: 0;
  264. border: 0;
  265. text-transform: uppercase;
  266. font-size: 14px;
  267. color: var(--dark-grey-3);
  268. background-color: var(--light-grey-2);
  269. flex-grow: 1;
  270. height: 32px;
  271. &:not(:first-of-type) {
  272. margin-left: 5px;
  273. }
  274. }
  275. .selected {
  276. background-color: var(--primary-color) !important;
  277. color: var(--white) !important;
  278. font-weight: 600;
  279. }
  280. }
  281. .tab {
  282. .menu {
  283. margin-top: 20px;
  284. width: 100%;
  285. overflow: auto;
  286. height: calc(100% - 20px - 40px);
  287. .menu-list {
  288. margin-left: 0;
  289. padding: 0;
  290. }
  291. li {
  292. &:not(:first-of-type) {
  293. margin-top: 10px;
  294. }
  295. a {
  296. display: flex;
  297. align-items: center;
  298. padding: 5px 10px;
  299. border: 0.5px var(--light-grey-3) solid;
  300. border-radius: @border-radius;
  301. cursor: pointer;
  302. &:hover {
  303. background-color: var(--light-grey);
  304. color: var(--black);
  305. }
  306. .profile-picture {
  307. margin-right: 10px;
  308. width: 36px;
  309. height: 36px;
  310. }
  311. :deep(.profile-picture.using-initials span) {
  312. font-size: calc(
  313. 36px / 5 * 2
  314. ); // 2/5th of .profile-picture height/width
  315. }
  316. .user-rank {
  317. color: var(--primary-color);
  318. font-size: 18px;
  319. margin: 0 5px;
  320. }
  321. .button {
  322. margin-left: auto;
  323. font-size: 18px;
  324. width: 36px;
  325. }
  326. }
  327. }
  328. }
  329. h5 {
  330. font-size: 20px;
  331. }
  332. }
  333. }
  334. }
  335. </style>