-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook up the API, and add all the necessary elements
- Loading branch information
1 parent
6c604b9
commit b37f41e
Showing
19 changed files
with
169 additions
and
41 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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { Component } from '@angular/core'; | ||
import { RouterOutlet } from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'cnjg-root', | ||
standalone: true, | ||
imports: [RouterOutlet], | ||
imports: [RouterOutlet, HttpClientModule], | ||
template: '<router-outlet />', | ||
}) | ||
export class AppComponent {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { Routes } from '@angular/router'; | ||
import { HomeComponent } from './home/home.component'; | ||
import { FavouritesComponent } from './favourites/favourites.component'; | ||
|
||
export const routes: Routes = [ | ||
{ path: '', component: HomeComponent }, | ||
// Add more routes here if needed | ||
{ path: 'favourites', component: FavouritesComponent }, | ||
]; |
1 change: 1 addition & 0 deletions
1
src/app/chuck-norris-joke-generator/chuck-norris-joke-generator.constant.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 @@ | ||
export const chuckNorrisApi = 'https://api.chucknorris.io/jokes/random'; |
6 changes: 6 additions & 0 deletions
6
src/app/chuck-norris-joke-generator/chuck-norris-joke-generator.model.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,6 @@ | ||
export interface ChuckNorrisJoke { | ||
icon_url: string; | ||
id: string; | ||
url: string; | ||
value: string; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/app/chuck-norris-joke-generator/chuck-norris-joke-generator.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,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ChuckNorrisJokeGeneratorService } from './chuck-norris-joke-generator.service'; | ||
|
||
describe('ChuckNorrisJokeGeneratorService', () => { | ||
let service: ChuckNorrisJokeGeneratorService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(ChuckNorrisJokeGeneratorService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
src/app/chuck-norris-joke-generator/chuck-norris-joke-generator.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,19 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { ChuckNorrisJoke } from './chuck-norris-joke-generator.model'; | ||
import { Observable, forkJoin, map, switchMap, tap } from 'rxjs'; | ||
import { chuckNorrisApi } from './chuck-norris-joke-generator.constant'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ChuckNorrisJokeGeneratorService { | ||
constructor(private httpClient: HttpClient) {} | ||
|
||
public getJoke(): Observable<string> { | ||
return this.httpClient.get<ChuckNorrisJoke>(chuckNorrisApi).pipe( | ||
tap((joke) => console.log(joke)), | ||
map((joke) => joke.value) | ||
); | ||
} | ||
} |
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 @@ | ||
<p>favourites works!</p> |
Empty file.
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,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { FavouritesComponent } from './favourites.component'; | ||
|
||
describe('FavouritesComponent', () => { | ||
let component: FavouritesComponent; | ||
let fixture: ComponentFixture<FavouritesComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [FavouritesComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(FavouritesComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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,11 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'cnjg-favourites', | ||
standalone: true, | ||
imports: [], | ||
templateUrl: './favourites.component.html', | ||
styleUrl: './favourites.component.scss', | ||
// changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class FavouritesComponent {} |
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,6 @@ | ||
:host { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
padding: 25px; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { JokeStoreService } from './joke-store.service'; | ||
|
||
describe('JokeStoreService', () => { | ||
let service: JokeStoreService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(JokeStoreService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
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,22 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ChuckNorrisJokeGeneratorService } from '../chuck-norris-joke-generator/chuck-norris-joke-generator.service'; | ||
import { Observable, forkJoin } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class JokeStoreService { | ||
constructor( | ||
private chuckNorrisJokeGeneratorService: ChuckNorrisJokeGeneratorService | ||
) {} | ||
|
||
/** | ||
* @returns a list of 10 jokes | ||
*/ | ||
public getJokes(): Observable<string[]> { | ||
// TODO: Look into a more efficient way to do 10 concurrent requests (showing them as they return in the view): | ||
return forkJoin( | ||
Array(10).fill(this.chuckNorrisJokeGeneratorService.getJoke()) | ||
); | ||
} | ||
} |
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 @@ | ||
:host { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
|
||
ul { | ||
width: 80%; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
|
||
li { | ||
list-style: none; | ||
margin-bottom: 20px; | ||
} | ||
li:nth-child(even) { | ||
color: orange; | ||
} | ||
|
||
li:nth-child(odd) { | ||
color: lightblue; | ||
} | ||
} | ||
} |
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,47 +1,22 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { Component } from '@angular/core'; | ||
import { JokeStoreService } from '../joke-store/joke-store.service'; | ||
|
||
@Component({ | ||
selector: 'cnjg-jokes', | ||
standalone: true, | ||
imports: [CommonModule], | ||
templateUrl: './jokes.component.html', | ||
styleUrl: './jokes.component.scss', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
// changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class JokesComponent { | ||
public jokes = [ | ||
'Joke 1', | ||
'Joke 2', | ||
'Joke 3', | ||
'Joke 4', | ||
'Joke 5', | ||
'Joke 6', | ||
'Joke 7', | ||
'Joke 8', | ||
'Joke 9', | ||
'Joke 10', | ||
'Joke 11', | ||
'Joke 12', | ||
'Joke 13', | ||
'Joke 14', | ||
'Joke 15', | ||
'Joke 16', | ||
'Joke 17', | ||
'Joke 18', | ||
'Joke 19', | ||
'Joke 20', | ||
'Joke 21', | ||
'Joke 22', | ||
'Joke 23', | ||
'Joke 24', | ||
'Joke 25', | ||
'Joke 26', | ||
'Joke 27', | ||
'Joke 28', | ||
'Joke 29', | ||
'Joke 30', | ||
'Joke 31', | ||
'Joke 32', | ||
]; | ||
public jokes: string[] = []; | ||
|
||
constructor(private jokeStoreService: JokeStoreService) { | ||
// TODO: Look into using async pipe? | ||
this.jokeStoreService.getJokes().subscribe((jokes) => { | ||
this.jokes = jokes; | ||
}); | ||
} | ||
} |
Binary file not shown.
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