Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwind committed Nov 12, 2023
1 parent 175a9fc commit bfffc3c
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 111 deletions.
29 changes: 20 additions & 9 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
inject,
OnInit,
} from '@angular/core';
import { NavigationEnd, NavigationStart, Router } from '@angular/router';
import { PlatformService } from 'src/app/site-common/platform.service';
import { environment } from '../environments/environment';
Expand All @@ -7,18 +12,20 @@ import { SiteMetaService } from './site-common/site-meta.service';
import { TrackService } from './site-common/track.service';
import { filter, pairwise, startWith } from 'rxjs';

declare let gtag: Function;
declare const gtag: (
command: string,
action: string,
config: { page_path: string }
) => void;

@Component({
standalone: true,
selector: 'app-root',
imports: [
LayoutComponent,
],
imports: [LayoutComponent],
template: `<app-layout></app-layout>`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {
export class AppComponent implements OnInit {
private router = inject(Router);
private platformService = inject(PlatformService);
private siteMetaService = inject(SiteMetaService);
Expand All @@ -42,10 +49,14 @@ export class AppComponent {
startWith(null),
pairwise()
)
.subscribe((events: [any, any]) => {
.subscribe((events) => {
if (!this.platformService.isServer && environment.production) {
this.trackService.sendTrack(events[0]?.url || '');
gtag('event', 'page_view', { page_path: events[1].url });
this.trackService.sendTrack(
(events[0] as NavigationEnd | null)?.url || ''
);
gtag('event', 'page_view', {
page_path: (events[1] as NavigationEnd | null)?.url || '',
});
}
});
}
Expand Down
6 changes: 1 addition & 5 deletions src/app/blog/blog-archives/blog-archives-posts-resolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable, inject } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { PostMetaWithSlug } from '../../site-common/post-meta.interface';
import { SitePostService } from '../../site-common/site-post.service';
Expand All @@ -10,10 +9,7 @@ import { SitePostService } from '../../site-common/site-post.service';
export class BlogArchivesPostsResolve {
private sitePostService = inject(SitePostService);

resolve(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<PostMetaWithSlug[]> {
resolve(): Observable<PostMetaWithSlug[]> {
return this.sitePostService.postsMetaWithSlugAndSortDesc$;
}
}
2 changes: 1 addition & 1 deletion src/app/blog/blog-archives/blog-archives.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class BlogArchivesComponent {
return pagePosts.reduce((prev, curr) => {
const year = curr.date.slice(0, 4);

let yearPosts = prev.find((item) => item.year === year);
const yearPosts = prev.find((item) => item.year === year);
if (!yearPosts) {
prev.push({
year,
Expand Down
4 changes: 2 additions & 2 deletions src/app/blog/blog-categories/blog-categories-posts-resolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, inject } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { ActivatedRouteSnapshot } from '@angular/router';
import { descend, prop, sortWith } from 'ramda';
import { Observable, map } from 'rxjs';
import { PostMetaWithSlug } from '../../site-common/post-meta.interface';
Expand All @@ -12,7 +12,7 @@ import { findPosts } from '../find-posts';
export class BlogCategoriesPostsResolve {
private sitePostService = inject(SitePostService);

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<PostMetaWithSlug[]> {
resolve(route: ActivatedRouteSnapshot): Observable<PostMetaWithSlug[]> {
const categorySlug = route.paramMap.get('category-slug') as string;

return this.sitePostService.categoriesAndPosts$
Expand Down
3 changes: 1 addition & 2 deletions src/app/blog/blog-categories/blog-categories-resolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable, inject } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { PostMetaWithSlug } from '../../site-common/post-meta.interface';
import { SitePostService } from '../../site-common/site-post.service';
Expand All @@ -10,7 +9,7 @@ import { SitePostService } from '../../site-common/site-post.service';
export class BlogCategoriesResolve {
private sitePostService = inject(SitePostService);

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<{ [key:string] :PostMetaWithSlug[]}> {
resolve(): Observable<{ [key:string] :PostMetaWithSlug[]}> {
return this.sitePostService.categoriesAndPosts$;
}
}
4 changes: 2 additions & 2 deletions src/app/blog/blog-posts/blog-post/blog-content-resolve.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Injectable, TransferState, inject, makeStateKey } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { ActivatedRouteSnapshot } from '@angular/router';
import { Observable, catchError, map, of, tap, timeout } from 'rxjs';
import { MarkdownMeta, parseMarkdownMeta } from 'site-utils';
import { environment } from '../../../../environments/environment';
Expand All @@ -14,7 +14,7 @@ export class BlogContentResolve {
private state = inject(TransferState);
private platformService = inject(PlatformService);

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<MarkdownMeta> {
resolve(route: ActivatedRouteSnapshot): Observable<MarkdownMeta> {
return this.getMarkdownContent(route.paramMap.get('slug') as string);
}

Expand Down
28 changes: 15 additions & 13 deletions src/app/blog/blog-posts/blog-post/blog-post-toc.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
OnDestroy,
TransferState,
inject,
makeStateKey
makeStateKey,
} from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { Observable, ReplaySubject, map, startWith, switchMap } from 'rxjs';
Expand Down Expand Up @@ -85,7 +85,7 @@ const HEADINGS_CACHE_KEY = makeStateKey<Heading[]>('POST_TOC');
}`,
standalone: true,
imports: [],
changeDetection: ChangeDetectionStrategy.OnPush
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BlogPostTocComponent implements OnDestroy {
private transferState = inject(TransferState);
Expand Down Expand Up @@ -170,7 +170,7 @@ export class BlogPostTocComponent implements OnDestroy {
const containerElement = element.closest(
'.mat-drawer-content.main-content'
);
let options = {
const options = {
root: containerElement,
rootMargin: '0px',
threshold: 1.0,
Expand Down Expand Up @@ -213,17 +213,19 @@ export class BlogPostTocComponent implements OnDestroy {
}

private getTocHeadings(element: HTMLElement) {
let result: any[] = [];
const result: Array<{
text: string | null;
level: number;
element: Element | null;
active: boolean;
}> = [];
element.querySelectorAll('h1,h2,h3,h4,h5,h6').forEach((head) => {
result = [
...result,
{
text: head.textContent,
level: +head.tagName.replace(/h(.)/i, '$1'),
element: this.platformService.isServer ? null : head,
active: false,
},
];
result.push({
text: head.textContent,
level: +head.tagName.replace(/h(.)/i, '$1'),
element: this.platformService.isServer ? null : head,
active: false,
});
});
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/blog/blog-posts/blog-post/blog-post.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MatDividerModule } from '@angular/material/divider';
import { MatIconModule } from '@angular/material/icon';
import { MatTooltipModule } from '@angular/material/tooltip';
import { DomSanitizer } from '@angular/platform-browser';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { RouterLink } from '@angular/router';
import { MarkdownMeta } from 'site-utils';
import { getRouteData } from 'src/app/site-common/route-utils';
import { findMainContentContainer, scrollTo } from '../../../../utils';
Expand Down
7 changes: 2 additions & 5 deletions src/app/blog/blog-tags/blog-tags-posts-resolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, inject } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { ActivatedRouteSnapshot } from '@angular/router';
import { descend, prop, sortWith } from 'ramda';
import { Observable, map } from 'rxjs';
import { PostMetaWithSlug } from '../../site-common/post-meta.interface';
Expand All @@ -12,10 +12,7 @@ import { findPosts } from '../find-posts';
export class BlogTagsPostsResolve {
private sitePostService = inject(SitePostService);

resolve(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<PostMetaWithSlug[]> {
resolve(route: ActivatedRouteSnapshot): Observable<PostMetaWithSlug[]> {
const tagSlug = route.paramMap.get('tag-slug') as string;

return this.sitePostService.tagsAndPosts$.pipe(
Expand Down
6 changes: 1 addition & 5 deletions src/app/blog/blog-tags/blog-tags-resolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable, inject } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { PostMetaWithSlug } from '../../site-common/post-meta.interface';
import { SitePostService } from '../../site-common/site-post.service';
Expand All @@ -10,10 +9,7 @@ import { SitePostService } from '../../site-common/site-post.service';
export class BlogTagsResolve {
private sitePostService = inject(SitePostService);

resolve(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<{ [key: string]: PostMetaWithSlug[] }> {
resolve(): Observable<{ [key: string]: PostMetaWithSlug[] }> {
return this.sitePostService.tagsAndPosts$;
}
}
2 changes: 1 addition & 1 deletion src/app/layout/layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class LayoutComponent implements OnInit {
ngOnInit() {
this.router.events
.pipe(filter((event) => event instanceof NavigationStart))
.subscribe((url) => {
.subscribe(() => {
if (this.matDrawerContent) {
this.matDrawerContent.scrollTo({ top: 0, left: 0 });
this.cdr.detectChanges();
Expand Down
6 changes: 3 additions & 3 deletions src/app/site-common/blog-post-subtitle.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { RouterLink } from '@angular/router';
import { MarkdownMeta } from 'site-utils';
import { PostMeta } from './post-meta.interface';
import { SlugifyPipe } from './slugify.pipe';
import { RouterLink } from '@angular/router';
import { MatIconModule } from '@angular/material/icon';

@Component({
selector: 'app-blog-post-subtitle',
Expand Down
2 changes: 1 addition & 1 deletion src/app/site-common/pagination.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { RouterLink } from '@angular/router';
import { MatTooltipModule } from '@angular/material/tooltip';
Expand Down
2 changes: 1 addition & 1 deletion src/app/site-common/platform.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { isPlatformServer } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID, inject } from '@angular/core';
import { Injectable, PLATFORM_ID, inject } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { map, shareReplay } from 'rxjs';

Expand Down
2 changes: 2 additions & 0 deletions src/app/site-common/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const getRouteParam = <T>(getFn: (paramMap: ParamMap, index?: number) =>
const param$ = route.paramMap.pipe(
map(getFn)
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return toSignal<T>(param$, { initialValue: initialValue as any }) as Signal<T>;
};

Expand All @@ -16,5 +17,6 @@ export const getRouteData = <T>(getFn: (data: Data, index?: number) => T, initia
const data$ = route.data.pipe(
map(getFn)
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return toSignal<T>(data$, { initialValue: initialValue as any })as Signal<T>;
}
Loading

0 comments on commit bfffc3c

Please sign in to comment.