├── .browserslistrc
├── .editorconfig
├── .gitignore
├── .vscode
├── extensions.json
├── launch.json
└── tasks.json
├── README.md
├── angular.json
├── karma.conf.js
├── package-lock.json
├── package.json
├── src
├── app
│ ├── app-routing.module.ts
│ ├── app.component.html
│ ├── app.component.scss
│ ├── app.component.spec.ts
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── components
│ │ └── pages
│ │ │ ├── characters
│ │ │ ├── character-details
│ │ │ │ ├── character-details-routing.module.ts
│ │ │ │ ├── character-details.component.html
│ │ │ │ ├── character-details.component.scss
│ │ │ │ ├── character-details.component.spec.ts
│ │ │ │ ├── character-details.component.ts
│ │ │ │ └── character-details.module.ts
│ │ │ ├── character-list
│ │ │ │ ├── character-list-routing.module.ts
│ │ │ │ ├── character-list.component.html
│ │ │ │ ├── character-list.component.scss
│ │ │ │ ├── character-list.component.spec.ts
│ │ │ │ ├── character-list.component.ts
│ │ │ │ └── character-list.module.ts
│ │ │ ├── character.component.ts
│ │ │ └── characters.module.ts
│ │ │ └── home
│ │ │ ├── home-routing.module.ts
│ │ │ ├── home.component.html
│ │ │ ├── home.component.scss
│ │ │ ├── home.component.spec.ts
│ │ │ ├── home.component.ts
│ │ │ └── home.module.ts
│ └── shared
│ │ ├── components
│ │ ├── form-search
│ │ │ └── form-search.component.ts
│ │ └── header
│ │ │ ├── header.component.html
│ │ │ ├── header.component.scss
│ │ │ ├── header.component.spec.ts
│ │ │ └── header.component.ts
│ │ ├── interfaces
│ │ └── character.interface.ts
│ │ └── services
│ │ ├── character.service.spec.ts
│ │ └── character.service.ts
├── assets
│ └── .gitkeep
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── index.html
├── main.ts
├── polyfills.ts
├── styles.scss
└── test.ts
├── tsconfig.app.json
├── tsconfig.json
└── tsconfig.spec.json
/.browserslistrc:
--------------------------------------------------------------------------------
1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 |
5 | # For the full list of supported browsers by the Angular framework, please see:
6 | # https://angular.io/guide/browser-support
7 |
8 | # You can see what browsers were selected by your queries by running:
9 | # npx browserslist
10 |
11 | last 1 Chrome version
12 | last 1 Firefox version
13 | last 2 Edge major versions
14 | last 2 Safari major versions
15 | last 2 iOS major versions
16 | Firefox ESR
17 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.ts]
12 | quote_type = single
13 |
14 | [*.md]
15 | max_line_length = off
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # Compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | /bazel-out
8 |
9 | # Node
10 | /node_modules
11 | npm-debug.log
12 | yarn-error.log
13 |
14 | # IDEs and editors
15 | .idea/
16 | .project
17 | .classpath
18 | .c9/
19 | *.launch
20 | .settings/
21 | *.sublime-workspace
22 |
23 | # Visual Studio Code
24 | .vscode/*
25 | !.vscode/settings.json
26 | !.vscode/tasks.json
27 | !.vscode/launch.json
28 | !.vscode/extensions.json
29 | .history/*
30 |
31 | # Miscellaneous
32 | /.angular/cache
33 | .sass-cache/
34 | /connect.lock
35 | /coverage
36 | /libpeerconnection.log
37 | testem.log
38 | /typings
39 |
40 | # System files
41 | .DS_Store
42 | Thumbs.db
43 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
3 | "recommendations": ["angular.ng-template"]
4 | }
5 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
3 | "version": "0.2.0",
4 | "configurations": [
5 | {
6 | "name": "ng serve",
7 | "type": "pwa-chrome",
8 | "request": "launch",
9 | "preLaunchTask": "npm: start",
10 | "url": "http://localhost:4200/"
11 | },
12 | {
13 | "name": "ng test",
14 | "type": "chrome",
15 | "request": "launch",
16 | "preLaunchTask": "npm: test",
17 | "url": "http://localhost:9876/debug.html"
18 | }
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
3 | "version": "2.0.0",
4 | "tasks": [
5 | {
6 | "type": "npm",
7 | "script": "start",
8 | "isBackground": true,
9 | "problemMatcher": {
10 | "owner": "typescript",
11 | "pattern": "$tsc",
12 | "background": {
13 | "activeOnStart": true,
14 | "beginsPattern": {
15 | "regexp": "(.*?)"
16 | },
17 | "endsPattern": {
18 | "regexp": "bundle generation complete"
19 | }
20 | }
21 | }
22 | },
23 | {
24 | "type": "npm",
25 | "script": "test",
26 | "isBackground": true,
27 | "problemMatcher": {
28 | "owner": "typescript",
29 | "pattern": "$tsc",
30 | "background": {
31 | "activeOnStart": true,
32 | "beginsPattern": {
33 | "regexp": "(.*?)"
34 | },
35 | "endsPattern": {
36 | "regexp": "bundle generation complete"
37 | }
38 | }
39 | }
40 | }
41 | ]
42 | }
43 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Rick and Morty Application
2 |
3 | Aplicação Angular que consome a API do Rick and Morty e permite procurar os personagens pelo nome.
4 |
5 | ### Link do site na Netlify: https://rick-and-morty-web-page.netlify.app/
6 |
7 | ### The Rick and Morty API: https://rickandmortyapi.com/
8 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "rickAndMortyApp": {
7 | "projectType": "application",
8 | "schematics": {
9 | "@schematics/angular:component": {
10 | "style": "scss"
11 | }
12 | },
13 | "root": "",
14 | "sourceRoot": "src",
15 | "prefix": "app",
16 | "architect": {
17 | "build": {
18 | "builder": "@angular-devkit/build-angular:browser",
19 | "options": {
20 | "outputPath": "dist/rick-and-morty-app",
21 | "index": "src/index.html",
22 | "main": "src/main.ts",
23 | "polyfills": "src/polyfills.ts",
24 | "tsConfig": "tsconfig.app.json",
25 | "inlineStyleLanguage": "scss",
26 | "assets": [
27 | "src/favicon.ico",
28 | "src/assets"
29 | ],
30 | "styles": [
31 | "node_modules/bootstrap/dist/css/bootstrap.min.css",
32 | "src/styles.scss"
33 | ],
34 | "scripts": [
35 | "node_modules/jquery/dist/jquery.min.js",
36 | "node_modules/@popperjs/core/dist/umd/popper.min.js",
37 | "node_modules/bootstrap/dist/js/bootstrap.min.js"
38 | ]
39 | },
40 | "configurations": {
41 | "production": {
42 | "budgets": [
43 | {
44 | "type": "initial",
45 | "maximumWarning": "500kb",
46 | "maximumError": "1mb"
47 | },
48 | {
49 | "type": "anyComponentStyle",
50 | "maximumWarning": "2kb",
51 | "maximumError": "4kb"
52 | }
53 | ],
54 | "fileReplacements": [
55 | {
56 | "replace": "src/environments/environment.ts",
57 | "with": "src/environments/environment.prod.ts"
58 | }
59 | ],
60 | "outputHashing": "all"
61 | },
62 | "development": {
63 | "buildOptimizer": false,
64 | "optimization": false,
65 | "vendorChunk": true,
66 | "extractLicenses": false,
67 | "sourceMap": true,
68 | "namedChunks": true
69 | }
70 | },
71 | "defaultConfiguration": "production"
72 | },
73 | "serve": {
74 | "builder": "@angular-devkit/build-angular:dev-server",
75 | "configurations": {
76 | "production": {
77 | "browserTarget": "rickAndMortyApp:build:production"
78 | },
79 | "development": {
80 | "browserTarget": "rickAndMortyApp:build:development"
81 | }
82 | },
83 | "defaultConfiguration": "development"
84 | },
85 | "extract-i18n": {
86 | "builder": "@angular-devkit/build-angular:extract-i18n",
87 | "options": {
88 | "browserTarget": "rickAndMortyApp:build"
89 | }
90 | },
91 | "test": {
92 | "builder": "@angular-devkit/build-angular:karma",
93 | "options": {
94 | "main": "src/test.ts",
95 | "polyfills": "src/polyfills.ts",
96 | "tsConfig": "tsconfig.spec.json",
97 | "karmaConfig": "karma.conf.js",
98 | "inlineStyleLanguage": "scss",
99 | "assets": [
100 | "src/favicon.ico",
101 | "src/assets"
102 | ],
103 | "styles": [
104 | "src/styles.scss"
105 | ],
106 | "scripts": []
107 | }
108 | }
109 | }
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | jasmine: {
17 | // you can add configuration options for Jasmine here
18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19 | // for example, you can disable the random execution with `random: false`
20 | // or set a specific seed with `seed: 4321`
21 | },
22 | clearContext: false // leave Jasmine Spec Runner output visible in browser
23 | },
24 | jasmineHtmlReporter: {
25 | suppressAll: true // removes the duplicated traces
26 | },
27 | coverageReporter: {
28 | dir: require('path').join(__dirname, './coverage/rick-and-morty-app'),
29 | subdir: '.',
30 | reporters: [
31 | { type: 'html' },
32 | { type: 'text-summary' }
33 | ]
34 | },
35 | reporters: ['progress', 'kjhtml'],
36 | port: 9876,
37 | colors: true,
38 | logLevel: config.LOG_INFO,
39 | autoWatch: true,
40 | browsers: ['Chrome'],
41 | singleRun: false,
42 | restartOnFileChange: true
43 | });
44 | };
45 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rick-and-morty-app",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "watch": "ng build --watch --configuration development",
9 | "test": "ng test"
10 | },
11 | "private": true,
12 | "dependencies": {
13 | "@angular/animations": "^14.0.0",
14 | "@angular/common": "^14.0.0",
15 | "@angular/compiler": "^14.0.0",
16 | "@angular/core": "^14.0.0",
17 | "@angular/forms": "^14.0.0",
18 | "@angular/platform-browser": "^14.0.0",
19 | "@angular/platform-browser-dynamic": "^14.0.0",
20 | "@angular/router": "^14.0.0",
21 | "@popperjs/core": "^2.11.5",
22 | "bootstrap": "^5.2.0",
23 | "jquery": "^3.6.0",
24 | "ngx-infinite-scroll": "^14.0.0",
25 | "rxjs": "~7.5.0",
26 | "tslib": "^2.3.0",
27 | "zone.js": "~0.11.4"
28 | },
29 | "devDependencies": {
30 | "@angular-devkit/build-angular": "^14.0.4",
31 | "@angular/cli": "~14.0.4",
32 | "@angular/compiler-cli": "^14.0.0",
33 | "@types/jasmine": "~4.0.0",
34 | "jasmine-core": "~4.1.0",
35 | "karma": "~6.3.0",
36 | "karma-chrome-launcher": "~3.1.0",
37 | "karma-coverage": "~2.2.0",
38 | "karma-jasmine": "~5.0.0",
39 | "karma-jasmine-html-reporter": "~1.7.0",
40 | "typescript": "~4.7.2"
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { RouterModule, Routes } from '@angular/router';
3 |
4 | const routes: Routes = [
5 | {
6 | path: '',
7 | redirectTo: 'home',
8 | pathMatch: 'full'
9 | },
10 | {
11 | path: 'home',
12 | loadChildren: () =>
13 | import('./components/pages/home/home.module').then(m => m.HomeModule)
14 | },
15 | {
16 | path: 'character-list',
17 | loadChildren: () =>
18 | import('./components/pages/characters/character-list/character-list.module')
19 | .then(m => m.CharacterListModule) }, { path: 'character-details',
20 | loadChildren: () =>
21 | import('./components/pages/characters/character-details/character-details.module')
22 | .then(m => m.CharacterDetailsModule)
23 | },
24 | {
25 | path: 'character-details/:id',
26 | loadChildren: () =>
27 | import('./components/pages/characters/character-details/character-details.module')
28 | .then(m => m.CharacterDetailsModule)
29 | }
30 | ];
31 |
32 | @NgModule({
33 | imports: [RouterModule.forRoot(routes)],
34 | exports: [RouterModule]
35 | })
36 | export class AppRoutingModule { }
37 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/app/app.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paulo-magls/rick-and-morty-application/bc89ebe5ce86555f597aedcaf13e9e96bb63c564/src/app/app.component.scss
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 | import { RouterTestingModule } from '@angular/router/testing';
3 | import { AppComponent } from './app.component';
4 |
5 | describe('AppComponent', () => {
6 | beforeEach(async () => {
7 | await TestBed.configureTestingModule({
8 | imports: [
9 | RouterTestingModule
10 | ],
11 | declarations: [
12 | AppComponent
13 | ],
14 | }).compileComponents();
15 | });
16 |
17 | it('should create the app', () => {
18 | const fixture = TestBed.createComponent(AppComponent);
19 | const app = fixture.componentInstance;
20 | expect(app).toBeTruthy();
21 | });
22 |
23 | it(`should have as title 'rickAndMortyApp'`, () => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | const app = fixture.componentInstance;
26 | expect(app.title).toEqual('rickAndMortyApp');
27 | });
28 |
29 | it('should render title', () => {
30 | const fixture = TestBed.createComponent(AppComponent);
31 | fixture.detectChanges();
32 | const compiled = fixture.nativeElement as HTMLElement;
33 | expect(compiled.querySelector('.content span')?.textContent).toContain('rickAndMortyApp app is running!');
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.scss']
7 | })
8 | export class AppComponent {
9 | title = 'rickAndMortyApp';
10 | }
11 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { BrowserModule } from '@angular/platform-browser';
3 |
4 | import { AppRoutingModule } from './app-routing.module';
5 | import { AppComponent } from './app.component';
6 | import { HeaderComponent } from './shared/components/header/header.component';
7 | import { FormSearchComponent } from './shared/components/form-search/form-search.component';
8 | import { HttpClientModule } from '@angular/common/http';
9 |
10 | @NgModule({
11 | declarations: [
12 | AppComponent,
13 | HeaderComponent,
14 | FormSearchComponent
15 | ],
16 | imports: [
17 | BrowserModule,
18 | AppRoutingModule,
19 | HttpClientModule
20 | ],
21 | providers: [],
22 | bootstrap: [AppComponent]
23 | })
24 | export class AppModule { }
25 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-details/character-details-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { RouterModule, Routes } from '@angular/router';
3 | import { CharacterDetailsComponent } from './character-details.component';
4 |
5 | const routes: Routes = [{ path: '', component: CharacterDetailsComponent }];
6 |
7 | @NgModule({
8 | imports: [RouterModule.forChild(routes)],
9 | exports: [RouterModule]
10 | })
11 | export class CharacterDetailsRoutingModule { }
12 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-details/character-details.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-details/character-details.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paulo-magls/rick-and-morty-application/bc89ebe5ce86555f597aedcaf13e9e96bb63c564/src/app/components/pages/characters/character-details/character-details.component.scss
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-details/character-details.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { CharacterDetailsComponent } from './character-details.component';
4 |
5 | describe('CharacterDetailsComponent', () => {
6 | let component: CharacterDetailsComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async () => {
10 | await TestBed.configureTestingModule({
11 | declarations: [ CharacterDetailsComponent ]
12 | })
13 | .compileComponents();
14 |
15 | fixture = TestBed.createComponent(CharacterDetailsComponent);
16 | component = fixture.componentInstance;
17 | fixture.detectChanges();
18 | });
19 |
20 | it('should create', () => {
21 | expect(component).toBeTruthy();
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-details/character-details.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { ActivatedRoute } from '@angular/router';
3 | import { Character } from '@app/shared/interfaces/character.interface';
4 | import { CharacterService } from '@app/shared/services/character.service';
5 | import { Observable } from 'rxjs';
6 | import { Location } from '@angular/common';
7 | import { take } from 'rxjs/operators';
8 |
9 | @Component({
10 | selector: 'app-character-details',
11 | templateUrl: './character-details.component.html',
12 | styleUrls: ['./character-details.component.scss']
13 | })
14 | export class CharacterDetailsComponent implements OnInit {
15 | character$: Observable;
16 |
17 | constructor(private route: ActivatedRoute, private characterSvc: CharacterService, private location: Location) { }
18 |
19 | ngOnInit(): void {
20 | this.route.params.pipe(take(1)).subscribe((params) => {
21 | const id = params['id'];
22 | this.character$ = this.characterSvc.getDetails(id);
23 | })
24 | }
25 |
26 | onGoBack(): void {
27 | this.location.back();
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-details/character-details.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 |
4 | import { CharacterDetailsRoutingModule } from './character-details-routing.module';
5 |
6 |
7 | @NgModule({
8 | declarations: [],
9 | imports: [
10 | CommonModule,
11 | CharacterDetailsRoutingModule
12 | ]
13 | })
14 | export class CharacterDetailsModule { }
15 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-list/character-list-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { RouterModule, Routes } from '@angular/router';
3 | import { CharacterListComponent } from './character-list.component';
4 |
5 | const routes: Routes = [{ path: '', component: CharacterListComponent }];
6 |
7 | @NgModule({
8 | imports: [RouterModule.forChild(routes)],
9 | exports: [RouterModule]
10 | })
11 | export class CharacterListRoutingModule { }
12 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-list/character-list.component.html:
--------------------------------------------------------------------------------
1 |
10 |
11 | Developed by paulo-magls
12 |
13 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-list/character-list.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paulo-magls/rick-and-morty-application/bc89ebe5ce86555f597aedcaf13e9e96bb63c564/src/app/components/pages/characters/character-list/character-list.component.scss
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-list/character-list.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { CharacterListComponent } from './character-list.component';
4 |
5 | describe('CharacterListComponent', () => {
6 | let component: CharacterListComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async () => {
10 | await TestBed.configureTestingModule({
11 | declarations: [ CharacterListComponent ]
12 | })
13 | .compileComponents();
14 |
15 | fixture = TestBed.createComponent(CharacterListComponent);
16 | component = fixture.componentInstance;
17 | fixture.detectChanges();
18 | });
19 |
20 | it('should create', () => {
21 | expect(component).toBeTruthy();
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-list/character-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, HostListener, Inject, OnInit } from '@angular/core';
2 | import { ActivatedRoute, NavigationEnd, ParamMap, Router } from '@angular/router';
3 | import { DOCUMENT } from '@angular/common';
4 | import { take, filter } from 'rxjs/operators';
5 |
6 | import { Character } from '@app/shared/interfaces/character.interface';
7 | import { CharacterService } from '@app/shared/services/character.service';
8 | type RequestInfo = {
9 | next: null
10 | }
11 |
12 | @Component({
13 | selector: 'app-character-list',
14 | templateUrl: './character-list.component.html',
15 | styleUrls: ['./character-list.component.scss']
16 | })
17 | export class CharacterListComponent implements OnInit {
18 | characters: Character[] = [];
19 |
20 | info: RequestInfo = {
21 | next: null
22 | }
23 |
24 | showGoUpButton = false;
25 |
26 | private pageNum = 1;
27 | private query?: string;
28 | private hideScrollHeight = 200;
29 | private showScrollHeight = 500;
30 |
31 | constructor(
32 | @Inject(DOCUMENT) private document: Document,
33 | private characterSvc: CharacterService,
34 | private route: ActivatedRoute,
35 | private router: Router
36 | ) {
37 | this.onUrlChanged();
38 | }
39 |
40 | ngOnInit(): void {
41 | this.getCharactersByQuery();
42 | }
43 |
44 | @HostListener('window:scroll', [])
45 | onWindowScroll(): void {
46 | const yOffSet = window.pageYOffset;
47 | if((yOffSet || this.document.documentElement.scrollTop || this.document.body.scrollTop) > this.showScrollHeight) {
48 | this.showGoUpButton = true;
49 | } else if (this.showGoUpButton && (yOffSet || this.document.documentElement.scrollTop || this.document.body.scrollTop) < this.hideScrollHeight){
50 | this.showGoUpButton = false;
51 | }
52 | }
53 |
54 | onScrollDown(): void {
55 | if(this.info.next){
56 | this.pageNum++;
57 | this.getDataFromService();
58 | }
59 | }
60 |
61 | onScrollTop(): void {
62 | this.document.body.scrollTop = 0; // Safari
63 | this.document.documentElement.scrollTop = 0; // Others
64 | }
65 |
66 | private onUrlChanged(): void {
67 | this.router.events
68 | .pipe(filter((event) => event instanceof NavigationEnd))
69 | .subscribe(()=> {
70 | this.characters = [];
71 | this.pageNum = 1;
72 | this.getCharactersByQuery();
73 | });
74 | }
75 |
76 | private getCharactersByQuery(): void {
77 | this.route.queryParams.pipe(take(1)).subscribe((params: ParamMap) => {
78 | console.log('Params -> ', params);
79 | this.query = params['q'];
80 | this.getDataFromService();
81 | })
82 | }
83 |
84 | private getDataFromService(): void {
85 | this.characterSvc.searchCharacters(this.query, this.pageNum)
86 | .pipe(take(1))
87 | .subscribe((res: any) => {
88 | if(res?.results?.length) {
89 | const {info, results} = res;
90 | this.characters = [... this.characters, ... results];
91 | this.info = info;
92 | } else {
93 | this.characters = [];
94 | }
95 | });
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character-list/character-list.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 |
4 | import { CharacterListRoutingModule } from './character-list-routing.module';
5 |
6 |
7 | @NgModule({
8 | declarations: [],
9 | imports: [
10 | CommonModule,
11 | CharacterListRoutingModule
12 | ]
13 | })
14 | export class CharacterListModule { }
15 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/character.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
2 | import { Character } from '@app/shared/interfaces/character.interface';
3 |
4 | @Component({
5 | selector:'app-character',
6 | template:`
7 | `,
28 | changeDetection:ChangeDetectionStrategy.OnPush
29 | })
30 | export class CharacterComponent {
31 | @Input() character: Character;
32 | }
33 |
--------------------------------------------------------------------------------
/src/app/components/pages/characters/characters.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { RouterModule } from '@angular/router';
4 | import { CharacterDetailsComponent } from './character-details/character-details.component';
5 | import { CharacterListComponent } from './character-list/character-list.component';
6 | import { CharacterComponent } from './character.component';
7 | import { InfiniteScrollModule } from 'ngx-infinite-scroll';
8 |
9 | const myComponents = [
10 | CharacterDetailsComponent,
11 | CharacterListComponent,
12 | CharacterComponent
13 | ]
14 |
15 | @NgModule({
16 | declarations: [... myComponents],
17 | imports: [CommonModule, RouterModule, InfiniteScrollModule],
18 | exports: [... myComponents]
19 | })
20 | export class CharactersModule { }
21 |
--------------------------------------------------------------------------------
/src/app/components/pages/home/home-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { RouterModule, Routes } from '@angular/router';
3 | import { HomeComponent } from './home.component';
4 |
5 | const routes: Routes = [{ path: '', component: HomeComponent }];
6 |
7 | @NgModule({
8 | imports: [RouterModule.forChild(routes)],
9 | exports: [RouterModule]
10 | })
11 | export class HomeRoutingModule { }
12 |
--------------------------------------------------------------------------------
/src/app/components/pages/home/home.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/components/pages/home/home.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paulo-magls/rick-and-morty-application/bc89ebe5ce86555f597aedcaf13e9e96bb63c564/src/app/components/pages/home/home.component.scss
--------------------------------------------------------------------------------
/src/app/components/pages/home/home.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { HomeComponent } from './home.component';
4 |
5 | describe('HomeComponent', () => {
6 | let component: HomeComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async () => {
10 | await TestBed.configureTestingModule({
11 | declarations: [ HomeComponent ]
12 | })
13 | .compileComponents();
14 |
15 | fixture = TestBed.createComponent(HomeComponent);
16 | component = fixture.componentInstance;
17 | fixture.detectChanges();
18 | });
19 |
20 | it('should create', () => {
21 | expect(component).toBeTruthy();
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/src/app/components/pages/home/home.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-home',
5 | templateUrl: './home.component.html',
6 | styleUrls: ['./home.component.scss']
7 | })
8 | export class HomeComponent implements OnInit {
9 |
10 | constructor() { }
11 |
12 | ngOnInit(): void {
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/app/components/pages/home/home.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 |
4 | import { HomeRoutingModule } from './home-routing.module';
5 | import { HomeComponent } from './home.component';
6 | import { CharactersModule } from '../characters/characters.module';
7 |
8 |
9 | @NgModule({
10 | declarations: [
11 | HomeComponent
12 | ],
13 | imports: [
14 | CommonModule,
15 | HomeRoutingModule,
16 | CharactersModule
17 | ]
18 | })
19 | export class HomeModule { }
20 |
--------------------------------------------------------------------------------
/src/app/shared/components/form-search/form-search.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { Router } from '@angular/router';
3 |
4 | @Component({
5 | selector: 'app-form-search',
6 | template: `
7 |
15 | `,
16 | styles: ['input {width:100%;}']
17 | })
18 | export class FormSearchComponent implements OnInit {
19 |
20 | constructor(private router: Router) { }
21 |
22 | ngOnInit(): void {
23 | }
24 |
25 | onSearch(value: string) {
26 | if(value && value.length > 3){
27 | this.router.navigate(['/character-list'], {
28 | queryParams: { q: value }
29 | })
30 | }
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/app/shared/components/header/header.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/shared/components/header/header.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paulo-magls/rick-and-morty-application/bc89ebe5ce86555f597aedcaf13e9e96bb63c564/src/app/shared/components/header/header.component.scss
--------------------------------------------------------------------------------
/src/app/shared/components/header/header.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { HeaderComponent } from './header.component';
4 |
5 | describe('HeaderComponent', () => {
6 | let component: HeaderComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async () => {
10 | await TestBed.configureTestingModule({
11 | declarations: [ HeaderComponent ]
12 | })
13 | .compileComponents();
14 |
15 | fixture = TestBed.createComponent(HeaderComponent);
16 | component = fixture.componentInstance;
17 | fixture.detectChanges();
18 | });
19 |
20 | it('should create', () => {
21 | expect(component).toBeTruthy();
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/src/app/shared/components/header/header.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-header',
5 | templateUrl: './header.component.html',
6 | styleUrls: ['./header.component.scss']
7 | })
8 | export class HeaderComponent implements OnInit {
9 |
10 | constructor() { }
11 |
12 | ngOnInit(): void {
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/app/shared/interfaces/character.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Character {
2 | id: number;
3 | name: string;
4 | image: string;
5 | species: string;
6 | gender: string;
7 | created: string;
8 | status: string;
9 | }
--------------------------------------------------------------------------------
/src/app/shared/services/character.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 |
3 | import { CharacterService } from './character.service';
4 |
5 | describe('CharacterService', () => {
6 | let service: CharacterService;
7 |
8 | beforeEach(() => {
9 | TestBed.configureTestingModule({});
10 | service = TestBed.inject(CharacterService);
11 | });
12 |
13 | it('should be created', () => {
14 | expect(service).toBeTruthy();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/src/app/shared/services/character.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient } from '@angular/common/http';
3 | import { Character } from '../interfaces/character.interface';
4 | import { environment } from 'src/environments/environment';
5 |
6 | @Injectable({
7 | providedIn: 'root'
8 | })
9 | export class CharacterService {
10 |
11 | constructor(private http: HttpClient) { }
12 |
13 | searchCharacters(query = '', page = 1) {
14 | const filter = `${environment.baseUrlAPI}/?name=${query}&page=${page}`;
15 | return this.http.get(filter);
16 | }
17 |
18 | getDetails(id: number) {
19 | return this.http.get(`${environment.baseUrlAPI}/${id}`);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paulo-magls/rick-and-morty-application/bc89ebe5ce86555f597aedcaf13e9e96bb63c564/src/assets/.gitkeep
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true,
3 | baseUrlAPI: 'https://rickandmortyapi.com/api/character/'
4 | };
5 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false,
7 | baseUrlAPI: 'https://rickandmortyapi.com/api/character/'
8 | };
9 |
10 | /*
11 | * For easier debugging in development mode, you can import the following file
12 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
13 | *
14 | * This import should be commented out in production mode because it will have a negative impact
15 | * on performance if an error is thrown.
16 | */
17 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
18 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paulo-magls/rick-and-morty-application/bc89ebe5ce86555f597aedcaf13e9e96bb63c564/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Rick and Morty Application
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes recent versions of Safari, Chrome (including
12 | * Opera), Edge on the desktop, and iOS and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /**
22 | * By default, zone.js will patch all possible macroTask and DomEvents
23 | * user can disable parts of macroTask/DomEvents patch by setting following flags
24 | * because those flags need to be set before `zone.js` being loaded, and webpack
25 | * will put import in the top of bundle, so user need to create a separate file
26 | * in this directory (for example: zone-flags.ts), and put the following flags
27 | * into that file, and then add the following code before importing zone.js.
28 | * import './zone-flags';
29 | *
30 | * The flags allowed in zone-flags.ts are listed here.
31 | *
32 | * The following flags will work for all browsers.
33 | *
34 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
35 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
36 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
37 | *
38 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
39 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
40 | *
41 | * (window as any).__Zone_enable_cross_context_check = true;
42 | *
43 | */
44 |
45 | /***************************************************************************************************
46 | * Zone JS is required by default for Angular itself.
47 | */
48 | import 'zone.js'; // Included with Angular CLI.
49 |
50 |
51 | /***************************************************************************************************
52 | * APPLICATION IMPORTS
53 | */
54 |
--------------------------------------------------------------------------------
/src/styles.scss:
--------------------------------------------------------------------------------
1 | html {
2 | scroll-behavior: smooth;
3 | }
4 |
5 | body {
6 | background-color: rgb(44, 44, 44);
7 | }
8 |
9 | .container {
10 | margin-top: 4rem;
11 | }
12 |
13 | .card {
14 | box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 1px 2px rgba(0, 0, 0, .24);
15 | box-sizing: border-box;
16 | margin-top: 10px 0;
17 | background-color: rgb(44, 44, 44);
18 | max-width: 529px;
19 | white-space: nowrap;
20 | overflow: hidden;
21 | transition: all 0.2 ease-in-out;
22 | &:hover{
23 | box-shadow: 0 5px 5px rgba(0, 0, 0, .19), 0 6px 6px rgba(0, 0, 0, .24);
24 | cursor: pointer;
25 | }
26 | img{
27 | opacity: 0.7;
28 | width: 100%;
29 | transition: opacity 0.7;
30 | &:hover{
31 | opacity: 1;
32 | }
33 | }
34 |
35 | .card-inner{
36 | padding: 10px;
37 | }
38 | }
39 |
40 | .Alive {
41 | color: #adff2f;
42 | }
43 |
44 | .Dead {
45 | color: #ff0000;
46 | }
47 |
48 | .unknown {
49 | color: #808080;
50 | }
51 |
52 | #my-github {
53 | text-decoration: none;
54 | color: #fff;
55 | }
56 |
57 | .no-hidden {
58 | position: fixed;
59 | bottom: 10px;
60 | right: 10px;
61 | visibility: visible;
62 | }
63 |
64 | @media(max-width: 570px) {
65 | .card {
66 | img {
67 | opacity: 1;
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: {
11 | context(path: string, deep?: boolean, filter?: RegExp): {
12 | (id: string): T;
13 | keys(): string[];
14 | };
15 | };
16 |
17 | // First, initialize the Angular testing environment.
18 | getTestBed().initTestEnvironment(
19 | BrowserDynamicTestingModule,
20 | platformBrowserDynamicTesting(),
21 | );
22 |
23 | // Then we find all the tests.
24 | const context = require.context('./', true, /\.spec\.ts$/);
25 | // And load the modules.
26 | context.keys().forEach(context);
27 |
--------------------------------------------------------------------------------
/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/app",
6 | "types": []
7 | },
8 | "files": [
9 | "src/main.ts",
10 | "src/polyfills.ts"
11 | ],
12 | "include": [
13 | "src/**/*.d.ts"
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "compileOnSave": false,
4 | "compilerOptions": {
5 | "baseUrl": "./",
6 | "paths": {
7 | "@app/*":["src/app/*"],
8 | "@shared/*":["src/app/shared/*"],
9 | "@environment/*":["src/environment/*"],
10 | "@characters/*":["src/app/components/pages/characters/*"],
11 | "@pages/*":["src/app/components/pages/*"]
12 | },
13 | "outDir": "./dist/out-tsc",
14 | "forceConsistentCasingInFileNames": true,
15 | "strict": false,
16 | "noImplicitOverride": true,
17 | "noPropertyAccessFromIndexSignature": true,
18 | "noImplicitReturns": true,
19 | "noFallthroughCasesInSwitch": true,
20 | "sourceMap": true,
21 | "declaration": false,
22 | "downlevelIteration": true,
23 | "experimentalDecorators": true,
24 | "moduleResolution": "node",
25 | "importHelpers": true,
26 | "target": "es2020",
27 | "module": "es2020",
28 | "lib": [
29 | "es2020",
30 | "dom"
31 | ]
32 | },
33 | "angularCompilerOptions": {
34 | "enableI18nLegacyMessageIdFormat": false,
35 | "strictInjectionParameters": true,
36 | "strictInputAccessModifiers": true,
37 | "strictTemplates": true
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/spec",
6 | "types": [
7 | "jasmine"
8 | ]
9 | },
10 | "files": [
11 | "src/test.ts",
12 | "src/polyfills.ts"
13 | ],
14 | "include": [
15 | "src/**/*.spec.ts",
16 | "src/**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------