Skip to content

Commit

Permalink
sorting ad pools list (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
hichri-louay authored Oct 5, 2023
1 parent 059f184 commit 48e5785
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/app/campaigns/ad-pools/ad-pools.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,35 @@ export class AdPoolsComponent implements OnInit, OnDestroy {
draftsArray.sort((a: any, b: any) => {
return <any>new Date(b.createdAt) - <any>new Date(a.createdAt);
});
campaignsArray.sort((a:any, b:any) => {
const typeOrder:{ [key: string]: number } = { applyOwned: 1, applyNotOwned: 1, finished: 3 };
const typeA = a.type.toLowerCase();
const typeB = b.type.toLowerCase();

if (typeA === "apply" && a.isOwnedByUser) {
if (typeB === "apply" && b.isOwnedByUser) {
return 0; // Both apply and owned by user, order doesn't matter.
}
return -1; // a comes first, as it's apply and owned by user.
} else if (typeA === "apply" && !a.isOwnedByUser) {
if (typeB === "apply" && !b.isOwnedByUser) {
return 0; // Both apply and not owned by user, order doesn't matter.
}
return 1; // b comes first, as a is apply and not owned by user.
} else if (typeA === "finished" && typeB !== "finished") {
return 1; // "finished" type should come after all other types.
} else if (typeA !== "finished" && typeB === "finished") {
return -1; // "finished" type should come after all other types.
}

return 0;


})
const newCampaignsArray = concat(draftsArray, campaignsArray);
this.campaignsList = newCampaignsArray;
this.campaignsList2 = newCampaignsArray;
console.log({newCampaignsArray})
this.campaignsList?.forEach((element: Campaign) => {
if (
['SATTPOLYGON', 'SATTBEP20', 'SATTBTT'].includes(
Expand Down

0 comments on commit 48e5785

Please sign in to comment.