Skip to content

Commit

Permalink
Show what the user is doing on their profile
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Aug 28, 2024
1 parent 99fa15f commit 9e1e6a3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/app/api/token-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class TokenStorageService {
return JSON.parse(str);
} catch (e) {
console.error("Failed to retrieve stored user", e, str);
this.ClearStoredUser()
return null;
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/app/components/ui/info/user-status.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {Component, Input} from '@angular/core';
import {Room} from "../../../api/types/rooms/room";
import {LevelLinkComponent} from "../text/links/level-link.component";

@Component({
selector: 'app-user-status',
standalone: true,
imports: [
LevelLinkComponent
],
template: `
@if(activeRoom) {
<div class="bg-green w-2 h-2 rounded-full inline-block align-middle mr-1"></div>
<span class="text-secondary-bright">
Online,
@switch (activeRoom.levelType) {
@case (0) {
<span>playing a story level</span>
}
@case(1) {
<span>playing <app-level-link [level]="null" [levelId]="activeRoom.levelId"></app-level-link></span>
}
@case (2) {
<span>on the moon</span>
}
@case (5) {
<span>in the pod</span>
}
@default {
<span>unhandled level type {{activeRoom.levelType}}</span>
}
}
</span>
} @else {
<div class="bg-secondary w-2 h-2 rounded-full inline-block align-middle mr-1"></div>
<span class="text-secondary">Offline</span>
}
`
})
export class UserStatusComponent {
@Input() activeRoom: Room | undefined;
}
4 changes: 2 additions & 2 deletions src/app/components/ui/layouts/fancy-header.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Input, OnDestroy} from '@angular/core';
import {Component, Input} from '@angular/core';
import {ContainerHeaderComponent} from "../container-header.component";
import {DarkContainerComponent} from "../dark-container.component";
import {DateComponent} from "../info/date.component";
Expand All @@ -7,7 +7,6 @@ import {PageTitleComponent} from "../text/page-title.component";
import {LevelStatisticsComponent} from "../../items/level-statistics.component";
import { AsyncPipe, NgTemplateOutlet } from "@angular/common";
import {LayoutService} from "../../../services/layout.service";
import {Subscription} from "rxjs";

@Component({
selector: 'app-fancy-header',
Expand Down Expand Up @@ -39,6 +38,7 @@ import {Subscription} from "rxjs";
<ng-content select="[titleSubtext]"></ng-content>
</span>
</div>
<ng-content select="[belowTitle]"></ng-content>
<ng-content select="[statistics]"></ng-content>
@if (!(layout.isMobile | async)) {
<ng-container *ngTemplateOutlet="descriptionTemplate"></ng-container>
Expand Down
18 changes: 12 additions & 6 deletions src/app/pages/user/user.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
@if (user) {
<app-fancy-header [title]="user.username" [description]="user.description | default: user.username + ' hasn\'t introduced themselves yet.'">
<app-user-avatar [user]="user" [size]="(layout.isMobile | async) ? 90 : 176" avatar></app-user-avatar>
<ng-container titleSubtext>
Joined <app-date [date]="user.joinDate"></app-date>
</ng-container>
</app-fancy-header>
<app-fancy-header [title]="user.username"
[description]="user.description | default: user.username + ' hasn\'t introduced themselves yet.'">
<app-user-avatar [user]="user" [size]="(layout.isMobile | async) ? 90 : 176" avatar></app-user-avatar>
<ng-container titleSubtext>
Joined
<app-date [date]="user.joinDate"></app-date>
<br>
</ng-container>
<ng-container belowTitle>
<app-user-status [activeRoom]="user.activeRoom"></app-user-status>
</ng-container>
</app-fancy-header>
}
8 changes: 5 additions & 3 deletions src/app/pages/user/user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import {UserAvatarComponent} from "../../components/ui/photos/user-avatar.compon
import {DateComponent} from "../../components/ui/info/date.component";
import {FancyHeaderComponent} from "../../components/ui/layouts/fancy-header.component";
import {LayoutService} from "../../services/layout.service";
import {UserStatusComponent} from "../../components/ui/info/user-status.component";

@Component({
selector: 'app-user',
standalone: true,
imports: [
imports: [
DefaultPipe,
UserAvatarComponent,
DateComponent,
FancyHeaderComponent,
AsyncPipe
],
AsyncPipe,
UserStatusComponent
],
templateUrl: './user.component.html',
styles: ``
})
Expand Down

0 comments on commit 9e1e6a3

Please sign in to comment.