Skip to content

Commit

Permalink
ADD STATUS (FRONTEND):
Browse files Browse the repository at this point in the history
Add user status to profile page.
  • Loading branch information
riblanc committed Oct 6, 2023
1 parent c526786 commit 3428477
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
25 changes: 24 additions & 1 deletion front/components/profile/profile.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<script lang="ts">
import type { User } from '~/types/user';
enum Status {
OFFLINE = 'offline',
ONLINE = 'online',
IN_GAME = 'in game',
}
export default defineNuxtComponent({
props: ['id'],
props: ['id', 'socket'],
data: () => ({
user: null as User | null,
status: Status.OFFLINE
}),
async beforeMount() {
const data = await this.$api.get(`/user/${this.id}`);
Expand All @@ -14,6 +21,13 @@ export default defineNuxtComponent({
return ;
}
this.user = data;
this.status = this.user.status;
this.socket.on(`user:${this.id}:status`, (data: { status: Status }) => {
this.status = data.status;
});
},
async unmounted() {
this.socket.off(`user:${this.id}:status`);
},
methods: {
editable() {
Expand All @@ -25,6 +39,14 @@ export default defineNuxtComponent({
onUpdateUser(user: User) {
console.log(user);
this.user = user;
},
getStatusColor() {
if (this.status === Status.OFFLINE)
return '#be4545';
if (this.status === Status.ONLINE)
return '#62de62';
if (this.status === Status.IN_GAME)
return '#6161c9';
}
}
})
Expand All @@ -37,6 +59,7 @@ export default defineNuxtComponent({
<div class="d-flex flex-column h-100 overflow-auto align-center">
<ProfileAvatar :user="this.user" :editable="this.editable()" @user:updated="this.onUpdateUser" />
<ProfileUsername :user="this.user" :editable="this.editable()" @user:updated="this.onUpdateUser" />
<p :style="{'color': this.getStatusColor()}">{{ this.status }}</p>
</div>
</div>
<div v-else class="d-flex w-100 h-100">
Expand Down
8 changes: 5 additions & 3 deletions front/pages/profile/[id].vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script setup lang="ts">
<script lang="ts">
export default defineNuxtComponent({
props: ['socket'],
})
</script>

<template>
<div class="profile-page d-flex align-center justify-center">
<Profile :id="this.$route.params.id" />
<Profile :socket="this.socket" :id="this.$route.params.id" />
</div>
</template>

Expand Down
5 changes: 4 additions & 1 deletion front/pages/profile/index.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script lang="ts">
export default defineNuxtComponent({
props: ['socket'],
})
</script>

<template>
<div class="profile-page d-flex align-center justify-center">
<Profile :id="this.$auth.user.id" />
<Profile :socket="this.socket" :id="this.$auth.user.id" />
</div>
</template>

Expand Down

0 comments on commit 3428477

Please sign in to comment.