-
Notifications
You must be signed in to change notification settings - Fork 8
feat(main): newsletter & top banners #380
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
Open
majahendzel-va
wants to merge
2
commits into
main
Choose a base branch
from
feat/multiple-banner-logic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
import { Slider } from '@angular-love/blog/contracts/banners'; | ||
import { Banners } from '@angular-love/blog/contracts/banners'; | ||
|
||
import { WPBannerDto, WPBannerMediaDto } from './dtos'; | ||
|
||
export const toBanner = ( | ||
dto: WPBannerDto, | ||
mediaDto: WPBannerMediaDto[], | ||
): Slider => { | ||
): Banners => { | ||
return { | ||
slideDisplayTimeMs: +dto.acf.display_time, | ||
slides: | ||
dto.acf.slides?.map((slide) => { | ||
const media = mediaDto.find((media) => media.id === slide.slide_image)!; | ||
return { | ||
url: media.guid.rendered, | ||
alt: media.alt_text, | ||
navigateTo: slide.slide_url, | ||
}; | ||
}) ?? [], | ||
...(dto.acf.is_slider_banner_displayed && { | ||
slider: { | ||
slideDisplayTimeMs: +dto.acf.display_time, | ||
slides: dto.acf.slides.map((slide) => { | ||
const media = mediaDto.find( | ||
(media) => media.id === slide.slide_image_desktop, | ||
)!; | ||
return { | ||
url: media?.guid.rendered, | ||
alt: media?.alt_text, | ||
navigateTo: slide.slide_url, | ||
}; | ||
}), | ||
}, | ||
}), | ||
...(dto.acf.is_top_banner_displayed && { | ||
topBanner: { | ||
url: mediaDto.find( | ||
(media) => media.id === dto.acf.top_banner_image_desktop, | ||
)?.guid.rendered, | ||
alt: mediaDto.find( | ||
(media) => media.id === dto.acf.top_banner_image_desktop, | ||
)?.alt_text, | ||
navigateTo: dto.acf.top_banner_image_url, | ||
}, | ||
}), | ||
...(dto.acf.is_card_banner_displayed && { | ||
cardBanner: { | ||
url: mediaDto.find((media) => media.id === dto.acf.card_banner_image) | ||
?.guid.rendered, | ||
alt: mediaDto.find((media) => media.id === dto.acf.card_banner_image) | ||
?.alt_text, | ||
navigateTo: dto.acf.card_banner_url, | ||
}, | ||
}), | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
export interface Slider { | ||
slideDisplayTimeMs: number; | ||
slides: { | ||
url: string; | ||
alt: string; | ||
url?: string; | ||
alt?: string; | ||
navigateTo: string; | ||
}[]; | ||
} | ||
|
||
export interface TopBanner { | ||
url?: string; | ||
alt?: string; | ||
navigateTo: string; | ||
} | ||
|
||
export interface CardBanner { | ||
url?: string; | ||
alt?: string; | ||
navigateTo: string; | ||
} | ||
|
||
export interface Banners { | ||
slider?: Slider; | ||
topBanner?: TopBanner; | ||
cardBanner?: CardBanner; | ||
} |
6 changes: 3 additions & 3 deletions
6
libs/blog/ad-banner/data-access/src/lib/infrastructure/ad-banner.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { inject, Injectable } from '@angular/core'; | ||
|
||
import { Slider } from '@angular-love/blog/contracts/banners'; | ||
import { Banners } from '@angular-love/blog/contracts/banners'; | ||
import { ConfigService } from '@angular-love/shared/config'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class AdBannerService { | ||
private readonly _apiBaseUrl = inject(ConfigService).get('apiBaseUrl'); | ||
private readonly _http = inject(HttpClient); | ||
|
||
getBannerSlider() { | ||
return this._http.get<Slider>(`${this._apiBaseUrl}/banners`); | ||
getVisibleBanners() { | ||
return this._http.get<Banners>(`${this._apiBaseUrl}/banners`); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
libs/blog/ad-banner/ui/src/lib/newsletter-banner/al-newsletter-banner.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { NgOptimizedImage } from '@angular/common'; | ||
import { ChangeDetectionStrategy, Component, input } from '@angular/core'; | ||
|
||
import { CardBanner } from '@angular-love/blog/contracts/banners'; | ||
|
||
@Component({ | ||
selector: 'al-newsletter-banner', | ||
imports: [NgOptimizedImage], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: ` | ||
<a | ||
class="relative flex h-full items-center" | ||
[href]="cardBanner().navigateTo!" | ||
> | ||
<aside class="absolute h-full w-full overflow-hidden rounded-lg"> | ||
<img | ||
tabindex="0" | ||
role="button" | ||
class="!relative object-cover shadow-inner blur-xl" | ||
[attr.aria-label]="cardBanner()!.alt!" | ||
[alt]="cardBanner().alt!" | ||
[ngSrc]="cardBanner().url!" | ||
fill | ||
priority | ||
/> | ||
</aside> | ||
<aside> | ||
<img | ||
tabindex="0" | ||
role="button" | ||
class="!relative" | ||
[attr.aria-label]="cardBanner().alt!" | ||
[alt]="cardBanner().alt!" | ||
[ngSrc]="cardBanner().url!" | ||
fill | ||
priority | ||
/> | ||
</aside> | ||
</a> | ||
`, | ||
}) | ||
export class AlNewsletterBannerComponent { | ||
readonly cardBanner = input.required<CardBanner>(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we host this data as a json asset? it would be created in the build time as a part of the process in
apps/blog/scripts/build-routes.mjs
. This resource can be received via http client, similarly tolibs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts
.With current implementation we fetch banners from BFF for every available page. Basically it adds an extra request during prerendering. If we prerender 500 pages, it ends up with BFF 1000 request, where 50% is the same banners request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, we can do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pr resolves the issue #415