From 1b8cbeea460fd69b7aae3db193306a6cf2cf62c2 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Fri, 25 Oct 2024 16:16:12 +0100 Subject: [PATCH 1/6] Refactor contest navigation to use navigable contests and add slugPrefix getter. --- app/components/contest-page/navigation.ts | 16 ++++++++++------ app/models/contest.ts | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/components/contest-page/navigation.ts b/app/components/contest-page/navigation.ts index a70824ed4..ef067d818 100644 --- a/app/components/contest-page/navigation.ts +++ b/app/components/contest-page/navigation.ts @@ -16,7 +16,7 @@ export default class ContestPageNavigationComponent extends Component @service declare date: DateService; get currentContestIndex(): number { - return this.sortedContests.indexOf(this.args.contest); + return this.sortedNavigableContests.indexOf(this.args.contest); } get isNextContestDisabled(): boolean { @@ -27,9 +27,13 @@ export default class ContestPageNavigationComponent extends Component return !this.previousContest; } + get navigableContests(): ContestModel[] { + return this.args.allContests.filter((contest) => contest.slugPrefix === this.args.contest.slugPrefix); + } + get nextContest(): ContestModel | null { - if (this.currentContestIndex < this.sortedContests.length - 1) { - const nextContest = this.sortedContests[this.currentContestIndex + 1] as ContestModel; + if (this.currentContestIndex < this.sortedNavigableContests.length - 1) { + const nextContest = this.sortedNavigableContests[this.currentContestIndex + 1] as ContestModel; const oneWeekFromNow = new Date(this.date.now() + 7 * 24 * 60 * 60 * 1000); if (nextContest.startsAt < oneWeekFromNow) { @@ -44,14 +48,14 @@ export default class ContestPageNavigationComponent extends Component get previousContest(): ContestModel | null { if (this.currentContestIndex > 0) { - return this.sortedContests[this.currentContestIndex - 1] as ContestModel; + return this.sortedNavigableContests[this.currentContestIndex - 1] as ContestModel; } else { return null; } } - get sortedContests(): ContestModel[] { - return this.args.allContests.sortBy('startsAt'); + get sortedNavigableContests(): ContestModel[] { + return this.navigableContests.sortBy('startsAt'); } } diff --git a/app/models/contest.ts b/app/models/contest.ts index 98bb02e49..1204101fb 100644 --- a/app/models/contest.ts +++ b/app/models/contest.ts @@ -35,4 +35,8 @@ export default class ContestModel extends Model { get leaderboardEntriesRevealedAt(): Date { return new Date(this.startsAt.getTime() + 1000 * 60 * 60 * 24); // 24 hours after contest starts } + + get slugPrefix(): string { + return this.slug.replace(/-\d+$/, ''); + } } From d6ce5a939335b1eae577798070b3dcd5b106f1c5 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Fri, 25 Oct 2024 16:18:43 +0100 Subject: [PATCH 2/6] Refactor nextContest and previousContest getters for cleaner logic. --- app/components/contest-page/navigation.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/app/components/contest-page/navigation.ts b/app/components/contest-page/navigation.ts index ef067d818..234e12298 100644 --- a/app/components/contest-page/navigation.ts +++ b/app/components/contest-page/navigation.ts @@ -32,23 +32,12 @@ export default class ContestPageNavigationComponent extends Component } get nextContest(): ContestModel | null { - if (this.currentContestIndex < this.sortedNavigableContests.length - 1) { - const nextContest = this.sortedNavigableContests[this.currentContestIndex + 1] as ContestModel; - const oneWeekFromNow = new Date(this.date.now() + 7 * 24 * 60 * 60 * 1000); - - if (nextContest.startsAt < oneWeekFromNow) { - return nextContest; - } else { - return null; - } - } else { - return null; - } + return this.sortedNavigableContests[this.currentContestIndex + 1] || null; } get previousContest(): ContestModel | null { if (this.currentContestIndex > 0) { - return this.sortedNavigableContests[this.currentContestIndex - 1] as ContestModel; + return this.sortedNavigableContests[this.currentContestIndex - 1] || null; } else { return null; } From 19ed47f6fcef582b17bf23510b3f19f334533171 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Fri, 25 Oct 2024 16:28:10 +0100 Subject: [PATCH 3/6] improve leaderboard entry colours --- app/components/contest-page/leaderboard-entry.hbs | 2 +- app/components/contest-page/leaderboard-entry.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/contest-page/leaderboard-entry.hbs b/app/components/contest-page/leaderboard-entry.hbs index 6a8798393..703315d86 100644 --- a/app/components/contest-page/leaderboard-entry.hbs +++ b/app/components/contest-page/leaderboard-entry.hbs @@ -1,7 +1,7 @@ diff --git a/app/components/contest-page/leaderboard-entry.ts b/app/components/contest-page/leaderboard-entry.ts index 97288c8df..def6fd23d 100644 --- a/app/components/contest-page/leaderboard-entry.ts +++ b/app/components/contest-page/leaderboard-entry.ts @@ -24,7 +24,7 @@ export default class ContestPageLeaderboardEntryComponent extends Component Date: Fri, 25 Oct 2024 16:51:01 +0100 Subject: [PATCH 4/6] update green bg --- app/components/contest-page/leaderboard-entry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/contest-page/leaderboard-entry.ts b/app/components/contest-page/leaderboard-entry.ts index def6fd23d..fc0d7ddb8 100644 --- a/app/components/contest-page/leaderboard-entry.ts +++ b/app/components/contest-page/leaderboard-entry.ts @@ -21,7 +21,7 @@ export default class ContestPageLeaderboardEntryComponent extends Component Date: Fri, 25 Oct 2024 16:54:51 +0100 Subject: [PATCH 5/6] Update contests-test.js to improve next button assertions and navigation tests. --- tests/acceptance/contests-test.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/contests-test.js b/tests/acceptance/contests-test.js index cb69bc923..d463c9a8b 100644 --- a/tests/acceptance/contests-test.js +++ b/tests/acceptance/contests-test.js @@ -162,13 +162,19 @@ module('Acceptance | contests-test', function (hooks) { assert.strictEqual(currentURL(), '/contests/weekly-1', 'Previous button is disabled when there are no more previous contests'); await contestsPage.headerNavigation.clickOnNextContestButton(); - await contestsPage.headerNavigation.clickOnNextContestButton(); + assert.strictEqual(currentURL(), '/contests/weekly-2', 'Next button works'); + await contestsPage.headerNavigation.clickOnNextContestButton(); assert.strictEqual(currentURL(), '/contests/weekly-3', 'Next button works'); await contestsPage.headerNavigation.clickOnNextContestButton(); + assert.strictEqual(currentURL(), '/contests/weekly-4', 'Next button works'); + + await contestsPage.headerNavigation.clickOnNextContestButton(); + assert.strictEqual(currentURL(), '/contests/weekly-5', 'Next button works'); - assert.strictEqual(currentURL(), '/contests/weekly-3', 'Next button is disabled when the next contest is the second contest from present'); + await contestsPage.headerNavigation.clickOnNextContestButton(); + assert.strictEqual(currentURL(), '/contests/weekly-5', 'Next button is disabled when contest is last'); }); test('prize details navigation buttons work', async function (assert) { @@ -192,7 +198,12 @@ module('Acceptance | contests-test', function (hooks) { assert.strictEqual(currentURL(), '/contests/weekly-3', 'Next button works'); await contestsPage.prizeDetailsNavigation.clickOnNextContestButton(); + assert.strictEqual(currentURL(), '/contests/weekly-4', 'Next button works'); + + await contestsPage.prizeDetailsNavigation.clickOnNextContestButton(); + assert.strictEqual(currentURL(), '/contests/weekly-5', 'Next button works'); - assert.strictEqual(currentURL(), '/contests/weekly-3', 'Next button is disabled when the next contest is the second contest from present'); + await contestsPage.prizeDetailsNavigation.clickOnNextContestButton(); + assert.strictEqual(currentURL(), '/contests/weekly-5', 'Next button is disabled when contest is last'); }); }); From 51314933fe81f3f718c03ae16461cb5584099d85 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Fri, 25 Oct 2024 16:59:29 +0100 Subject: [PATCH 6/6] update nav --- app/components/contest-page/navigation.hbs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/components/contest-page/navigation.hbs b/app/components/contest-page/navigation.hbs index 2bd696d14..02d17069a 100644 --- a/app/components/contest-page/navigation.hbs +++ b/app/components/contest-page/navigation.hbs @@ -4,12 +4,12 @@ @route="contest" @model={{this.previousContest.slug}} @disabled={{this.isPreviousContestDisabled}} - class="flex items-center rounded-l-md border border-r-[0.5px] border-gray-800 hover:border-gray-700 hover:bg-gray-800 px-2 py-1.5 + class="flex items-center rounded-l-md border border-r-[0.5px] border-white/15 hover:border-white/20 hover:bg-white/5 pl-1.5 pr-2 py-1.5 {{if this.isPreviousContestDisabled 'pointer-events-none opacity-50'}}" data-test-previous-contest-button > {{svg-jar "chevron-left" class="w-4 fill-current"}} - Previous + Prev @@ -18,7 +18,7 @@ @route="contest" @model={{this.nextContest.slug}} @disabled={{this.isNextContestDisabled}} - class="flex items-center rounded-r-md border border-l-[0.5px] border-gray-800 hover:border-gray-700 hover:bg-gray-800 px-2 py-1.5 + class="flex items-center rounded-r-md border border-l-[0.5px] border-white/15 hover:border-white/20 hover:bg-white/5 pl-2 pr-1.5 py-1.5 {{if this.isNextContestDisabled 'pointer-events-none opacity-50'}}" data-test-next-contest-button >