-
Notifications
You must be signed in to change notification settings - Fork 16
[ENG-8777] Add scheduled banner #371
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
bp-cos
merged 6 commits into
CenterForOpenScience:develop
from
adlius:add-scheduled-banner
Sep 13, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c6c7bd2
feat(banner): Add services and models for scheduled banners
adlius f3fe12f
feat(osf): Add scheduled banner
adlius 7c87eba
feat(banner): Fix merge conflicts
adlius 6372e53
feat(banner): CR followup
adlius 1f5c516
feat(banners): CR followup again
adlius 90fe2e2
feat(banners): Use primeflex classesl; remove scss file
adlius 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
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
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
Empty file.
22 changes: 22 additions & 0 deletions
22
src/app/shared/components/scheduled-banner/scheduled-banner.component.html
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,22 @@ | ||
@if (this.shouldShowBanner()) { | ||
<div | ||
[style.background-color]="this.currentBanner()?.color" | ||
class="flex w-full justify-content-center align-items flex-row" | ||
> | ||
<a [href]="this.currentBanner()?.link" target="_blank" rel="noopener noreferrer"> | ||
@if (this.isMobile()) { | ||
<img | ||
class="block w-full" | ||
[src]="this.currentBanner()?.mobilePhoto" | ||
[alt]="this.currentBanner()?.mobileAltText" | ||
/> | ||
} @else { | ||
<img | ||
class="block w-full" | ||
[src]="this.currentBanner()?.defaultPhoto" | ||
[alt]="this.currentBanner()?.defaultAltText" | ||
/> | ||
} | ||
</a> | ||
</div> | ||
} |
33 changes: 33 additions & 0 deletions
33
src/app/shared/components/scheduled-banner/scheduled-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,33 @@ | ||
import { select, Store } from '@ngxs/store'; | ||
|
||
import { ChangeDetectionStrategy, Component, computed, inject, OnInit } from '@angular/core'; | ||
import { toSignal } from '@angular/core/rxjs-interop'; | ||
|
||
import { IS_XSMALL } from '@osf/shared/helpers'; | ||
import { BannersSelector, FetchCurrentScheduledBanner } from '@osf/shared/stores/banners'; | ||
|
||
@Component({ | ||
selector: 'osf-scheduled-banner', | ||
templateUrl: './scheduled-banner.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ScheduledBannerComponent implements OnInit { | ||
private readonly store = inject(Store); | ||
currentBanner = select(BannersSelector.getCurrentBanner); | ||
isMobile = toSignal(inject(IS_XSMALL)); | ||
|
||
ngOnInit() { | ||
this.store.dispatch(new FetchCurrentScheduledBanner()); | ||
} | ||
|
||
shouldShowBanner = computed(() => { | ||
const banner = this.currentBanner(); | ||
if (banner) { | ||
const bannerStartTime = banner.startDate; | ||
const bannderEndTime = banner.endDate; | ||
const currentTime = new Date(); | ||
return bannerStartTime < currentTime && bannderEndTime > currentTime; | ||
} | ||
return false; | ||
}); | ||
} |
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,20 @@ | ||
import { BannerJsonApi } from '../models/banner.json-api.model'; | ||
import { BannerModel } from '../models/banner.model'; | ||
|
||
export class BannerMapper { | ||
static fromResponse(response: BannerJsonApi): BannerModel { | ||
return { | ||
id: response.id, | ||
startDate: new Date(response.attributes.start_date), | ||
endDate: new Date(response.attributes.end_date), | ||
color: response.attributes.color, | ||
license: response.attributes.license, | ||
name: response.attributes.name, | ||
defaultAltText: response.attributes.default_alt_text, | ||
mobileAltText: response.attributes.mobile_alt_text, | ||
defaultPhoto: response.links.default_photo, | ||
mobilePhoto: response.links.mobile_photo, | ||
link: response.attributes.link, | ||
}; | ||
} | ||
} |
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,18 @@ | ||
export interface BannerJsonApi { | ||
id: string; | ||
attributes: { | ||
start_date: string; | ||
end_date: string; | ||
color: string; | ||
license: string; | ||
name: string; | ||
default_alt_text: string; | ||
mobile_alt_text: string; | ||
link: string; | ||
}; | ||
links: { | ||
default_photo: string; | ||
mobile_photo: string; | ||
}; | ||
type: string; | ||
} |
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,13 @@ | ||
export interface BannerModel { | ||
id: string; | ||
startDate: Date; | ||
endDate: Date; | ||
color: string; | ||
license: string; | ||
name: string; | ||
defaultAltText: string; | ||
mobileAltText: string; | ||
defaultPhoto: string; | ||
mobilePhoto: string; | ||
link: string; | ||
} |
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,38 @@ | ||
import { map, Observable } from 'rxjs'; | ||
|
||
import { inject, Injectable } from '@angular/core'; | ||
|
||
import { JsonApiResponse } from '@shared/models'; | ||
import { JsonApiService } from '@shared/services'; | ||
|
||
import { BannerMapper } from '../mappers/banner.mapper'; | ||
import { BannerJsonApi } from '../models/banner.json-api.model'; | ||
import { BannerModel } from '../models/banner.model'; | ||
|
||
import { environment } from 'src/environments/environment'; | ||
|
||
/** | ||
* Service for fetching scheduled banners from OSF API v2 | ||
*/ | ||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class BannersService { | ||
/** | ||
* Injected instance of the JSON:API service used for making API requests. | ||
* This service handles standardized JSON:API request and response formatting. | ||
*/ | ||
private jsonApiService = inject(JsonApiService); | ||
|
||
/** | ||
* Retrieves the current banner | ||
* | ||
* @returns Observable emitting a Banner object. | ||
* | ||
*/ | ||
fetchCurrentBanner(): Observable<BannerModel> { | ||
return this.jsonApiService | ||
.get<JsonApiResponse<BannerJsonApi, null>>(`${environment.apiDomainUrl}/_/banners/current`) | ||
.pipe(map((response) => BannerMapper.fromResponse(response.data))); | ||
} | ||
} |
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,3 @@ | ||
export class FetchCurrentScheduledBanner { | ||
static readonly type = '[Banners] Fetch Current Scheduled Banner'; | ||
} |
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,14 @@ | ||
import { BannerModel } from '@osf/shared/models/banner.model'; | ||
import { AsyncStateModel } from '@shared/models/store'; | ||
|
||
export interface BannersStateModel { | ||
currentBanner: AsyncStateModel<BannerModel | null>; | ||
} | ||
|
||
export const BANNERS_DEFAULTS: BannersStateModel = { | ||
currentBanner: { | ||
data: null, | ||
isLoading: false, | ||
error: null, | ||
}, | ||
}; |
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,16 @@ | ||
import { Selector } from '@ngxs/store'; | ||
|
||
import { BannersStateModel } from './banners.model'; | ||
import { BannersState } from './banners.state'; | ||
|
||
export class BannersSelector { | ||
@Selector([BannersState]) | ||
static getCurrentBanner(state: BannersStateModel) { | ||
return state.currentBanner.data; | ||
} | ||
|
||
@Selector([BannersState]) | ||
static getCurrentBannerIsLoading(state: BannersStateModel) { | ||
return state.currentBanner.isLoading; | ||
} | ||
} |
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,43 @@ | ||
import { Action, State, StateContext } from '@ngxs/store'; | ||
|
||
import { catchError, tap } from 'rxjs'; | ||
|
||
import { inject, Injectable } from '@angular/core'; | ||
|
||
import { handleSectionError } from '@osf/shared/helpers'; | ||
import { BannersService } from '@osf/shared/services/banners.service'; | ||
|
||
import { FetchCurrentScheduledBanner } from './banners.actions'; | ||
import { BANNERS_DEFAULTS, BannersStateModel } from './banners.model'; | ||
|
||
@State<BannersStateModel>({ | ||
name: 'banners', | ||
defaults: BANNERS_DEFAULTS, | ||
}) | ||
@Injectable() | ||
export class BannersState { | ||
bannersService = inject(BannersService); | ||
|
||
@Action(FetchCurrentScheduledBanner) | ||
fetchCurrentScheduledBanner(ctx: StateContext<BannersStateModel>) { | ||
const state = ctx.getState(); | ||
ctx.patchState({ | ||
currentBanner: { | ||
...state.currentBanner, | ||
isLoading: true, | ||
}, | ||
}); | ||
return this.bannersService.fetchCurrentBanner().pipe( | ||
tap((newValue) => { | ||
ctx.patchState({ | ||
currentBanner: { | ||
data: newValue, | ||
isLoading: false, | ||
error: null, | ||
}, | ||
}); | ||
catchError((error) => handleSectionError(ctx, 'currentBanner', error)); | ||
}) | ||
); | ||
} | ||
} |
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,4 @@ | ||
export * from './banners.actions'; | ||
export * from './banners.model'; | ||
export * from './banners.selectors'; | ||
export * from './banners.state'; |
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.
Uh oh!
There was an error while loading. Please reload this page.