Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit 173db2b

Browse files
committed
feat(fire): implement guestbook in firebase
1 parent 32d816e commit 173db2b

File tree

14 files changed

+205
-58
lines changed

14 files changed

+205
-58
lines changed

apps/docs/src/app/docs/components/introduction/introduction.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { IntroductionComponent } from './introduction.component';
44

5-
describe('IntroductionComponent', () => {
5+
describe('GuestbookComponent', () => {
66
let component: IntroductionComponent;
77
let fixture: ComponentFixture<IntroductionComponent>;
88

apps/docs/src/app/docs/containers/docs-sidebar/docs-sidebar.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class DocsSidebarComponent implements OnInit {
2020

2121
public items = [
2222
{
23-
url: 'introduction',
23+
url: 'guestbook',
2424
title: 'Introduction',
2525
icon: 'fe fe-flag',
2626
},

apps/docs/src/app/docs/docs.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { DocsSidebarComponent } from './containers/docs-sidebar/docs-sidebar.com
1515

1616
const routes: Routes = [ {
1717
path: '', component: DocsIndexComponent, children: [
18-
{ path: '', redirectTo: 'introduction', pathMatch: 'full' },
19-
{ path: 'introduction', component: IntroductionComponent },
18+
{ path: '', redirectTo: 'guestbook', pathMatch: 'full' },
19+
{ path: 'guestbook', component: IntroductionComponent },
2020
{ path: 'alerts', component: AlertsComponent },
2121
{ path: 'badges', component: BadgesComponent },
2222
{ path: 'buttons', component: ButtonsComponent },

apps/fire/src/app/app.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
const headerMenu = [
33
{
4-
name: 'Fire',
5-
icon: 'fa fa-fire',
6-
url: '/fire',
4+
name: 'Guestbook',
5+
icon: 'fe fe-book',
6+
url: '/fire/guestbook',
77
},
88
]
99

apps/fire/src/app/app.module.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ import { NgModule } from '@angular/core'
33
import { BrowserModule } from '@angular/platform-browser'
44
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
55
import { CoreModule, SharedModule } from '@tabler/angular-core'
6+
import { environment } from '../environments/environment'
67

78
import { AppRoutingModule } from './app-routing.module'
8-
import { AppComponent } from './app.component';
9+
import { AppComponent } from './app.component'
10+
import { AngularFireModule } from 'angularfire2'
11+
import { AngularFirestoreModule } from 'angularfire2/firestore'
912

1013
@NgModule({
1114
imports: [
1215
BrowserModule,
1316
BrowserAnimationsModule,
1417
CoreModule,
1518
SharedModule,
16-
AppRoutingModule
19+
AppRoutingModule,
20+
AngularFireModule.initializeApp(environment.firebase),
21+
AngularFirestoreModule
1722
],
1823
declarations: [ AppComponent ],
1924
bootstrap: [ AppComponent ]

apps/fire/src/app/fire/components/introduction/introduction.component.spec.ts renamed to apps/fire/src/app/fire/components/guestbook/guestbook.component.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

3-
import { IntroductionComponent } from './introduction.component';
3+
import { GuestbookComponent } from './guestbook.component';
44

5-
describe('IntroductionComponent', () => {
6-
let component: IntroductionComponent;
7-
let fixture: ComponentFixture<IntroductionComponent>;
5+
describe('GuestbookComponent', () => {
6+
let component: GuestbookComponent;
7+
let fixture: ComponentFixture<GuestbookComponent>;
88

99
beforeEach(async(() => {
1010
TestBed.configureTestingModule({
11-
declarations: [ IntroductionComponent ]
11+
declarations: [ GuestbookComponent ]
1212
})
1313
.compileComponents();
1414
}));
1515

1616
beforeEach(() => {
17-
fixture = TestBed.createComponent(IntroductionComponent);
17+
fixture = TestBed.createComponent(GuestbookComponent);
1818
component = fixture.componentInstance;
1919
fixture.detectChanges();
2020
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { FireService } from '../../services/fire.service';
3+
4+
@Component({
5+
selector: 'app-introduction',
6+
template: `
7+
<div class="row">
8+
<div class="col-md-6 offset-md-3">
9+
<ui-page-title
10+
title="Firebase Guestbook"
11+
subTitle="Rock a guestbook like it's 1999! 🚀 "></ui-page-title>
12+
13+
14+
<div class="card">
15+
<div class="card-body">
16+
17+
<div class="my-3 py-3">
18+
<div class="input-group input-xl">
19+
<input type="text"
20+
class="form-control"
21+
placeholder="Message"
22+
[(ngModel)]="message"
23+
(keydown.enter)="sendMessage()">
24+
<div class="input-group-append">
25+
<button type="button"
26+
class="btn btn-secondary"
27+
(click)="sendMessage()">
28+
<i class="fe fe-send"></i>
29+
</button>
30+
</div>
31+
</div>
32+
</div>
33+
34+
35+
<div class="list-group list-group- my-5">
36+
37+
<div *ngIf="(fire.collection$ | async) as collection">
38+
39+
<div *ngIf="!collection.length">
40+
<div class="alert alert-info">No messages found...</div>
41+
</div>
42+
43+
<ng-container >
44+
<div class="list-group-item list-group-item-action mb-3"
45+
*ngFor="let item of collection">
46+
<div>
47+
{{item.message}}
48+
<div class="float-right">
49+
<span class="text-muted mr-4">
50+
{{item.created | date: 'short' }}
51+
</span>
52+
<button class="btn btn-sm text-danger"
53+
(click)="deleteMessage(item.id)">
54+
<i class="fa fa-trash"></i>
55+
</button>
56+
</div>
57+
</div>
58+
</div>
59+
</ng-container>
60+
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
66+
67+
68+
</div>
69+
</div>
70+
71+
`,
72+
styles: []
73+
})
74+
export class GuestbookComponent implements OnInit {
75+
public message: string
76+
77+
constructor(public fire: FireService) {}
78+
79+
ngOnInit() {
80+
this.reset()
81+
}
82+
83+
addMessage(message: string) {
84+
this.fire.upsert({ message })
85+
.subscribe(res => {
86+
console.log('Item added', res)
87+
})
88+
}
89+
90+
sendMessage() {
91+
this.addMessage(this.message)
92+
this.reset()
93+
}
94+
95+
deleteMessage(id) {
96+
this.fire.delete(id)
97+
.subscribe(res => {
98+
console.log('Item deleted', res)
99+
})
100+
}
101+
102+
reset() {
103+
this.message = ''
104+
}
105+
}

apps/fire/src/app/fire/components/introduction/introduction.component.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

apps/fire/src/app/fire/containers/fire-index/fire-index.component.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,9 @@ import { Component } from '@angular/core'
44
selector: 'app-fire-index',
55
template: `
66
<ui-page>
7-
<ui-page-title
8-
title="Fire"
9-
icon="fa fa-fire"></ui-page-title>
10-
<div class="row">
11-
<div class="col-lg-3 order-lg-0 mb-4">
12-
<app-fire-sidebar></app-fire-sidebar>
13-
</div>
14-
<div class="col-lg-9">
15-
<div class="card">
16-
<div class="card-body">
17-
<router-outlet></router-outlet>
18-
</div>
19-
</div>
20-
</div>
21-
</div>
7+
<router-outlet></router-outlet>
228
</ui-page>
239
`,
24-
styles: []
2510
})
2611
export class FireIndexComponent {
2712

apps/fire/src/app/fire/containers/fire-sidebar/fire-sidebar.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export class FireSidebarComponent implements OnInit {
2020

2121
public items = [
2222
{
23-
url: 'introduction',
24-
title: 'Introduction',
25-
icon: 'fe fe-flag',
23+
url: 'guestbook',
24+
title: 'Guestbook',
25+
icon: 'fe fe-book',
2626
},
2727
]
2828

0 commit comments

Comments
 (0)