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

Award editor #331

Merged
merged 15 commits into from Dec 12, 2020
Merged

Award editor #331

merged 15 commits into from Dec 12, 2020

Conversation

luso97
Copy link
Contributor

@luso97 luso97 commented Nov 25, 2020

Feature #302 finished. All the problems you mentioned are fixed so I think it´s all done. i finally created an external component for the selects so it would be pretty easy to change it if neccesary, and all the error handling is done outside of this component.

Copy link
Member

@dumbmatter dumbmatter left a comment

Choose a reason for hiding this comment

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

This is awesome, thank you so much!

I left a bunch of comments. You can handle as many of them as you want, just let me know. I could definitely take it from here and address them all if you don't want to deal with it. Or if you do want to deal with it, that's great too. Or in between :)

Additional comments that don't fit inline with the code:

  • Run yarn run lint and there are some warnings that should be addressed.

  • The react-select inputs look bad in dark mode (Tools > Global Settings)

  • Add link from season summary page to form (only in God Mode)

  • If there is no player winning an award (such as MIP in the first season), if you add a player for that award, you can't remove it again. i guess ideally it should be possible for "nobody" to be selected for any award

  • In BBGM, editing the All-Defensive team doesn't seem to work, no changes get saved. All-League does work.

  • Would be nice to combine EditAwardsBasketball and EditAwardsFootball into one file, where all the UI code is shared and there is just some configuration object that differs across sports. Similar to how it works in Settings.tsx, where some settings are only available in FBGM or BBGM.

const teamSelect = element["players"].map(
(player: any, j: number) => {
return (
<div className="col form-group">
Copy link
Member

Choose a reason for hiding this comment

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

Add key={j} - without that, you see a warning message in the JS console from React. Same on line 286.

const p = await idb.cache.players.get(pid);
if (p) {
p.awards = p.awards.filter(
x => x.season != season || x.type! in awardsToDelete,
Copy link
Member

Choose a reason for hiding this comment

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

x.type! in awardsToDelete - how does this even work? If awardsToDelete is an array, this should always return false, because in looks at the keys of an object (which for an array are the numeric indices) and x.type is not a number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is so it doesn´t delete League champs. Basically what it does is just leaves those awards that are not changed on the form and those awards from other season

Copy link
Member

Choose a reason for hiding this comment

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

I understand that's what you intend for it to do, but x.type! in awardsToDelete will always be false. Try and see. Probably should be !awardsToDelete.includes(x.type)

Copy link
Contributor Author

@luso97 luso97 Dec 8, 2020

Choose a reason for hiding this comment

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

Doesn´t work since awardsToDelete is an object so includes is not a method. I have seen that The x.type! in awardsToDelete is not always false. For example if the player has a finalChamps award or an all star award, those awards is not included in awardsToDelete so the filter applies. I have tried erasing that part of the filter and it deletes the finals champ awards, which is what I´m trying to avoid. And I have printed in the console what the x.type!in awardsToDelete filter returns and it returns all the all star and champ awards, so that when updating the awards those are not changed whatsoever

Copy link
Member

Choose a reason for hiding this comment

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

awardsToDelete: string[], a few lines up says it's an array, and the only time this function is called, it's given a value of Object.values(awardNames) which is an array.

let awards = await idb.getCopy.awards({
season,
});

Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to default to last season if we know there are no awards for the current season, like:

if (!awards) {
    if (g.get("season") === season && g.get("phase") <= PHASE.PLAYOFFS) {
        season -= 1;
        awards = await idb.getCopy.awards({
		season,
	});
    }
}

(This is done after checking for the presence of awards in case some weird situation happens where there actually is an awards object before this season's playoffs end)

godMode: true,
league: true,
path: ["edit_awards"],
text: "Edit awards",
Copy link
Member

Choose a reason for hiding this comment

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

For consistency, name it "Edit Awards" and move after "Delete Old Data"

import React, { createRef } from "react";
import Select from "react-select";

class SelectReact extends React.Component<
Copy link
Member

Choose a reason for hiding this comment

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

This really doesn't matter, and you don't have to do anything about it, but I would have used hooks here. Generally I like the hooks API better, and I do have some shared hooks I use in multiple components that don't work with class components. Not relevant here, but maybe it would be in the future.

options={players}
player={awards["finalsMvp"]}
award="finalsMvp"
changing={handleChange.bind(this)}
Copy link
Member

Choose a reason for hiding this comment

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

Don't need .bind(this) in any of these, because handleChange does not use this so it doesn't matter what it is. Also this is undefined here anyway, since this is in an arrow function. Another nice thing about not using classes, you can ignore all the nonsense about what this is!

process.env.SPORT === "basketball"
? (["mvp", "roy", "smoy", "dpoy", "mip", "finalsMvp"] as const)
: (["mvp", "dpoy", "droy", "oroy", "finalsMvp"] as const);
const awardNames =
Copy link
Member

Choose a reason for hiding this comment

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

Since these are also defined exactly the same in doAwards.basketball.ts and doAwards.football.ts, they should be shared. Maybe as a new object in constants.basketball.ts and constants.football.ts which can then be imported both here and in the doAwards files.

Same with simpleAwards I think.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, a bunch of the code below seems to be duplicated from the doAwards files, so maybe all of this should just be put into a single function which gets called here and in the doAwards files, maybe called makeAwardsByPlayer(awards). I think that would be everything here before the awardsByPlayerToDelete stuff.

@@ -321,11 +327,29 @@ const saveAwardsByPlayer = async (
}
}
};
const deleteAwardsByPlayer = async (
awardsByPlayer: AwardsByPlayer,
conditions: Conditions,
Copy link
Member

Choose a reason for hiding this comment

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

This is never used, so it should not be an argument to this function.

if (p) {
for (const awardByPlayer of awardsByPlayer) {
if (awardByPlayer.pid === pid) {
p.awards.push({
season: g.get("season"),
season: season ? season : g.get("season"),
Copy link
Member

Choose a reason for hiding this comment

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

Fun new syntax! This can be season: season ?? g.get("season"). Or better yet, it can just be season, if you change line 265 to:

        season: number = g.get("season"),

const p2 = await idb.getCopy.players({
pid: pid,
});
p = p2 as PlayerFiltered;
Copy link
Member

Choose a reason for hiding this comment

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

PlayerFiltered is any, so might as well just call this any if that's what needs to be done. I feel like it should work to just make line 311.

this should work:

			p = await idb.getCopy.players({
				pid: pid,
			}); 

...except my return value from getCopy.players is wrong, should be undefined rather than void. If changing that causes other problems, don't worry about it, I can deal with this :)

Luis Morán added 6 commits December 3, 2020 11:04
@luso97
Copy link
Contributor Author

luso97 commented Dec 8, 2020

Everything works now and I have changed everything you mentioned. The only thing I didn´t change is the x.type! in awardsToDelete . for the reason I posted above. I also haven´t merged both EditFootball and EditBasketball (last bullet point in the comment above), if you think is neccesary I can look at that issue but could take some time, since I have looked at Setttings.tsx and haven´t figured out how to equate it to the code I have done already. I don´t know if you want it exactly like it is there or it was just an example.

Edit: Actually, if you don´t want it like in Settings.tsx it would be pretty easy to do I think, just some process.env.sport==football or basketball in the individual awards, and maybe 2 handleChange since the method differs a little between sports. So if that suits you, I´ll do it that way.

@luso97
Copy link
Contributor Author

luso97 commented Dec 9, 2020

I have finally merged both files in one with what I said in the last comment, since I saw it was pretty easy. So, I would say the whole functionality is done barring any error or bad practice.

@dumbmatter
Copy link
Member

I have finally merged both files in one with what I said in the last comment, since I saw it was pretty easy. So, I would say the whole functionality is done barring any error or bad practice.

Thanks. I think I'm going to try making a few minor tweaks and then merge it...

name: p.name,
tid: p.tid,
abbrev: p.abbrev,
pts: p.currentStats == undefined ? 0.0 : p.currentStats.pts,
Copy link
Member

Choose a reason for hiding this comment

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

(don't fix this, I'm editing stuff now)

0.0 vs 0 in Python is meaningful, but JS has only floats, so 0 and 0.0 are exactly the same thing.

}
};
const makeAwardsByPlayer = async (awards: any, conditions: Conditions) => {
const awardsByPlayer: AwardsByPlayer = [];
Copy link
Member

Choose a reason for hiding this comment

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

Before this function was created, awardsByPlayer was not an empty array at this point, it had the league leaders in it. So league leader awards are missing from players here :)

@dumbmatter
Copy link
Member

I did some work on this branch https://github.com/dumbmatter/gm-games/tree/luso97-award-editor and deployed it to https://beta.basketball-gm.com/ and https://beta.football-gm.com/ for a little user testing. Please let me know if you notice something I broke!

@dumbmatter dumbmatter merged commit 19ee430 into zengm-games:master Dec 12, 2020
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.

None yet

2 participants