-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show confetti if everyone answers the same
- Loading branch information
Showing
12 changed files
with
148 additions
and
12 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
1 change: 1 addition & 0 deletions
1
pokeR/ClientApp/src/app/shared-components/confetti/confetti.component.html
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<canvas class="d-none" #canvas></canvas> |
7 changes: 7 additions & 0 deletions
7
pokeR/ClientApp/src/app/shared-components/confetti/confetti.component.scss
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.confettiHolder { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
} |
25 changes: 25 additions & 0 deletions
25
pokeR/ClientApp/src/app/shared-components/confetti/confetti.component.spec.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ConfettiComponent } from './confetti.component'; | ||
|
||
describe('ConfettiComponent', () => { | ||
let component: ConfettiComponent; | ||
let fixture: ComponentFixture<ConfettiComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ConfettiComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ConfettiComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
pokeR/ClientApp/src/app/shared-components/confetti/confetti.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core'; | ||
import { ConfettiService } from './confetti.service'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
declare const confetti; | ||
|
||
@Component({ | ||
selector: 'app-confetti', | ||
templateUrl: './confetti.component.html', | ||
styleUrls: ['./confetti.component.scss'] | ||
}) | ||
export class ConfettiComponent implements AfterViewInit { | ||
@ViewChild('canvas') canvas: ElementRef; | ||
private confettiLauncher: any; | ||
|
||
constructor(private service: ConfettiService) { } | ||
|
||
ngAfterViewInit(): void { | ||
this.setupConfetti(); | ||
this.watchRequests().subscribe(); | ||
} | ||
|
||
setupConfetti = (): void => { | ||
this.confettiLauncher = confetti.create(this.canvas.nativeElement, { resize: true }); | ||
this.confettiLauncher({ | ||
particleCount: 100, | ||
spread: 160 | ||
}); | ||
} | ||
|
||
watchRequests = (): Observable<void> => this.service.confettiPlz.pipe(map(this.launch)) | ||
|
||
launch = (duration: number): void => { | ||
var end = Date.now() + (duration); | ||
|
||
var interval = setInterval(() => { | ||
if (Date.now() > end) { | ||
return clearInterval(interval); | ||
} | ||
|
||
confetti({ | ||
startVelocity: 30, | ||
spread: 360, | ||
ticks: 60, | ||
origin: { | ||
x: Math.random(), | ||
// since they fall down, start a bit higher than random | ||
y: Math.random() - 0.2 | ||
} | ||
}); | ||
}, 200); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
pokeR/ClientApp/src/app/shared-components/confetti/confetti.service.spec.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ConfettiService } from './confetti.service'; | ||
|
||
describe('ConfettiService', () => { | ||
beforeEach(() => TestBed.configureTestingModule({})); | ||
|
||
it('should be created', () => { | ||
const service: ConfettiService = TestBed.get(ConfettiService); | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
pokeR/ClientApp/src/app/shared-components/confetti/confetti.service.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Injectable, EventEmitter } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ConfettiService { | ||
|
||
constructor() { } | ||
|
||
public confettiPlz: EventEmitter<number> = new EventEmitter<number>(); | ||
|
||
public pop = (): void => this.confettiPlz.emit(5000); | ||
} |
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