diff --git a/README.md b/README.md
index 54b99ae..6889c25 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# AngularShopTutorial
+# AngularTutorial
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.3.2.
@@ -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).
+
+
+
+# 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!
diff --git a/package-lock.json b/package-lock.json
index f11761b..4da4cf8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1159,6 +1159,7 @@
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz",
"integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==",
"dev": true,
+ "optional": true,
"requires": {
"delegates": "^1.0.0",
"readable-stream": "^2.0.6"
@@ -2375,7 +2376,8 @@
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=",
- "dev": true
+ "dev": true,
+ "optional": true
},
"constants-browserify": {
"version": "1.0.0",
@@ -2771,7 +2773,8 @@
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=",
- "dev": true
+ "dev": true,
+ "optional": true
},
"depd": {
"version": "1.1.2",
@@ -3805,7 +3808,8 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"aproba": {
"version": "1.2.0",
@@ -4220,7 +4224,8 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"safer-buffer": {
"version": "2.1.2",
@@ -4276,6 +4281,7 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@@ -4319,12 +4325,14 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
}
}
},
@@ -4333,6 +4341,7 @@
"resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz",
"integrity": "sha1-XB+x8RdHcRTwYyoOtLcbPLD9MXE=",
"dev": true,
+ "optional": true,
"requires": {
"graceful-fs": "^4.1.2",
"inherits": "~2.0.0",
@@ -4345,6 +4354,7 @@
"resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz",
"integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=",
"dev": true,
+ "optional": true,
"requires": {
"aproba": "^1.0.3",
"console-control-strings": "^1.0.0",
@@ -4382,7 +4392,8 @@
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz",
"integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=",
- "dev": true
+ "dev": true,
+ "optional": true
},
"get-stream": {
"version": "3.0.0",
@@ -4598,7 +4609,8 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=",
- "dev": true
+ "dev": true,
+ "optional": true
},
"has-value": {
"version": "1.0.0",
@@ -5345,7 +5357,8 @@
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz",
"integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=",
- "dev": true
+ "dev": true,
+ "optional": true
},
"is-windows": {
"version": "1.0.2",
@@ -5944,6 +5957,7 @@
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
"dev": true,
+ "optional": true,
"requires": {
"graceful-fs": "^4.1.2",
"parse-json": "^2.2.0",
@@ -5956,7 +5970,8 @@
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
- "dev": true
+ "dev": true,
+ "optional": true
}
}
},
@@ -6231,7 +6246,8 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz",
"integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=",
- "dev": true
+ "dev": true,
+ "optional": true
},
"map-visit": {
"version": "1.0.0",
@@ -6858,6 +6874,7 @@
"resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz",
"integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==",
"dev": true,
+ "optional": true,
"requires": {
"are-we-there-yet": "~1.1.2",
"console-control-strings": "~1.1.0",
@@ -7927,6 +7944,7 @@
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz",
"integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=",
"dev": true,
+ "optional": true,
"requires": {
"load-json-file": "^1.0.0",
"normalize-package-data": "^2.3.2",
@@ -7938,6 +7956,7 @@
"resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz",
"integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=",
"dev": true,
+ "optional": true,
"requires": {
"graceful-fs": "^4.1.2",
"pify": "^2.0.0",
@@ -7948,7 +7967,8 @@
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
- "dev": true
+ "dev": true,
+ "optional": true
}
}
},
@@ -7957,6 +7977,7 @@
"resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz",
"integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=",
"dev": true,
+ "optional": true,
"requires": {
"find-up": "^1.0.0",
"read-pkg": "^1.0.0"
@@ -7967,6 +7988,7 @@
"resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz",
"integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=",
"dev": true,
+ "optional": true,
"requires": {
"path-exists": "^2.0.0",
"pinkie-promise": "^2.0.0"
@@ -7977,6 +7999,7 @@
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz",
"integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=",
"dev": true,
+ "optional": true,
"requires": {
"pinkie-promise": "^2.0.0"
}
@@ -9259,6 +9282,7 @@
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz",
"integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=",
"dev": true,
+ "optional": true,
"requires": {
"is-utf8": "^0.2.0"
}
@@ -10581,6 +10605,7 @@
"resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz",
"integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==",
"dev": true,
+ "optional": true,
"requires": {
"string-width": "^1.0.2 || 2"
}
diff --git a/src/app/app.component.html b/src/app/app.component.html
index de5bcc8..f1053a7 100644
--- a/src/app/app.component.html
+++ b/src/app/app.component.html
@@ -1,8 +1,24 @@
+
+
+Here are some links to help you start:
+
+
+
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 2e7eb1a..b6319d0 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -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,
diff --git a/src/app/timeline/timeline.component.html b/src/app/timeline/timeline.component.html
index 57f57b3..79f0533 100644
--- a/src/app/timeline/timeline.component.html
+++ b/src/app/timeline/timeline.component.html
@@ -7,8 +7,12 @@
{{ tweet.text }}
-
- {{ tweet.favoriteCount }}
+
+ {{ tweet.favoriteCount }}
diff --git a/src/app/timeline/timeline.component.less b/src/app/timeline/timeline.component.less
index c2527ec..b8ecc35 100644
--- a/src/app/timeline/timeline.component.less
+++ b/src/app/timeline/timeline.component.less
@@ -61,3 +61,7 @@
cursor: pointer;
}
}
+
+.favorite-count {
+ margin-left: 4px;
+}
diff --git a/src/app/timeline/timeline.component.ts b/src/app/timeline/timeline.component.ts
index 811ec63..a83857c 100644
--- a/src/app/timeline/timeline.component.ts
+++ b/src/app/timeline/timeline.component.ts
@@ -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;
+ }
+ }
}
diff --git a/src/app/tweet.ts b/src/app/tweet.ts
index 0c89b69..582fa53 100644
--- a/src/app/tweet.ts
+++ b/src/app/tweet.ts
@@ -3,5 +3,6 @@ export interface Tweet {
id: number,
text: string,
user: string,
- favoriteCount?: number
+ favoriteCount?: number,
+ isLiked?: boolean
}