123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <template>
- <div v-if="isUser">
- <main-header />
- <div class="container">
- <img class="avatar" src="/assets/notes.png" />
- <h2 class="has-text-centered username">@{{ user.username }}</h2>
- <h5>A member since {{ user.createdAt }}</h5>
- <div
- v-if="
- $parent.role === 'admin' && !($parent.userId === user._id)
- "
- class="admin-functionality"
- >
- <a
- v-if="user.role == 'default'"
- class="button is-small is-info is-outlined"
- @click="changeRank('admin')"
- >Promote to Admin</a
- >
- <a
- v-if="user.role == 'admin'"
- class="button is-small is-danger is-outlined"
- @click="changeRank('default')"
- >Demote to User</a
- >
- </div>
- <nav class="level">
- <div class="level-item has-text-centered">
- <p class="heading">
- Rank
- </p>
- <p class="title role">
- {{ user.role }}
- </p>
- </div>
- <div class="level-item has-text-centered">
- <p class="heading">
- Songs Requested
- </p>
- <p class="title">
- {{ user.statistics.songsRequested }}
- </p>
- </div>
- <div class="level-item has-text-centered">
- <p class="heading">
- Likes
- </p>
- <p class="title">
- {{ user.liked.length }}
- </p>
- </div>
- <div class="level-item has-text-centered">
- <p class="heading">
- Dislikes
- </p>
- <p class="title">
- {{ user.disliked.length }}
- </p>
- </div>
- </nav>
- </div>
- <main-footer />
- </div>
- </template>
- <script>
- import { Toast } from "vue-roaster";
- import MainHeader from "../MainHeader.vue";
- import MainFooter from "../MainFooter.vue";
- import io from "../../io";
- export default {
- components: { MainHeader, MainFooter },
- data() {
- return {
- user: {},
- isUser: false
- };
- },
- mounted() {
- const _this = this;
- io.getSocket(socket => {
- _this.socket = socket;
- _this.socket.emit(
- "users.findByUsername",
- _this.$route.params.username,
- res => {
- if (res.status === "error") this.$router.go("/404");
- else {
- _this.user = res.data;
- this.user.createdAt = moment(
- this.user.createdAt
- ).format("LL");
- _this.isUser = true;
- }
- }
- );
- });
- },
- methods: {
- changeRank(newRank) {
- this.socket.emit(
- "users.updateRole",
- this.user._id,
- newRank === "admin" ? "admin" : "default",
- res => {
- if (res.status === "error")
- Toast.methods.addToast(res.message, 2000);
- else this.user.role = newRank;
- Toast.methods.addToast(
- `User ${this.$route.params.username}'s rank has been changed to: ${newRank}`,
- 2000
- );
- }
- );
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .container {
- padding: 25px;
- }
- .avatar {
- border-radius: 50%;
- width: 250px;
- display: block;
- margin: auto;
- }
- h5 {
- text-align: center;
- margin-bottom: 25px;
- font-size: 17px;
- }
- .role {
- text-transform: capitalize;
- }
- .level {
- margin-top: 40px;
- }
- .admin-functionality {
- text-align: center;
- margin: 0 auto;
- }
- @media (max-width: 350px) {
- .username {
- font-size: 2.9rem;
- word-wrap: break-all;
- }
- }
- </style>
|