diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 138f727..863bb30 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,7 +1,7 @@ import { BrowserModule } from "@angular/platform-browser"; import { NgModule } from "@angular/core"; -import { NgbModalModule } from "@ng-bootstrap/ng-bootstrap"; +import { NgbModalModule, NgbTooltipModule } from "@ng-bootstrap/ng-bootstrap"; import { AppRoutingModule } from './app-routing.module'; import { FormsModule } from '@angular/forms'; @@ -34,13 +34,14 @@ import { InputManagerComponent } from './input-manager/input-manager.component'; ChannelComponent, SidebarComponent, DashboardComponent, - InputManagerComponent + InputManagerComponent, ], imports: [ BrowserModule, NgbModalModule, AppRoutingModule, FormsModule, + NgbTooltipModule, ], providers: [ MessageService, diff --git a/src/app/channel/channel.component.html b/src/app/channel/channel.component.html index f73df88..bdaff8f 100644 --- a/src/app/channel/channel.component.html +++ b/src/app/channel/channel.component.html @@ -17,7 +17,7 @@
diff --git a/src/app/channel/channel.component.scss b/src/app/channel/channel.component.scss index 54bbb5b..dc25b40 100644 --- a/src/app/channel/channel.component.scss +++ b/src/app/channel/channel.component.scss @@ -26,6 +26,10 @@ &::-webkit-scrollbar-button { display: none; } + + .deleteMessage { + cursor: pointer; + } } .inputRow { width: 100%; diff --git a/src/app/channel/channel.component.ts b/src/app/channel/channel.component.ts index 2bfe7d9..6aa5942 100644 --- a/src/app/channel/channel.component.ts +++ b/src/app/channel/channel.component.ts @@ -1,7 +1,5 @@ import { Component, OnInit } from "@angular/core"; -import { DomSanitizer } from '@angular/platform-browser'; import { ActivatedRoute, Router } from '@angular/router'; -import { NgbModal } from "@ng-bootstrap/ng-bootstrap"; import { SupabaseAuthUser } from '@supabase/supabase-js'; import { Subject } from 'rxjs'; import { take, takeUntil, map } from 'rxjs/operators'; @@ -25,19 +23,21 @@ export class ChannelComponent implements OnInit { $destroy: Subject = new Subject(); dataUpdated: boolean = false; messageInput: string = ''; + user: SupabaseAuthUser; constructor( private channelService: ChannelService, - private modalService: NgbModal, private supaService: SupaService, private route: ActivatedRoute, - private sanitizer: DomSanitizer, private userService: UserService, private router: Router, private messageService: MessageService, ) { } ngOnInit() { + this.supaService.client.auth.user() + .then(user => this.user = user) + .catch(error => console.error(error)); this.route.params.subscribe( params => { this.reset(); @@ -90,12 +90,11 @@ export class ChannelComponent implements OnInit { ); } - async sendMessage(text: string) { - if (!this.channel || !text) { + sendMessage(text: string) { + if (!this.channel || !text || !this.user) { return; } - const user: SupabaseAuthUser = await this.supaService.client.auth.user(); - const message = new Message(this.channel.id, user.id, text); + const message = new Message(this.channel.id, this.user.id, text); this.messageService.addOne(message).pipe(take(1)).subscribe( data => { console.log('Success', data); @@ -106,6 +105,23 @@ export class ChannelComponent implements OnInit { ); } + deleteMessage(message: Message) { + if (!message) { + return; + } + const confirm = window.confirm(`Do you want to delete the message "${message.message}"?`) + if (confirm) { + this.messageService.deleteOne(message).pipe(take(1)).subscribe( + data => { + console.log('Success', data); + }, + error => { + console.error('Failed', error); + } + ); + } + } + updateChannel(name:string, desc:string) { this.channel.name = name; this.channel.description = desc;