Skip to content

Commit

Permalink
Add functionality to follow user on user's profile
Browse files Browse the repository at this point in the history
  • Loading branch information
panispani committed Jun 15, 2017
1 parent e9a3e90 commit ea29de6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion aurelia-app/src/components/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2 class="card-title">${owner.name} ${owner.surname} | ${name}</h2>
${j.name}
</div>
CHECK WHO I'M FOLLOWING
<div repeat.for="f of following" class="row">
<div repeat.for="f of user.following" class="row">
${f.name}
</div>
</div>
Expand Down
18 changes: 12 additions & 6 deletions aurelia-app/src/components/profile.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import { RestApi } from 'services/api'
import {AuthService} from 'aurelia-authentication';
import {Login} from "./login/login";
import {Config} from "aurelia-api";


export class Profile {

static inject = [RestApi, AuthService, Login]
static inject = [RestApi, AuthService, Login, Config]

constructor(restApi, authService, login) {
constructor(restApi, authService, login, config) {
this.restApi = restApi
this.authService = authService
this.login = login
this.apiEndpoint = config.getEndpoint('api')
}

activate(params, routeConfig) {
this.restApi.getJourneysOfUser(params.id).then(journeys => this.journeys = journeys)

return this.restApi.getUser(params.id).then(user => {
Object.assign(this, ...user);
this.user = user;
})
}

follow() {
if (!this.authService.authenticated) {
console.log('you are not auth')
this.login.authenticate('facebook')
} else {
console.log('you are auth')
if (!this.authService.authenticated) {
return
}
}
return this.authService.getMe().then(
profile => this.apiEndpoint.post(`/users/${profile.id}/followers`, { "id": this.user.id })
)
}
}

0 comments on commit ea29de6

Please sign in to comment.