Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 55fe57d

Browse files
committed
Add initial thread component
1 parent e59b2d2 commit 55fe57d

File tree

15 files changed

+116
-23
lines changed

15 files changed

+116
-23
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { Router, ActivatedRoute } from '@angular/router';
3+
import { Observable } from 'rxjs';
4+
import { App } from 'models/entities/app.model';
5+
import { Thread } from 'models/messaging/thread.model';
6+
import { AppService } from './../../app.service';
7+
import config from '../../app.constants';
8+
import { switchMap } from 'rxjs/operators';
9+
import { MessagingService } from 'components/messaging/messaging.service';
10+
11+
@Component({
12+
selector: 'app-thread',
13+
template: require('./app-thread.html'),
14+
styles: [require('./app-thread.scss')],
15+
})
16+
export class AppThreadComponent implements OnInit {
17+
private thread$: Observable<Thread>;
18+
19+
static parameters = [Router, ActivatedRoute, MessagingService];
20+
constructor(
21+
private router: Router,
22+
private route: ActivatedRoute,
23+
private messagingService: MessagingService
24+
) {
25+
this.thread$ = this.route.params.pipe(switchMap(res => this.messagingService.getThread(res.id)));
26+
}
27+
28+
ngOnInit() {
29+
// this.app$ = this.appService.getApp();
30+
}
31+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="app-primary-header">
2+
<mat-icon class="app-nav-back-icon" routerLink="/discussion">keyboard_arrow_left</mat-icon>
3+
<h1 *ngIf="thread$ | async as thread">{{ thread.title }}</h1>
4+
</div>
5+
6+
<thread [thread$]="thread$"></thread>

client/app/discussion/app-thread/app-thread.scss

Whitespace-only changes.

client/app/discussion/discussion-new/discussion-new.component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { Observable } from 'rxjs';
4-
// import { Router, ActivatedRoute } from '@angular/router';
5-
// import { AppService } from '../app.service';
6-
// import { App } from 'models/entities/app.model';
7-
// import { PageTitleService } from 'components/page-title/page-title.service';
84
import { App } from 'models/entities/app.model';
95
import { Thread } from 'models/messaging/thread.model';
106
import { AppService } from './../../app.service';

client/app/discussion/discussion.component.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,4 @@ export class DiscussionComponent implements OnInit {
3535
err => console.error(err)
3636
);
3737
}
38-
39-
newThread(thread: Thread): void {
40-
// if (thread) {
41-
// this.router.navigate(['/discussion', thread._id]);
42-
// }
43-
}
4438
}

client/app/discussion/discussion.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<div class="app-primary-header app-thread-list-header">
22
<h1 class="app-primary-header-title">General Discussion</h1>
3-
<a mat-raised-button color="warn" class="app-thread-list-new-thread-btn" routerLink="/discussion/new" aria-label="Create a new thread">New Thread</a>
3+
<a
4+
mat-raised-button
5+
color="warn"
6+
class="app-thread-list-new-thread-btn"
7+
routerLink="/discussion/new"
8+
aria-label="Create a new thread"
9+
>New Thread</a
10+
>
411
</div>
512

613
<thread-list *ngIf="app" [entityId]="app._id" [entityType]="appEntityType"></thread-list>
7-
8-
<!-- <entity-discussion *ngIf="app" [entity]="app" [entityType]="entityType"></entity-discussion> -->

client/app/discussion/discussion.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AppService } from '../app.service';
1313

1414
import { DiscussionComponent } from './discussion.component';
1515
import { DiscussionNewComponent } from './discussion-new/discussion-new.component';
16+
import { AppThreadComponent } from './app-thread/app-thread.component';
1617

1718
export const ROUTES: Routes = [
1819
{
@@ -25,6 +26,11 @@ export const ROUTES: Routes = [
2526
component: DiscussionNewComponent,
2627
canActivate: [AuthGuard],
2728
},
29+
{
30+
path: 'discussion/:id',
31+
component: AppThreadComponent,
32+
canActivate: [AuthGuard],
33+
},
2834
];
2935

3036
@NgModule({
@@ -37,7 +43,7 @@ export const ROUTES: Routes = [
3743
MessagingModule,
3844
RouterModule.forChild(ROUTES),
3945
],
40-
declarations: [DiscussionComponent, DiscussionNewComponent],
46+
declarations: [DiscussionComponent, DiscussionNewComponent, AppThreadComponent],
4147
providers: [AppService, SocketService],
4248
exports: [],
4349
})

client/components/messaging/messaging.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { MessagingDataService } from './messaging-data.service';
2222
import { MessageDateSeparatorComponent } from './message-date-separator/message-date-separator.component';
2323
import { AppQuillModule } from '../quill/app-quill.module';
2424
import { SocketService } from 'components/socket/socket.service';
25+
import { ThreadComponent } from './thread/thread.component';
2526

2627
@NgModule({
2728
imports: [
@@ -60,15 +61,17 @@ import { SocketService } from 'components/socket/socket.service';
6061
ThreadListComponent,
6162
ThreadDateSeparatorComponent,
6263
StarredMessageListComponent,
63-
MessageDateSeparatorComponent
64+
MessageDateSeparatorComponent,
65+
ThreadComponent
6466
],
6567
exports: [
6668
ThreadNewComponent,
6769
ThreadEditComponent,
6870
MessageComponent,
6971
MessageNewComponent,
7072
ThreadListComponent,
71-
StarredMessageListComponent
73+
StarredMessageListComponent,
74+
ThreadComponent
7275
],
7376
entryComponents: [
7477
// MessageThreadComponent

client/components/messaging/messaging.service.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ export class MessagingService {
1616
static parameters = [HttpClient, SecondarySidenavService];
1717
constructor(private httpClient: HttpClient, private secondarySidenavService: SecondarySidenavService) {}
1818

19-
/**
20-
* Threads
21-
*/
19+
// THEADS FUNCTIONS
20+
21+
/**
22+
* Returns the thread specified.
23+
* @param id
24+
*/
25+
getThread(id: string): Observable<Thread> {
26+
return this.httpClient.get<Thread>(`/api/threads/${id}`);
27+
}
2228

2329
/**
2430
* Creates a new thread.
@@ -38,9 +44,7 @@ export class MessagingService {
3844
.pipe(map(threads => orderBy(['createdAt'], ['desc'], threads)));
3945
}
4046

41-
/**
42-
* Messages
43-
*/
47+
// MESSAGES FUNCTIONS
4448

4549
/**
4650
* Creates a new message and associates it to the thread specified.
@@ -66,6 +70,8 @@ export class MessagingService {
6670

6771

6872

73+
74+
6975
getThreads(): Observable<Thread[]> {
7076
return this.httpClient.get<Thread[]>(`/api/threads`);
7177
// .pipe(

client/components/messaging/thread-new/thread-new.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export class ThreadNewComponent implements OnInit {
8989

9090
createMessage(thread: Thread): Observable<Message> {
9191
let newMessage = {
92-
thread: thread._id,
9392
body: JSON.stringify(this.form.controls.body.value),
9493
};
9594
return this.messagingService.createMessage(thread, newMessage);

0 commit comments

Comments
 (0)