FriendsOfFlarum / gamification

Add upvotes, downvotes, and ranks to your Flarum Community
https://discuss.flarum.org/d/20671-friendsofflarum-gamification
MIT License
36 stars 17 forks source link

Fix missing / non-array user.ranks() issue on v17development/flarum-support #114

Open hackerESQ opened 9 months ago

hackerESQ commented 9 months ago

Related to v17development/flarum-support-feedback#14 which causes support page to break.

Changes proposed in this pull request: This change adds a conditional check to make sure the user.ranks() is actually loaded. If the rank is falsey, it does not try to add user rank to the PostUser view.

Reviewers should focus on:

    if (user.ranks()) { // <-- added this conditional
      header_node.children = header_node.children
        .concat(
          user
            .ranks()
            .reverse()
            .splice(0, amt)
            .map((rank) => {
              return <span className="Post-Rank">{rankLabel(rank)}</span>;
            })
        )
        .filter(function (el) {
          return el.tag !== undefined;
        });
    }

Screenshot This is how the support tickets page was breaking: image

And here's the console log showing the ranks() trying to reverse() which is not available since it's not an array: image

Confirmed

Required changes: N/A

hackerESQ commented 9 months ago

Not sure if that's the right way to do that. But let me know if that works.

DavideIadeluca commented 6 months ago

Hi @hackerESQ thanks for your contribution! This branch still has conflicts that must be resolved. I suggest that you git reset the branch back to the first commit you made and then force push to remote.