Skip to content

fix: Display sponsor size according to their level #5532

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

Merged
merged 2 commits into from
Nov 9, 2020
Merged
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
5 changes: 5 additions & 0 deletions app/components/public/sponsor-item.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="ui column">
<a href="{{@sponsor.url}}" target="_blank" rel="noopener nofollow">
<img src="{{@sponsor.logoUrl}}" height="250" width="250" class="ui image sponsor-image" alt="{{@sponsor.name}}">
</a>
</div>
7 changes: 0 additions & 7 deletions app/components/public/sponsor-item.js

This file was deleted.

10 changes: 10 additions & 0 deletions app/components/public/sponsor-list.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{#each-in this.sponsorsGrouped as |key sponsorsGroup|}}
{{#if (not-eq key 'null')}}
<h4 class="ui header">{{key}}</h4>
{{/if}}
<div class="ui {{sponsorsGroup.columns}} column stackable grid">
{{#each sponsorsGroup.sponsors as |sponsor|}}
<Public::SponsorItem @sponsor={{sponsor}} />
{{/each}}
</div>
{{/each-in}}
18 changes: 0 additions & 18 deletions app/components/public/sponsor-list.js

This file was deleted.

58 changes: 58 additions & 0 deletions app/components/public/sponsor-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { computed } from '@ember/object';
import Component from '@glimmer/component';
import { orderBy, groupBy } from 'lodash-es';

interface Sponsor { level: number, type: string }

interface Args {
sponsors: Sponsor[]
}

interface GroupedSponsors { [key: string]: { sponsors: Sponsor[], columns: string } }

export default class SponsorList extends Component<Args> {

getDistinctLevels(sponsors: Sponsor[]): number[] {
const levels = new Set(sponsors.toArray().map(sponsor => sponsor.level).filter(level => level != null));
return [...levels].sort((a, b) => a - b);
}

@computed('sponsors.[]')
get distinctLevels(): number[] {
return this.getDistinctLevels(this.args.sponsors);
}

inferColumns(sponsors: Sponsor[]): string {
const levels = this.distinctLevels;
const groupLevels = this.getDistinctLevels(sponsors);

const groupLevel = groupLevels.pop();
if (groupLevel !== null && groupLevel !== undefined) {
const index = levels.indexOf(groupLevel);
const columns = ['three', 'four', 'five', 'six', 'seven'];
return columns[Math.min(index, columns.length - 1)];
}

return 'three';
}

@computed('sponsors.[]')
get sponsorsGrouped(): GroupedSponsors {
const grouped = groupBy(
orderBy(
this.args.sponsors.toArray(),
sponsor => sponsor.level
),
sponsor => sponsor.type
);

const finalGrouped: GroupedSponsors = {};
for (const [key, sponsors] of Object.entries(grouped)) {
finalGrouped[key] = {
sponsors,
columns: this.inferColumns(sponsors)
};
}
return finalGrouped;
}
}
2 changes: 1 addition & 1 deletion app/controllers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class RegisterController extends Controller {
this.model.save()
.then(user => {
this.set('session.newUser', user.get('email'));
this.send('loginExistingUser', user.get('email'), password, this.inviteToken, this.event);
this.send('loginExistingUser', user.get('email'), password, this.inviteToken, this.event);
})
.catch(reason => {
if (reason && Object.prototype.hasOwnProperty.call(reason, 'errors') && reason.errors[0].status === 409) {
Expand Down
10 changes: 0 additions & 10 deletions app/templates/components/public/sponsor-list.hbs

This file was deleted.