This file contains 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
ngOnDestroy(): void { | |
this.renderer.removeChild(this.elementRef.nativeElement, this.styleElement); | |
this.destroy$.next(); | |
this.destroy$.complete(); | |
} | |
ngOnInit() { | |
switchMap((courseId) => | |
this.courseFacade.getCourseCustomStyling(courseId) | |
) |
This file contains 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
editCourseSubmitted(editedCourse: Course) { | |
return this.apollo.mutate<Course>({ | |
mutation: EDIT_COURSE_MUTATION, | |
variables: { | |
id: editedCourse.id, | |
name: editedCourse.name, | |
description: editedCourse.description, | |
} as Course, | |
}); | |
} |
This file contains 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
export function removeFromCache<ReadQueryResponseT>( | |
toRemove: EntityObject, | |
readQuery: DocumentNode, | |
cache: ApolloCache<any>, | |
entityName: keyof ReadQueryResponseT | |
) { | |
const existingEntities = cache.readQuery< | |
Record<keyof ReadQueryResponseT, EntityObject[]> | |
>({ | |
query: readQuery, |
This file contains 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
const getFlattenedParentRouteParams = (route: ActivatedRouteSnapshot) => { | |
if (!route.parent) { | |
return route.params; | |
} | |
const parentRouteParams = getFlattenedParentRouteParams(route.parent); | |
return { | |
...route.params, | |
...parentRouteParams, | |
}; |
This file contains 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
import { Directive, ElementRef, HostListener, OnInit } from '@angular/core'; | |
import 'hammerjs'; | |
/* | |
Preventing clicks after a HammerJS press (long press) event. | |
Inspired from HammerJS ghost click helper: https://gist.github.com/jtangelder/361052976f044200ea17 | |
*/ | |
@Directive({ | |
selector: '[preventGhostClicks]', | |
}) |
This file contains 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
export function createInCache<ReadQueryResponseT>( | |
toCreate: EntityObject, | |
readQuery: DocumentNode, | |
cache: ApolloCache<any>, | |
entityName: keyof ReadQueryResponseT | |
) { | |
const existingEntities = cache.readQuery< | |
Record<keyof ReadQueryResponseT, EntityObject[]> | |
>({ | |
query: readQuery, |
This file contains 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
export interface EntityObject { | |
id: string; | |
} |
This file contains 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
/* | |
For avoiding clicks on mouse up after HammerJS long press. | |
This event is triggered right before (click) to ensure we will not trigger click on long press. | |
*/ | |
preventClickAfterLongPress(event: MouseEvent) { | |
const element = event.target as HTMLElement; | |
// needs to add class directly so it is applied before click event | |
element.classList.add('prevent-pointer-events'); | |
setTimeout(() => { | |
element.classList.remove('prevent-pointer-events'); |
This file contains 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
private getTrustedVideoUrl(url: string): SafeResourceUrl { | |
// Url domains are whitelisted using CSP header | |
// Content-Security-Policy: frame-src <source> <source>; | |
const sanitizedUrl = this.sanitizer.sanitize( | |
SecurityContext.URL, | |
url | |
); | |
return this.sanitizer.bypassSecurityTrustResourceUrl(sanitizedUrl); | |
} |
This file contains 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
private getTrustedVideoUrl(url: string): SafeResourceUrl { | |
// Url domains are whitelisted using CSP header | |
// Content-Security-Policy: frame-src <source> <source>; | |
const sanitizedUrl = this.sanitizer.sanitize( | |
SecurityContext.RESOURCE_URL, | |
url | |
); | |
return this.sanitizer.bypassSecurityTrustResourceUrl(sanitizedUrl); | |
} |