Skip to content

Commit 19841ad

Browse files
fix lame code
1 parent 51cf4ce commit 19841ad

File tree

8 files changed

+80
-45
lines changed

8 files changed

+80
-45
lines changed

src/app/admin/_components/add-post/add-post.component.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@angular/core';
1313
import {
1414
FormBuilder,
15+
FormControl,
1516
FormGroup,
1617
FormsModule,
1718
NgModel,
@@ -67,15 +68,27 @@ export class AddPostComponent implements OnInit {
6768
@Input() postId?: string;
6869
quill = viewChild.required<QuillEditorComponent>('quill');
6970

70-
blogForm: FormGroup<PostForm>;
71-
range: Range | null = null;
72-
7371
viewContainerRef = inject(ViewContainerRef);
7472
dialogService = inject(DynamicDialogService<AddImageForm>);
7573

76-
private fb = inject(FormBuilder);
74+
blogForm: FormGroup<PostForm> = new FormGroup<PostForm>({
75+
title: new FormControl('', {
76+
validators: [Validators.required],
77+
nonNullable: true,
78+
}),
79+
content: new FormControl('', {
80+
validators: [Validators.required],
81+
nonNullable: true,
82+
}),
83+
date: new FormControl<Date | null>(null),
84+
description: new FormControl<string | null>(null),
85+
isDraft: new FormControl(false, { nonNullable: true }),
86+
});
87+
range: Range | null = null;
88+
7789
private apiService = inject(AdminApiService);
7890

91+
<<<<<<< HEAD
7992
constructor() {
8093
this.blogForm = this.fb.group({
8194
title: ['', [Validators.required]],
@@ -92,17 +105,21 @@ export class AddPostComponent implements OnInit {
92105
=======
93106
});
94107
>>>>>>> ab739b9 (nothing special)
108+
=======
109+
ngOnInit(): void {
110+
this.loadPostIfIdExists();
111+
this.initializeQuill();
112+
>>>>>>> cbcd61c (fix lame code)
95113
}
96114

97-
ngOnInit(): void {
115+
private loadPostIfIdExists(): void {
98116
if (this.postId) {
99117
this.apiService.getPostById(this.postId).subscribe((post) => {
100118
if (post) {
101119
this.blogForm.patchValue(post);
102120
}
103121
});
104122
}
105-
this.initializeQuill();
106123
}
107124

108125
async initializeQuill() {

src/app/app.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ import {
33
ViewContainerRef,
44
afterNextRender,
55
inject,
6-
OnInit,
76
} from '@angular/core';
87
import { RouterOutlet } from '@angular/router';
98
import { CookieConsentService } from './shared/cookie-consent/cookie-consent.service';
10-
import { SupabaseClient } from '@supabase/supabase-js';
11-
import { SupabaseService } from './services/supabase.service';
129

1310
@Component({
1411
selector: 'app-root',
@@ -18,13 +15,16 @@ import { SupabaseService } from './services/supabase.service';
1815
styleUrl: './app.component.scss',
1916
})
2017
export class AppComponent {
21-
// cookieConsentService = inject(CookieConsentService);
22-
// viewContainerRef = inject(ViewContainerRef);
18+
cookieConsentService = inject(CookieConsentService);
19+
viewContainerRef = inject(ViewContainerRef);
2320

2421
constructor() {
25-
console.log('AppComponent');
26-
// afterNextRender(() =>
27-
// this.cookieConsentService.showCookieConsent(this.viewContainerRef),
28-
// );
22+
this.showCookieConsent();
23+
}
24+
25+
private showCookieConsent() {
26+
afterNextRender(() =>
27+
this.cookieConsentService.showCookieConsent(this.viewContainerRef),
28+
);
2929
}
3030
}

src/app/reader/_components/main-page/post/add-comment/add-comment.component.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
FormBuilder,
1010
Validators,
1111
ReactiveFormsModule,
12+
FormControl,
1213
} from '@angular/forms';
1314
import { ReaderApiService } from '../../../../_services/reader-api.service';
1415
import { CommentsStore } from '../comments/comments.store';
@@ -25,17 +26,15 @@ import { Comment } from '../../../../../types/supabase';
2526
})
2627
export class AddCommentComponent {
2728
@Input() postId!: string;
28-
commentForm: FormGroup;
2929

30-
private fb = inject(FormBuilder);
31-
private apiService = inject(ReaderApiService);
32-
private commentsStore = inject(CommentsStore);
30+
commentForm: FormGroup = new FormGroup({
31+
content: new FormControl<string>('', {
32+
validators: [Validators.required],
33+
nonNullable: true,
34+
}),
35+
});
3336

34-
constructor() {
35-
this.commentForm = this.fb.group({
36-
content: ['', [Validators.required]],
37-
});
38-
}
37+
private commentsStore = inject(CommentsStore);
3938

4039
onSubmit(): void {
4140
if (this.commentForm.valid) {

src/app/reader/_components/main-page/post/post.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,27 @@ export class PostComponent implements OnInit {
3535
postStore = inject(PostStore);
3636

3737
post: Signal<Post | null> = this.postStore.post;
38+
date: string = '';
3839

3940
private dialogService = inject(DynamicDialogService);
4041
private viewContainerRef = inject(ViewContainerRef);
4142

42-
date: string = '';
43-
4443
constructor() {
4544
this.addEventsForOpenModalWithCode();
4645
}
4746

4847
ngOnInit() {
49-
this.postStore.getPost(this.id());
48+
this.loadPost();
5049
}
5150

5251
goBack(): void {
5352
this.router.navigate(['/posts']);
5453
}
5554

55+
private loadPost(): void {
56+
this.postStore.getPost(this.id());
57+
}
58+
5659
private showCodeModal(event: Event) {
5760
const preElement = event.currentTarget as HTMLElement;
5861
const codeElement = preElement.querySelector('code');
@@ -73,6 +76,7 @@ export class PostComponent implements OnInit {
7376

7477
private addEventsForOpenModalWithCode() {
7578
afterNextRender(() => {
79+
//TODO: Move to the service
7680
const processedNodes = new Set<Node>();
7781

7882
const observer = new MutationObserver((mutations) => {

src/app/reader/_components/main-page/posts-list/posts-list.component.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,12 @@ export class PostsListComponent implements OnInit {
4545
initialScroll = 2;
4646

4747
constructor() {
48-
this.scrollProgress.set(this.initialScroll);
49-
afterNextRender(() => {
50-
this.scroll()?.nativeElement.addEventListener(
51-
'scroll',
52-
this.onScroll.bind(this),
53-
);
54-
});
48+
this.initializeScrolling();
5549
}
5650

57-
//TODO: FIX HACK FOR PRERENDERING
5851
ngOnInit() {
59-
setTimeout(() => {}, 0);
52+
//TODO: FIX HACK FOR PRERENDERING
53+
this.applyPrerenderingHack();
6054
}
6155

6256
onScroll(event: Event) {
@@ -69,4 +63,18 @@ export class PostsListComponent implements OnInit {
6963

7064
this.scrollProgress.set(scrollPercentage);
7165
}
66+
67+
private applyPrerenderingHack(): void {
68+
setTimeout(() => {}, 0);
69+
}
70+
71+
private initializeScrolling(): void {
72+
this.scrollProgress.set(this.initialScroll);
73+
afterNextRender(() => {
74+
this.scroll()?.nativeElement.addEventListener(
75+
'scroll',
76+
this.onScroll.bind(this),
77+
);
78+
});
79+
}
7280
}

src/app/services/supabase.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { environment } from '../../environments/environment';
1313
providedIn: 'root',
1414
})
1515
export class SupabaseService {
16-
private readonly supabase: SupabaseClient;
17-
public session: AuthSession | null = null;
16+
private supabase: SupabaseClient;
1817
private readonly ngZone = inject(NgZone);
18+
public session: AuthSession | null = null;
1919

2020
constructor() {
2121
this.supabase = this.ngZone.runOutsideAngular(() =>

src/app/shared/dynamic-dialog/dynamic-dialog.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ export class DynamicDialogComponent<C = unknown> implements OnInit {
3838
ModalCloseStatusEnum = ModalCloseStatusEnum;
3939

4040
ngOnInit(): void {
41-
if (this.divEl() && this.component) {
42-
this.componentRef = this.divEl().createComponent(this.component);
43-
}
41+
this.createDynamicComponent();
4442
}
4543

4644
closeDialog(
@@ -57,4 +55,10 @@ export class DynamicDialogComponent<C = unknown> implements OnInit {
5755
onOverlayClick($event: MouseEvent) {
5856
console.log('Overlay clicked', $event);
5957
}
58+
59+
private createDynamicComponent(): void {
60+
if (this.divEl() && this.component) {
61+
this.componentRef = this.divEl().createComponent(this.component);
62+
}
63+
}
6064
}

src/app/shared/navbar/navbar.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ export class NavbarComponent implements AfterViewInit {
3434

3535
private dynamicDialogService = inject(DynamicDialogService);
3636
private viewContainerRef = inject(ViewContainerRef);
37-
private supabaseService = inject(SupabaseService);
3837

3938
constructor() {
40-
afterNextRender(() => {
41-
this.navHeight.set(this.navbar()?.nativeElement.scrollHeight ?? 0);
42-
});
39+
this.initializeNavHeight();
4340
}
4441

4542
ngAfterViewInit() {}
@@ -66,6 +63,12 @@ export class NavbarComponent implements AfterViewInit {
6663
}
6764
}
6865

66+
private initializeNavHeight(): void {
67+
afterNextRender(() => {
68+
this.navHeight.set(this.navbar()?.nativeElement.scrollHeight ?? 0);
69+
});
70+
}
71+
6972
@HostListener('window:scroll', [])
7073
onWindowScroll() {
7174
this.isScrolled = window.scrollY > 0;

0 commit comments

Comments
 (0)