Skip to content

Commit

Permalink
Merge pull request #31 from adobecom/mwpw-152074-never-expires-cards
Browse files Browse the repository at this point in the history
MWPW-152074 - never expires cards; older than 180 days cards;
  • Loading branch information
Ben-Zahler authored Jun 20, 2024
2 parents 15806ca + 124c76a commit b3ee6a4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
53 changes: 34 additions & 19 deletions eds/blocks/partner-news/PartnerNews.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,22 @@ export class PartnerNews extends PartnerCards {
this.selectedDateFilter = {};
}

async firstUpdated() {
await super.firstUpdated();
this.selectedDateFilter = this.blockData.dateFilter.tags[0];
additionalFirstUpdated() {
const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0);
const startDate = new Date(currentDate);
startDate.setDate(startDate.getDate() - 180);

this.allCards = this.allCards.filter(card => {
const cardDate = new Date(card.cardDate);

if (cardDate >= startDate && cardDate <= currentDate) return true;

const isNeverExpires = card.tags.some((tag) => tag.id === "caas:adobe-partners/collections/news/never-expires");
return isNeverExpires;
})

if (this.blockData.dateFilter) this.selectedDateFilter = this.blockData.dateFilter.tags[0];
}

get pagination() {
Expand Down Expand Up @@ -201,36 +214,38 @@ export class PartnerNews extends PartnerCards {
handleDateFilterAction() {
const { key } = this.selectedDateFilter;
const currentDate = new Date();
const currentMonth = currentDate.getMonth();
const currentYear = currentDate.getFullYear();

if (key === 'current-month') {
this.cards = this.cards.filter(card => {
const cardDate = new Date(card.cardDate);
const cardMonth = cardDate.getMonth();
const cardYear = cardDate.getFullYear();
return cardMonth === currentMonth && cardYear === currentYear;
})
}
else if (key === 'previous-month') {
let previousMonth = currentMonth === 0 ? 11 : currentMonth - 1;
let yearOfPreviousMonth = currentMonth === 0 ? currentYear - 1 : currentYear;
if (key === 'current-month' || key === 'previous-month') {
const currentMonth = currentDate.getMonth();
const currentYear = currentDate.getFullYear();
let targetMonth = currentMonth;
let targetYear = currentYear;

if (key === 'previous-month') {
targetMonth = currentMonth === 0 ? 11 : currentMonth - 1;
targetYear = currentMonth === 0 ? currentYear - 1 : currentYear;
}

this.cards = this.cards.filter(card => {
const cardDate = new Date(card.cardDate);
const cardMonth = cardDate.getMonth();
const cardYear = cardDate.getFullYear();
return cardMonth === previousMonth && cardYear === yearOfPreviousMonth;
return cardMonth === targetMonth && cardYear === targetYear;
})
}
else if (key === 'last-90-days') {

if (key === 'last-90-days') {
currentDate.setHours(0, 0, 0, 0);
const startDate = new Date(currentDate);
startDate.setDate(startDate.getDate() - 90);

this.cards = this.cards.filter(card => {
const cardDate = new Date(card.cardDate);
return cardDate >= startDate && cardDate <= currentDate;
})
} else {
}

if (key === 'show-all') {
return;
}
}
Expand Down
3 changes: 3 additions & 0 deletions eds/components/PartnerCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,12 @@ export class PartnerCards extends LitElement {
if (this.blockData.filters.length) this.initUrlSearchParams();
if (this.blockData.sort.items.length) this.selectedSortOrder = this.blockData.sort.default;
if (this.blockData.cardsPerPage) this.cardsPerPage = this.blockData.cardsPerPage;
this.additionalFirstUpdated();
this.handleActions();
}

additionalFirstUpdated() {}

async fetchData() {
try {
const api = new URL('https://www.adobe.com/chimera-api/collection?originSelection=dx-partners&draft=false&debug=true&flatFile=false&expanded=true');
Expand Down

0 comments on commit b3ee6a4

Please sign in to comment.