Created
September 17, 2019 03:06
-
-
Save shadow1349/17a9894f078dbb6fa35efdcd737ef7fe to your computer and use it in GitHub Desktop.
Notes page using algolia instant search
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
<div *ngIf="user | async as User"> | |
<button mat-raised-button color="accent" (click)="newNote = true"> | |
Create Note | |
</button> | |
<h2 *ngIf="User.NumNotes === 0">Looks like there are no notes to display</h2> | |
<h2 *ngIf="User.NumNotes > 0">You have {{ User.NumNotes }} notes</h2> | |
<app-note *ngIf="newNote" (update)="createNote($event, User.Id)"></app-note> | |
<ais-instantsearch [config]="aisConfig"> | |
<ais-search-box></ais-search-box> | |
<ais-refinement-list attribute="_tags"></ais-refinement-list> | |
<ais-hits> | |
<ng-template let-hits="hits"> | |
<app-note *ngFor="let hit of hits" [note]="hit"></app-note> | |
</ng-template> | |
</ais-hits> | |
</ais-instantsearch> | |
<app-note *ngFor="let note of notes | async" [note]="note" (update)="updateNote($event)" | |
(delete)="deleteNote($event)"></app-note> | |
</div> |
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
import { Component, OnInit } from '@angular/core'; | |
import { INote, IUser } from 'firebasenoteapptypes'; | |
import { Observable } from 'rxjs'; | |
import { NotesService, UserService } from 'src/app/services'; | |
import { environment } from 'src/environments/environment'; | |
@Component({ | |
selector: 'app-notes', | |
templateUrl: './notes.component.html', | |
styleUrls: ['./notes.component.scss'] | |
}) | |
export class NotesComponent implements OnInit { | |
user: Observable<IUser>; | |
notes: Observable<INote[]>; | |
newNote = false; | |
aisConfig = { | |
apiKey: environment.algoliaConfig.searchKey, | |
appId: environment.algoliaConfig.appId, | |
indexName: 'Notes', | |
routing: true | |
}; | |
constructor(private noteService: NotesService, private userService: UserService) { | |
this.user = this.userService.user; | |
this.notes = this.noteService.notes; | |
} | |
ngOnInit() {} | |
updateNote(note: INote) { | |
this.noteService.updateNote(note); | |
} | |
createNote(note: INote, userId: string) { | |
if (note === null) { | |
this.newNote = false; | |
} else { | |
note.Author = userId; | |
this.noteService.addNote(note); | |
this.newNote = false; | |
} | |
} | |
deleteNote(id: string) { | |
this.noteService.deleteNote(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment