-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(collaboration): share notes with friends via email (#32)
- Loading branch information
Showing
10 changed files
with
191 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,5 @@ Thumbs.db | |
|
||
# firebase | ||
firebase-adminsdk-credentials.json | ||
functions/lib | ||
functions/lib | ||
.firebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 80 additions & 4 deletions
84
src/app/notes/components/note-collaborators/note-collaborators.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,96 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { ActivatedRoute, Router, ActivatedRouteSnapshot } from '@angular/router'; | ||
import { AngularFirestore, AngularFirestoreDocument } from 'angularfire2/firestore'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { FormControl } from '@angular/forms'; | ||
|
||
import { Note } from '../../models/note.model'; | ||
import { Collaborator } from '../../models/collaborator.model'; | ||
import { AuthService } from '../../../core/auth.service'; | ||
|
||
@Component({ | ||
selector: 'app-note-collaborators', | ||
templateUrl: './note-collaborators.component.html' | ||
}) | ||
export class NoteCollaboratorsComponent implements OnInit { | ||
noteId: any; | ||
currentUser: any; | ||
emailFormControl = new FormControl(''); | ||
note: Note; | ||
note$: Observable<Note>; | ||
private noteId = ''; | ||
private noteDoc: AngularFirestoreDocument<Note>; | ||
|
||
constructor( | ||
private route: ActivatedRoute | ||
private auth: AuthService, | ||
private afs: AngularFirestore, | ||
private route: ActivatedRoute, | ||
private router: Router | ||
) { | ||
route.params.subscribe((params: Object) => this.noteId = params['id']); | ||
} | ||
|
||
ngOnInit() { | ||
async ngOnInit() { | ||
this.noteDoc = this.afs.doc<Note>(`notes/${this.noteId}`); | ||
this.note$ = this.noteDoc.snapshotChanges().map(item => { | ||
const id = item.payload.id; | ||
const data = item.payload.data(); | ||
return <Note>{ id, ...data }; | ||
}); | ||
this.note$.subscribe(noteItem => { | ||
this.note = noteItem; | ||
}); | ||
|
||
this.auth.authState$.subscribe(user => { | ||
this.currentUser = user; | ||
}); | ||
} | ||
|
||
async addCollaborator(e) { | ||
const email = e.target.value; | ||
if (email.trim().length) { | ||
const photoURL = `https://avatars.io/gravatar/${email}`; | ||
const collaborator: Collaborator = { email, photoURL}; | ||
const collabEmailEscaped = email.replace(/\W/g, ''); | ||
const collaborators = {...this.note.collaborators, ...{[collabEmailEscaped]: true}}; | ||
const sharedWith = this.note.sharedWith.concat(collaborator); | ||
|
||
await this.noteDoc.collection('collaborators').doc(`${collabEmailEscaped}`).set({ | ||
email, | ||
photoURL, | ||
invitedBy: this.currentUser.uid | ||
}); | ||
|
||
await this.noteDoc.update({ | ||
collaborators, | ||
sharedWith | ||
}); | ||
|
||
this.emailFormControl.reset(); | ||
} | ||
} | ||
|
||
async deleteCollaborator(e, collab) { | ||
const sharedWith = [...this.note.sharedWith.filter(item => item.email !== collab.email)]; | ||
|
||
// https://codeburst.io/use-es2015-object-rest-operator-to-omit-properties-38a3ecffe90 | ||
const collabEmailEscaped = collab.email.replace(/\W/g, ''); | ||
delete this.note.collaborators[collabEmailEscaped]; | ||
const collaborators = {...this.note.collaborators}; | ||
|
||
await this.noteDoc.collection('collaborators').doc(`${collabEmailEscaped}`).delete(); | ||
await this.noteDoc.update({ | ||
collaborators, | ||
sharedWith | ||
}); | ||
} | ||
|
||
enableInvitationForm() { | ||
this.noteDoc.update({ | ||
isInvitaionFormEnabled: true | ||
}); | ||
} | ||
|
||
navigateBack() { | ||
this.router.navigate([`/note/${this.noteId}`]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters