Skip to content
This repository was archived by the owner on Jul 8, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 0 additions & 213 deletions src/app/app.component.html

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import { AppComponent } from './app.component';
import { GraphQLModule } from './graphql.module';
import { HttpClientModule } from '@angular/common/http';
import { ExchangeRatesComponent } from './exchange-rates/exchange-rates.component';
import { PersonalityComponent } from './personality/personality.component';

@NgModule({
declarations: [
AppComponent,
ExchangeRatesComponent
],
imports: [
BrowserModule,
GraphQLModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
declarations: [
AppComponent,
ExchangeRatesComponent,
PersonalityComponent
],
imports: [
BrowserModule,
GraphQLModule,
HttpClientModule
],
providers: [],
bootstrap: [
AppComponent
]
})
export class AppModule { }
27 changes: 21 additions & 6 deletions src/app/exchange-rates/exchange-rates.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
<p>This component is made by me! The information below is queried from a GraphQL server that gave me exchange rates:</p>
<p>What type of pokemon are you?</p>

<div *ngIf="loading">
Loading...
</div>
<div *ngIf="error">
Error :(
</div>
<div *ngIf="rates">
<div *ngFor="let rate of rates">
<p>{{rate.currency}}: {{rate.rate}}</p>
</div>
</div>
<!-- <div *ngIf="rates">
<p>{{rates.name}}</p>
</div> -->
<p>I like to do things last minuite</p>
<app-personality (notify)="onNotify($event)"></app-personality>
<p>I have trouble managing my time</p>
<app-personality (notify)="onNotify($event)"></app-personality>
<p>I like fire</p>
<app-personality (notify)="onNotify($event)"></app-personality>
<p>I like water</p>
<app-personality (notify)="onNotify($event)"></app-personality>
<p>I like grass for some reason</p>
<app-personality (notify)="onNotify($event)"></app-personality>
<p>I really need help</p>
<app-personality (notify)="onNotify($event)"></app-personality>
<p>I want to free myself of this pain</p>
<app-personality (notify)="onNotify($event)"></app-personality>
<button (click)=whatAmI()>"what pokemon am I?"</button>
<button (click)=getMoreInfo()>"pokemon info"</button>

28 changes: 26 additions & 2 deletions src/app/exchange-rates/exchange-rates.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GraphQLModule } from '../graphql.module';
import { ExchangeRatesComponent } from './exchange-rates.component';
import { HttpClientModule } from '@angular/common/http';
import { FieldsOnCorrectTypeRule } from 'graphql';

describe('ExchangeRatesComponent', () => {
let component: ExchangeRatesComponent;
Expand All @@ -15,13 +16,36 @@ describe('ExchangeRatesComponent', () => {
.compileComponents();
}));

it('should create', () => {
expect(component).toBeTruthy();
});
it('should create', () => {
expect(component.pokemon).toBeFalsy();
});
it('should create', () => {
expect(component.pokemonid).toBeFalsy();
});
it('should create', () => {
expect(component.pokemonmoves).toBeFalsy();
});

beforeEach(() => {
fixture = TestBed.createComponent(ExchangeRatesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
spyOn(component, 'whatAmI');
expect(component.pokemon).toBeTruthy();
expect(component.pokemonid).toBeTruthy();
expect(component.pokemonmoves).toBeTruthy();

});

it('should create', () => {
expect(component).toBeTruthy();
beforeEach(() => {
fixture = TestBed.createComponent(ExchangeRatesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
spyOn(component, 'getMoreInfo');
expect(window.alert).toHaveBeenCalledWith("You havent revealed your pokemon yet!!!");
});

});
97 changes: 83 additions & 14 deletions src/app/exchange-rates/exchange-rates.component.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,105 @@
import { Component, OnInit } from '@angular/core';
import {Apollo} from 'apollo-angular';
import gql from 'graphql-tag';
import { ApolloQueryResult } from 'apollo-client';
import { Component, OnInit } from "@angular/core";
import { Apollo } from "apollo-angular";
import gql from "graphql-tag";
import { ApolloQueryResult } from "apollo-client";

@Component({
selector: 'app-exchange-rates',
templateUrl: './exchange-rates.component.html',
styleUrls: ['./exchange-rates.component.css']
selector: "app-exchange-rates",
templateUrl: "./exchange-rates.component.html",
styleUrls: ["./exchange-rates.component.css"]
})
export class ExchangeRatesComponent implements OnInit {
rates: any[];

loading = true;
error: any;

myCount: number = 0;
totalnum: number;
pokemon: string;
pokemonmoves: any[];
pokemonid: string;
constructor(private apollo: Apollo) {}

ngOnInit() {
this.apollo
.watchQuery({
// {
// rates(currency: "USD") {
// currency
// rate
// }
// }

query: gql`
{
rates(currency: "USD") {
currency
rate
pokemons(first: 1000) {
name
}
}
`,
`
})
.valueChanges.subscribe((result: ApolloQueryResult<any>) => {
this.rates = result.data && result.data.rates;
this.rates = result.data.pokemons;
this.loading = result.loading;
this.error = result.errors;
this.totalnum = this.rates.length;
});
}
onNotify($event: any) {
console.log($event);
this.myCount += $event;
console.log(this.totalnum);
}
whatAmI() {
this.pokemon = this.rates[
(this.myCount * this.myCount) % this.totalnum
].name;
window.alert(this.pokemon);
this.getInfo();
}
getInfo() {
const pokemoninfo = gql`
query pokemoninfo($name: String!) {
pokemon(name: $name) {
id
number
name
attacks {
special {
name
type
damage
}
}
}
}
`;

this.apollo
.watchQuery({
query: pokemoninfo,
variables: {
name: this.pokemon
}
})
.valueChanges.subscribe((result: ApolloQueryResult<any>) => {
this.pokemonmoves = result.data.pokemon.attacks.special;
this.pokemonid = result.data.pokemon.id;
}); // do whatever

// 1, "string", false
}

getMoreInfo() {
if (!this.pokemon) {
// if a is negative,undefined,null,empty value then...
window.alert("You havent revealed your pokemon yet!!!"); // do whatever
} else {
window.alert("Your pokemon name is " + this.pokemon);

window.alert("Your pokemon id is " + this.pokemonid);
for (let move of this.pokemonmoves) {
window.alert("You can do " + move.name + " attack!");
}
}
}
}
2 changes: 1 addition & 1 deletion src/app/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ApolloModule, APOLLO_OPTIONS} from 'apollo-angular';
import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory';

const uri = 'https://o5x5jzoo7z.sse.codesandbox.io/graphql'; // <-- change the URL to point to Yelp GraphQL server, this is just a test server
const uri = 'https://graphql-pokemon.now.sh/'; // <-- change the URL to point to Yelp GraphQL server, this is just a test server
export function createApollo(httpLink: HttpLink) {
return {
link: httpLink.create({uri}),
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions src/app/personality/personality.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<div *ngFor="let item of [0,1,2,3,4]; let i = index;">
<input type="radio" (click)="submitNum(item)"> {{item}}
</div>
30 changes: 30 additions & 0 deletions src/app/personality/personality.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';

import { PersonalityComponent } from './personality.component';

describe('PersonalityComponent', () => {
let component: PersonalityComponent;
let fixture: ComponentFixture<PersonalityComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PersonalityComponent ]
})
.compileComponents();
}));



beforeEach(() => {
fixture = TestBed.createComponent(PersonalityComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
23 changes: 23 additions & 0 deletions src/app/personality/personality.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component, OnInit } from '@angular/core';
import { Output, EventEmitter } from '@angular/core'
@Component({
selector: 'app-personality',
templateUrl: './personality.component.html',
styleUrls: ['./personality.component.css']
})
export class PersonalityComponent implements OnInit {
@Output() notify = new EventEmitter();

submitNum($event: any) {
this.notify.emit($event);


}
constructor() { }

ngOnInit() {
}



}