Skip to content

Commit

Permalink
fix(News): Only show Discourse news on home page if discourse_url is …
Browse files Browse the repository at this point in the history
…set (#1082)
  • Loading branch information
geoffreykwan authored Mar 7, 2023
1 parent ea21cbb commit 8e678ee
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/app/domain/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export class Config {
currentTime: number;
wiseHostname?: string;
wise4Hostname?: string;
discourseNewsCategory?: string;
discourseURL?: string;
}
6 changes: 3 additions & 3 deletions src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
Integrated science learning and teaching with technology
</div>
</ng-template>
<ng-template #sideTemplate>
<ng-template #sideTemplate *ngIf="isDiscourseNewsAvailable">
<discourse-latest-news
[@bounceIn]="{ value: '*', params: { duration: '1.25s', delay: '3500ms' } }"
baseUrl="https://wise-discuss.berkeley.edu"
category="c/news-announcements/7"
[baseUrl]="discourseUrl"
[category]="discourseNewsCategory"
queryString="order=latest"
>
</discourse-latest-news>
Expand Down
19 changes: 12 additions & 7 deletions src/app/home/home.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { HomeComponent } from './home.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ConfigService } from '../services/config.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('HomeComponent', () => {
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [HomeComponent],
imports: [],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [HomeComponent],
imports: [HttpClientTestingModule],
providers: [ConfigService],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
})
);

beforeEach(() => {
fixture = TestBed.createComponent(HomeComponent);
Expand Down
22 changes: 20 additions & 2 deletions src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit, SecurityContext } from '@angular/core';
import { bounceIn, flipInX, flipInY, jackInTheBox, rotateIn, zoomIn } from '../animations';
import { DomSanitizer } from '@angular/platform-browser';
import { ConfigService } from '../services/config.service';
import { Config } from '../domain/config';

@Component({
selector: 'app-home',
Expand All @@ -9,6 +11,9 @@ import { DomSanitizer } from '@angular/platform-browser';
animations: [bounceIn, flipInX, flipInY, jackInTheBox, rotateIn, zoomIn]
})
export class HomeComponent implements OnInit {
discourseNewsCategory: string;
discourseUrl: string;
isDiscourseNewsAvailable: boolean = false;
loaded: boolean = false;
hero = {
imgSrc: 'assets/img/wise-students-hero.jpg',
Expand Down Expand Up @@ -87,7 +92,20 @@ export class HomeComponent implements OnInit {
}
];

constructor(private sanitizer: DomSanitizer) {}
constructor(private configService: ConfigService, private sanitizer: DomSanitizer) {}

ngOnInit() {}
ngOnInit() {
this.configService.getConfig().subscribe((config: Config) => {
if (config != null) {
this.discourseUrl = this.configService.getDiscourseURL();
this.discourseNewsCategory = this.configService.getDiscourseNewsCategory();
this.isDiscourseNewsAvailable =
this.isSet(this.discourseUrl) && this.isSet(this.discourseNewsCategory);
}
});
}

private isSet(str: string): boolean {
return str != null && str !== '';
}
}
4 changes: 4 additions & 0 deletions src/app/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class ConfigService {
return this.config$.getValue().discourseURL;
}

getDiscourseNewsCategory() {
return this.config$.getValue().discourseNewsCategory;
}

getGoogleAnalyticsId() {
return this.config$.getValue().googleAnalyticsId;
}
Expand Down

0 comments on commit 8e678ee

Please sign in to comment.