Skip to content

Commit

Permalink
added img-loader and film-thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
minhyeong-joe committed Jul 31, 2020
1 parent 14f72eb commit 4345b67
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 210 deletions.
7 changes: 6 additions & 1 deletion src/app/pages/about/about.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ <h1 class="heading text-center">About Us</h1>
<div class="col-12 col-sm-9 col-lg-6 main-content" *ngFor="let about of abouts">
<p class="mb-0 title">{{about.HEADING}}</p>
<div class="vertical-bar"></div>
<img class="img-fluid" src="https://via.placeholder.com/300x400" alt="temp">
<mat-grid-list cols="1" rowHeight="2:3">
<mat-grid-tile>
<!-- <img class="img-fluid" src="https://via.placeholder.com/300x400" alt="temp"> -->
<img-loader src="https://via.placeholder.com/3000x5000" loader="assets/spinner.gif"></img-loader>
</mat-grid-tile>
</mat-grid-list>
<p class="text-muted lead description mt-2">{{about.DESCRIPTION}}</p>
</div>
</div> <!-- end of row of about us contents-->
Expand Down
3 changes: 0 additions & 3 deletions src/app/pages/about/about.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ $container-margin-bottom: $striped-height + 30px;
margin-top: 8px;
margin-bottom: 8px;
}
img {
width: 100%;
}
// adds zig-zag effect
&:nth-child(even) {
top: $striped-height;
Expand Down
22 changes: 13 additions & 9 deletions src/app/pages/films/films.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@
<i class="fa fa-meh-o" aria-hidden="true"></i> No film found.
</div>

<div class="grid-container" *ngIf="films?.length > 0">
<div *ngFor="let film of films" class="grid grid-sm" [routerLink]="['/film', film._id]" (click)="onClickFilm()">
<img class="movie-thumbnail img-fluid" src="{{film.poster_url}}" />
<div class="movie-title-container">
<p class="h4 title">{{film.title}}</p>
<p class="lead text-muted director-year">{{film.director[0]}} | {{film.release_date | date:'yyyy'}}</p>
</div>
</div>
</div>
<mat-grid-list *ngIf="films?.length > 0" [cols]="cols" gutterSize="0" (window:resize)="onResize($event)">
<mat-grid-tile *ngFor="let film of films" [colspan]="1" [rowspan]="1">
<film-thumbnail
[id]="film._id"
[src]="film.poster_url"
loader="assets/spinner.gif"
[title]="film.title"
[director]="film.director[0]"
[year]="film.release_date | date:'yyyy'"
[queryParams]="queryParams"
></film-thumbnail>
</mat-grid-tile>
</mat-grid-list>
</div>

<div class="paginator">
Expand Down
4 changes: 0 additions & 4 deletions src/app/pages/films/films.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
}
}

// to keep paginator at the bottom
.paginator {
position: absolute;
width: 100%;
bottom: $footer-height;
* {
font-size: 1.2rem;
}
Expand Down
57 changes: 20 additions & 37 deletions src/app/pages/films/films.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ export class FilmsComponent implements OnInit, OnDestroy {

public queryParams: Params;

public cols: number;

constructor(private filmService: FilmService,
private fb: FormBuilder,
private session: SessionStorageService,
private route: ActivatedRoute,
private router: Router) { }

ngOnInit(): void {
// grid size
if (window.innerWidth >= 992) {
this.cols = 4;
} else if (window.innerWidth >= 576) {
this.cols = 2;
} else {
this.cols = 1;
}
// initialize year list from current year -> 2000 (const FROM_YEAR)
const currentYear = new Date().getFullYear();
for (let y = currentYear; y >= FROM_YEAR; y--) {
Expand Down Expand Up @@ -122,43 +132,6 @@ export class FilmsComponent implements OnInit, OnDestroy {
}});
}

// resetPagination() {
// if (this.isByYear) {
// const year = this.years[this.selectedTabIndex];

// this.getCountSub = this.filmService.getCountByYear(year)
// .subscribe(res => {
// if (res.success) {
// this.pageEvent.pageSize = PAGE_SIZE;
// this.pageEvent.length = res.count;
// }
// });
// } else {
// const searchBy:string = this.searchForm.get('searchBy').value;
// const query:string = this.searchForm.get('query').value;
// switch (searchBy) {
// case "title":
// this.getCountSub = this.filmService.getCountByTitle(query)
// .subscribe(res => {
// if (res.success) {
// this.pageEvent.pageSize = PAGE_SIZE;
// this.pageEvent.length = res.count;
// }
// })
// break;
// case "director":
// this.getCountSub = this.filmService.getCountByDirector(query)
// .subscribe(res => {
// if (res.success) {
// this.pageEvent.pageSize = PAGE_SIZE;
// this.pageEvent.length = res.count;
// }
// })
// break;
// }
// }
// }

renderList() {
if (this.isByYear) {
const year = this.years[this.selectedTabIndex];
Expand Down Expand Up @@ -195,6 +168,16 @@ export class FilmsComponent implements OnInit, OnDestroy {
}
}

onResize(event) {
if (event.target.innerWidth >= 992) {
this.cols = 4;
} else if (event.target.innerWidth >= 576) {
this.cols = 2;
} else {
this.cols = 1;
}
}

ngOnDestroy():void {
this.getFilmsSub.unsubscribe();
// this.getCountSub.unsubscribe();
Expand Down
73 changes: 43 additions & 30 deletions src/app/pages/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,49 @@

<ng-container *ngIf="latestFilms?.length > 0">

<div class="grid-container">
<div class="grid grid-sm order-1" [routerLink]="['film', latestFilms[0]._id]">
<img class="movie-thumbnail img-fluid" [lazyLoad]="latestFilms[0].poster_url" defaultImage="assets/spinner.gif">
<div class="movie-title-container">
<p class="h4 title">{{latestFilms[0].title}}</p>
<p class="lead text-muted director-year">{{latestFilms[0].director[0]}} | {{latestFilms[0].release_date | date:'yyyy'}}</p>
</div>
</div>
<div class="grid grid-sm order-2" [routerLink]="['film', latestFilms[1]._id]">
<img class="movie-thumbnail img-fluid" [lazyLoad]="latestFilms[1].poster_url" defaultImage="assets/spinner.gif">
<div class="movie-title-container">
<p class="h4 title">{{latestFilms[1].title}}</p>
<p class="lead text-muted director-year">{{latestFilms[1].director[0]}} | {{latestFilms[1].release_date | date:'yyyy'}}</p>
</div>
</div>
<div class="grid grid-md order-3 order-lg-4" [routerLink]="['film', latestFilms[2]._id]">
<img class="movie-thumbnail img-fluid" [lazyLoad]="latestFilms[2].poster_url" defaultImage="assets/spinner.gif">
<div class="movie-title-container">
<p class="h4 title">{{latestFilms[2].title}}</p>
<p class="lead text-muted director-year">{{latestFilms[2].director[0]}} | {{latestFilms[2].release_date | date:'yyyy'}}</p>
</div>
</div>
<div class="grid grid-lg order-4 order-lg-3" [routerLink]="['film', latestFilms[3]._id]">
<img class="movie-thumbnail img-fluid" [lazyLoad]="latestFilms[3].poster_url" [defaultImage]="'assets/spinner.gif'">
<div class="movie-title-container">
<p class="h4 title">{{latestFilms[3].title}}</p>
<p class="lead text-muted director-year">{{latestFilms[3].director[0]}} | {{latestFilms[3].release_date | date:'yyyy'}}</p>
</div>
</div>
</div>
<mat-grid-list [cols]="cols" gutterSize="0" (window:resize)="onResize($event)">
<mat-grid-tile [colspan]="dimLg" [rowspan]="dimLg">
<film-thumbnail
[id]="latestFilms[0]._id"
[src]="latestFilms[0].poster_url"
loader="assets/spinner.gif"
[title]="latestFilms[0].title"
[director]="latestFilms[0].director[0]"
[year]="latestFilms[0].release_date | date:'yyyy'"
></film-thumbnail>
</mat-grid-tile>
<mat-grid-tile [colspan]="dimLg" [rowspan]="rowMd">
<film-thumbnail
[id]="latestFilms[1]._id"
[src]="latestFilms[1].poster_url"
loader="assets/spinner.gif"
[title]="latestFilms[1].title"
[director]="latestFilms[1].director[0]"
[year]="latestFilms[1].release_date | date:'yyyy'"
></film-thumbnail>
</mat-grid-tile>
<mat-grid-tile [colspan]="dimSm" [rowspan]="dimSm">
<film-thumbnail
[id]="latestFilms[2]._id"
[src]="latestFilms[2].poster_url"
loader="assets/spinner.gif"
[title]="latestFilms[2].title"
[director]="latestFilms[2].director[0]"
[year]="latestFilms[2].release_date | date:'yyyy'"
></film-thumbnail>
</mat-grid-tile>
<mat-grid-tile [colspan]="dimSm" [rowspan]="dimSm">
<film-thumbnail
[id]="latestFilms[3]._id"
[src]="latestFilms[3].poster_url"
loader="assets/spinner.gif"
[title]="latestFilms[3].title"
[director]="latestFilms[3].director[0]"
[year]="latestFilms[3].release_date | date:'yyyy'"
></film-thumbnail>
</mat-grid-tile>

</mat-grid-list>

</ng-container>

Expand Down
41 changes: 40 additions & 1 deletion src/app/pages/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { Subscription } from 'rxjs';
})
export class HomeComponent implements OnInit, OnDestroy {
private getFilmsSub: Subscription;
latestFilms: Film[];
public latestFilms: Film[];
public cols: number;
public dimLg: number;
public rowMd: number;
public dimSm: number;

constructor(private filmService: FilmService) { }

Expand All @@ -22,6 +26,41 @@ export class HomeComponent implements OnInit, OnDestroy {
this.latestFilms = res.data.films;
}
});
if (window.innerWidth >= 992) {
this.cols = 4;
this.dimLg = 2;
this.rowMd = 1;
this.dimSm = 1;
} else if (window.innerWidth >= 576) {
this.cols = 2;
this.dimLg = 1;
this.rowMd = 1;
this.dimSm = 1;
} else {
this.cols = 1;
this.dimLg = 1;
this.rowMd = 1;
this.dimSm = 1;
}
}

onResize(event) {
if (event.target.innerWidth >= 992) {
this.cols = 4;
this.dimLg = 2;
this.rowMd = 1;
this.dimSm = 1;
} else if (event.target.innerWidth >= 576) {
this.cols = 2;
this.dimLg = 1;
this.rowMd = 1;
this.dimSm = 1;
} else {
this.cols = 1;
this.dimLg = 1;
this.rowMd = 1;
this.dimSm = 1;
}
}

ngOnDestroy() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/single-film/single-film.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="nav-btn prev" [ngClass]="{'disabled': prevId == null}" [routerLink]="['/film', prevId]">
<i class="fa fa-chevron-left" aria-hidden="true"></i>
</div>
<div class="nav-btn menu" [routerLink]="['/films']" [queryParams]="queryParams">
<div class="nav-btn menu" [routerLink]="[backUrl]" [queryParams]="queryParams">
<i class="fa fa-bars" aria-hidden="true"></i>
</div>
<div class="nav-btn next" [ngClass]="{'disabled': nextId == null}" [routerLink]="['/film', nextId]">
Expand Down
4 changes: 4 additions & 0 deletions src/app/pages/single-film/single-film.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class SingleFilmComponent implements OnInit, OnDestroy {
public prevId: string;
public nextId: string;

public backUrl: string = '/films';
public queryParams: Params;

constructor(private filmService: FilmService,
Expand All @@ -27,6 +28,9 @@ export class SingleFilmComponent implements OnInit, OnDestroy {

ngOnInit(): void {
this.queryParams = this.session.getFilmParams();
if (this.queryParams == null) {
this.backUrl = '/';
}
// get ID from path
this.getIdSub = this.route.params.subscribe(params => {
const id = params['id'];
Expand Down
10 changes: 10 additions & 0 deletions src/app/shared/film-thumbnail/film-thumbnail.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="wrapper" [routerLink]="['/film', id]" (click)="onClick()">
<div class="image-loader">
<img [hidden]="isLoading" class="img-loaded img-fluid" [src]="src" [alt]="alt" (load)="onLoad()">
<img *ngIf="isLoading" class="img-loading" [src]="loaderSrc" alt="loading...">
</div>
<div *ngIf="!isLoading" class="movie-title-container">
<p class="h4 title">{{title}}</p>
<p class="lead text-muted director-year">{{director}} | {{year}}</p>
</div>
</div>
73 changes: 73 additions & 0 deletions src/app/shared/film-thumbnail/film-thumbnail.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
$transition-duration: 0.15s;

.image-loader {
img.img-loaded {
animation: fadeIn 0.8s;
position: absolute;
height: 100%;
width: 100%;
object-fit: cover;
transition: filter $transition-duration ease-in-out;
}
img.img-loading {
position: absolute;
height: 60px;
width: 60px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
pointer-events: none;
}
}

@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}

.movie-title-container {
z-index: 5;
position: absolute;
background-color: rgba(0,0,0,0.75);
color: white;
padding-top: 1rem;
width: 100%;
height: 100%;
text-align: center;
opacity: 0;
transition: opacity $transition-duration ease-in-out;
display: flex;
flex-direction: column;
justify-content: center;
.text-muted {
color: #999 !important;
}
p {
transform: scaleX(0);
}
p:first-child {
transition: transform 0.25s ease-in-out $transition-duration;
}
p:last-child {
transition: transform 0.25s ease-in-out 0.3s;
}
}
.wrapper {
cursor: pointer;
}
.wrapper:hover {
.movie-title-container {
opacity: 1;
p {
transform: scaleX(1);
}
}
.img-loaded {
filter: grayscale(0.5);
}
}

Loading

0 comments on commit 4345b67

Please sign in to comment.