Skip to content

Ymarivint dev #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AngularShopTutorial
# AngularTutorial

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.3.2.

Expand All @@ -25,3 +25,19 @@ Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protrac
## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

<hr/>

# Exercice

## Setup:

- Fork the project, and clone it
- create your own dev branch `git checkout -b dev`
- launch `npm install` to download dependencies

## Sync with forked repository:

- use command `git fetch upstream` to retrieve master branch from forked repository. It will create a local upstream/master branch.
- go to your local master branch: `git checkout master`
- merge the upstream master to your local master: ` git merge upstream/master`. You're up to date!
49 changes: 37 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
<!--The content below is only a placeholder and can be replaced.-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">

<div style="text-align:center">
<img width="100" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>

<h2>Here are some links to help you start: </h2>

<ul>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Documentation</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
</li>
</ul>

<app-timeline></app-timeline>

<router-outlet></router-outlet>
6 changes: 4 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { TimeAgoPipe } from 'time-ago-pipe';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { TimelineComponent } from './timeline/timeline.component';
import { TimeAgoPipe } from 'time-ago-pipe';



@NgModule({
declarations: [
AppComponent,
TimelineComponent,
TimeAgoPipe,
TimeAgoPipe
],
imports: [
BrowserModule,
Expand Down
8 changes: 6 additions & 2 deletions src/app/timeline/timeline.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
{{ tweet.text }}
</div>
<div class="favorite">
<i class="far fa-heart"></i>
<span *ngIf="tweet.favoriteCount">{{ tweet.favoriteCount }}</span>
<i class="button fa-heart" [ngClass]="{
'fas': tweet.isLiked,
'far': !tweet.isLiked
}"
(click)="likeTweet(tweet.id)"></i>
<span *ngIf="tweet.favoriteCount != null">{{ tweet.favoriteCount }}</span>
</div>
</div>

Expand Down
4 changes: 4 additions & 0 deletions src/app/timeline/timeline.component.less
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@
cursor: pointer;
}
}

.favorite-count {
margin-left: 4px;
}
11 changes: 11 additions & 0 deletions src/app/timeline/timeline.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ export class TimelineComponent implements OnInit {
this.tweets.push(tweet);
}

likeTweet(id) {
const tweetIndex = this.tweets.findIndex(tweet => tweet.id === id);
const tweet = this.tweets[tweetIndex];
if(!tweet.isLiked) {
tweet.favoriteCount ? tweet.favoriteCount++ : tweet.favoriteCount = 1;
tweet.isLiked = true;
} else {
tweet.favoriteCount--;
tweet.isLiked = false;
}
}
}
3 changes: 2 additions & 1 deletion src/app/tweet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export interface Tweet {
id: number,
text: string,
user: string,
favoriteCount?: number
favoriteCount?: number,
isLiked?: boolean
}