Skip to content

Commit 4732587

Browse files
committed
👊 building layout of post details and comments
1 parent f66ebeb commit 4732587

29 files changed

Lines changed: 426 additions & 146 deletions

angular-client/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
alt="avatar"
1212
/>
1313
<div class="meta">
14-
<h4 class="txt-1">{{ authUser.username }}</h4>
14+
<h4 class="txt-1">{{ authUser.username | truncate:5 }}</h4>
1515
<p>{{ authUser.name }}</p>
1616
</div>
1717
</div>

angular-client/src/app/app.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { TokenInterceptor, HttpErrorInterceptor } from './interceptors';
1111
import { AppErrorHandler } from './services';
1212
import { AppRoutingModule } from './app-routing.module';
1313
import { AppComponent } from './app.component';
14+
import { TruncatePipe } from './utils';
1415

1516
const CUSTOM_PROVIDERS = [
1617
{ provide: HTTP_INTERCEPTORS, useClass: HttpErrorInterceptor, multi: true },
@@ -20,7 +21,8 @@ const CUSTOM_PROVIDERS = [
2021

2122
@NgModule({
2223
declarations: [
23-
AppComponent
24+
AppComponent,
25+
TruncatePipe,
2426
],
2527
imports: [
2628
BrowserModule,
@@ -32,7 +34,7 @@ const CUSTOM_PROVIDERS = [
3234
MatIconModule,
3335
MatSnackBarModule,
3436
],
35-
providers: [...CUSTOM_PROVIDERS],
37+
providers: [...CUSTOM_PROVIDERS, TruncatePipe],
3638
bootstrap: [AppComponent]
3739
})
3840
export class AppModule { }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './page-header/page-header.module';
2+
export * from './page-header/page-header.component';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div [class]="'page__header ' + style">
2+
<div class="header--text">{{ title }}</div>
3+
<button *ngIf="icon" (click)="emitIconClick()" mat-icon-button class="header--icon-right">
4+
<mat-icon>{{ icon }}</mat-icon>
5+
</button>
6+
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.page__header {
2+
display: flex;
3+
justify-content: space-between;
4+
align-items: center;
5+
background-color: #fff;
6+
padding: 1rem;
7+
}
8+
.header--text,
9+
.header--icon-right {
10+
font-size: 2rem;
11+
font-weight: bold;
12+
}
13+
.sticky {
14+
position: sticky;
15+
top: 0;
16+
z-index: 3;
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { PageHeaderComponent } from './page-header.component';
4+
5+
describe('PageHeaderComponent', () => {
6+
let component: PageHeaderComponent;
7+
let fixture: ComponentFixture<PageHeaderComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ PageHeaderComponent ]
12+
})
13+
.compileComponents();
14+
});
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(PageHeaderComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component, EventEmitter, Input, Output } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-page-header',
5+
templateUrl: './page-header.component.html',
6+
styleUrls: ['./page-header.component.scss']
7+
})
8+
export class PageHeaderComponent {
9+
10+
@Input() style: string;
11+
@Input() title: string;
12+
@Input() icon: string;
13+
@Output() onIconClicked = new EventEmitter<any>();
14+
15+
public emitIconClick() {
16+
this.onIconClicked.emit();
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { MatButtonModule } from '@angular/material/button';
4+
import { MatIconModule } from '@angular/material/icon';
5+
6+
import { PageHeaderComponent } from './page-header.component';
7+
8+
@NgModule({
9+
declarations: [PageHeaderComponent],
10+
imports: [
11+
CommonModule,
12+
MatIconModule,
13+
MatButtonModule,
14+
],
15+
exports: [PageHeaderComponent],
16+
})
17+
export class PageHeaderModule { }

angular-client/src/app/home/home.component.html

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<!-- home header -->
2-
<div class="home__header">
3-
<div class="logo--text">instAngular</div>
4-
<button mat-icon-button class="logo--message">
5-
<mat-icon>message</mat-icon>
6-
</button>
7-
</div>
1+
<!-- page header -->
2+
<app-page-header
3+
[title]="'instAngular'"
4+
[style]="'sticky'"
5+
[icon]="'message'"
6+
(onIconClicked)="showMessages()"
7+
></app-page-header>
88

99
<!-- home story list -->
1010
<ul class="stories--list">
@@ -21,7 +21,20 @@
2121
<!-- home post list -->
2222
<div class="posts--list">
2323
<ng-container *ngFor="let post of posts$ | async">
24-
<app-post-item [post]="post"></app-post-item>
24+
<app-post-item
25+
[post]="post"
26+
(onUserProfileClicked)="viewUserProfile($event)"
27+
>
28+
<app-post-item-footer
29+
[post]="post"
30+
[comments]="post.comments"
31+
[authUser]="authUser"
32+
[viewCommentsText]="'View all ' + post.commentsCount + ' comments'"
33+
(onViewCommentsClicked)="viewPostComments($event)"
34+
(onUserProfileClicked)="viewUserProfile($event)"
35+
(onAddCommentClicked)="addComment($event)"
36+
></app-post-item-footer>
37+
</app-post-item>
2538
</ng-container>
2639
</div>
2740

angular-client/src/app/home/home.component.scss

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
1-
// home header
2-
.home__header {
3-
display: flex;
4-
justify-content: space-between;
5-
align-items: center;
6-
position: sticky;
7-
top: 0;
8-
left: 0;
9-
right: 0;
10-
z-index: 2;
11-
background-color: #fff;
12-
padding: 1rem;
13-
}
14-
.logo--text,
15-
.logo--message {
16-
font-size: 2rem;
17-
font-weight: bold;
18-
}
19-
.logo--text {
20-
margin-left: 1.5rem;
21-
cursor: pointer;
22-
}
23-
241
ul.stories--list {
25-
// padding: 0;
2+
padding: 0;
263
margin: 1rem;
27-
// width: calc(2 / 3 * 70vw - 4rem);
284
list-style: none;
295
display: flex;
306
flex-direction: row;

0 commit comments

Comments
 (0)