Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor POIs so that Mobs can be displayed #131

Merged
merged 24 commits into from
Oct 19, 2016
Merged

Refactor POIs so that Mobs can be displayed #131

merged 24 commits into from
Oct 19, 2016

Conversation

MajorBreakfast
Copy link
Contributor

@MajorBreakfast MajorBreakfast commented Oct 18, 2016

WIP

@MajorBreakfast
Copy link
Contributor Author

MajorBreakfast commented Oct 18, 2016

mob-card

Note: This PR is a lot more than this simple layout. I've refactored the layout of the sightings card and a lot of related stuff.

You may review it now! :) Let's get it merged

@gyachdav
Copy link

Mucho cool!

@MajorBreakfast MajorBreakfast mentioned this pull request Oct 18, 2016
@WoH
Copy link
Member

WoH commented Oct 19, 2016

There's 2 or more things going on in one PR again ...

@MajorBreakfast
Copy link
Contributor Author

MajorBreakfast commented Oct 19, 2016

more things going on in one PR

@WoH There's not. I never touched anything that wasn't related. If you want, you can think about this PR as "Refactor POIs so that Mobs can be displayed". If I had left things as they were, it would have been a mess. Nevertheless, plz review. I'd like to get this in. ;)

@WoH
Copy link
Member

WoH commented Oct 19, 2016

@MajorBreakfast I would've liked to have the initial refractoring in a PR.

@WoH
Copy link
Member

WoH commented Oct 19, 2016

I'd want @johartl to comment, the POI Cards are his baby.

@MajorBreakfast MajorBreakfast changed the title Mob card Refactor POIs so that Mobs can be displayed Oct 19, 2016
@MajorBreakfast
Copy link
Contributor Author

MajorBreakfast commented Oct 19, 2016

I would've liked to have the initial refractoring in a PR.

@WoH I've changed the name. The actual Mob card is the least part of this PR. However, there is little value in separating it out. I agree that @johartl should comment.

@MajorBreakfast
Copy link
Contributor Author

I'm going to merge this this evening unless there are objections to any of the things I changed. The code is clean and I tested all affected app parts thoroughly, so it should be fine.

return sighting;
} else if ('clusterId' in rawData) {
const mob = new Mob();
return mob;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for returning an empty mob object here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the map already produce mobs? If so, what's the exact format of the event data?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if they already do. But the data should look like this PokemonGoers/PokeMap-2#32 (comment) which is exactly what our Mob class represents.
The best thing you can probably do is const mob = Mob.fromObject(rawData);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I just realized that you've removed the fromObject method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it from the model itself because it doesn't really belong in there.

<div class="title">PokeMob</div>
<div class="description">
A lot of players seem to gather at this location!<br><br>
Based on {{ poi.tweets.length }} tweet(s).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the definition of a mob there should always be multiple tweets so I think you can replace tweet(s) by tweets

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I'll change it.

@@ -10,4 +10,7 @@
</button>

<poke-poi-card #poiCard></poke-poi-card>

<button id="artificial-mob-button"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad you added this button so I can test your functionality. But obviously that shouldn't end up in the final product. So I think either the button should be removed at all or somehow hidden such that it can only by used by developers.

Copy link
Contributor Author

@MajorBreakfast MajorBreakfast Oct 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it in for now, so that people can try it out. It's easy enough to remove later. It's for developers only, but triggering it through the console would be two cumbersome.

Copy link
Member

@WoH WoH Oct 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just make sure neither mock data nor the button remain after all.
I like being able to test it that way though.
This would be beautiful to test with a mock websocket (I believe that's where we get those).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is triggering it through the console cumbersome? And even if it is, this functionality will only ever be used for testing purposes by developers. So it doesn't have to be easily accessible by everyone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WoH What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I can remove it immediately, e.g. by uncommenting it
  • Or keep it for a while, e.g. remove it before we launch/map shows mobs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe show it only in dev Mode?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe set the style to display: none and then anyone can still look for the element in the DOM using the developer console and make it visible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it is only shown in dev mode

@johartl
Copy link
Collaborator

johartl commented Oct 19, 2016

Regarding the discussion about too many things in one PR. I mostly agree that all changes focus around the mob card with the exception of renaming PokeSighting, PokeAttack, PokeGender, PokeMob, and some more. Personally, I think you could have done this in a separate PR.

} else {
throw new Error('PokePOI cannot be identified as PokeSighting or PokeMob:\n' + JSON.stringify(pokePOI));
}
function poiFromMapEventData(rawData: any) : POI {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason to use the function keyword

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that TypeScript feature?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and we are using it all over the place I think 😆 http://www.typescriptlang.org/docs/handbook/classes.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compile error. Am I doing something wrong?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you paste the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript docu uses the keyword as well https://www.typescriptlang.org/docs/handbook/functions.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class ends before the function definition, I didn't realiize this on github.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly.

Copy link
Contributor Author

@MajorBreakfast MajorBreakfast Oct 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johartl Should I make this a static method or a utility function? What do you prefer? I and @WoH need another opinion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the static method

<ion-row>
<div id="slide-card" #slideCard @slide="slideState">
<!-- Sightings -->
<div *ngIf="poi && poi.type == 'sighting' && pokemon">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could make use of the Elvis operator here: <div *ngIf="poi?.type == 'sighting' && pokemon">

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elvis operator :) I'll change that

Copy link
Member

@WoH WoH Oct 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that's something very Angular2 specific, but I think it is nice. Easy to understand, and makes these checks really concise.

Directions
</button>
<!-- Mobs -->
<div *ngIf="poi && poi.type == 'mob'">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jep

timestamp: number;

type = 'mob';
}

export type PokeTweet = {
export type MobTweet = {
Copy link
Collaborator

@johartl johartl Oct 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we extract this class to a separate file and call it Tweet we can reuse it in other parts of the application. For instance, the sentiment analysis also returns an array of tweets and these are not related to mobs.

@MajorBreakfast
Copy link
Contributor Author

@johartl Plz update your review.

@MajorBreakfast
Copy link
Contributor Author

Clear to merge? Any other wishes?

@@ -25,4 +24,5 @@ export class ConfigService {
}
}

buildEnvironment = env.BUILD_ENV;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  get buildEnvironment(): string {
    return env.BUILD_ENV;
  }

For consistency reasons this is better here maybe.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Even better: a method isDevelopEnvironment()

get isDevelopEnvironment(): boolean {
    return env.BUILD_ENV === 'develop';
}

But that's just my personal preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@MajorBreakfast MajorBreakfast merged commit 2c6511e into PokemonGoers:develop Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants