Skip to content

Commit 8fe3cca

Browse files
fix(sidebar layout): going back to using layout component to avoid issues with primeng sidebar
1 parent ec547ac commit 8fe3cca

11 files changed

+107
-50
lines changed

src/app/app.component.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
<app-header />
2-
<div class="content">
3-
<router-outlet />
4-
</div>
5-
<app-footer />
1+
<router-outlet />
62

73
@if (showScrollButton) {
84
<p-button class="scroll-btn" (click)="scrollToTop()" icon="pi pi-angle-up" [rounded]="true" size="small"></p-button>

src/app/app.component.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
.content {
2-
display: flex;
3-
align-items: center;
4-
justify-content: center;
5-
min-height: 74vh;
6-
width: 100%;
7-
}
8-
91
.scroll-btn {
102
position: fixed;
113
bottom: 1rem;

src/app/app.routes.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
import { Routes } from '@angular/router';
2-
import { PostDetailsComponent } from './components/post-details/post-details.component';
3-
import { PostsComponent } from './components/posts/posts.component';
4-
import { SeriesComponent } from './components/series/series.component';
1+
import { Routes } from "@angular/router";
2+
import { PostDetailsComponent } from "./components/post-details/post-details.component";
3+
import { PostsComponent } from "./components/posts/posts.component";
4+
import { SeriesComponent } from "./components/series/series.component";
5+
import { LayoutComponent } from "./components/layout/layout.component";
56

67
export const routes: Routes = [
7-
{
8-
path: '',
9-
component: PostsComponent
10-
},
11-
{
12-
path: 'series/:slug',
13-
component: SeriesComponent
14-
},
15-
{
16-
path: 'post/:postSlug',
17-
component: PostDetailsComponent
18-
},
19-
{
20-
path: '**',
21-
redirectTo: ''
22-
}
8+
{
9+
path: "",
10+
component: LayoutComponent,
11+
children: [
12+
{
13+
path: "",
14+
component: PostsComponent,
15+
},
16+
{
17+
path: "series/:slug",
18+
component: SeriesComponent,
19+
},
20+
],
21+
},
22+
{
23+
path: "post/:postSlug",
24+
component: PostDetailsComponent,
25+
},
26+
{
27+
path: "**",
28+
redirectTo: "",
29+
},
2330
];

src/app/components/header/header.component.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@
22
<div class="toolbar-row first">
33
<div class="p-toolbar-group-start">
44
<a routerLink="/" class="blog-title">
5-
@if (showMainHeader) {
65
<img class="logo-image" src="{{blogImage}}" alt="logo" />
7-
} @else {
8-
<app-sidenav></app-sidenav>
9-
}
106
<h1>{{blogName}}</h1>
117
</a>
128
</div>
139

1410
<div class="p-toolbar-group-end">
1511
<div class="controls">
16-
@if (showMainHeader) {
1712
<app-search-dialog [blogId]="blogId"></app-search-dialog>
1813
<app-settings-dialog></app-settings-dialog>
19-
}
2014
<p-inputSwitch [(ngModel)]="checked" (click)="onThemeChange(checked ? 'dark' : 'light')"
2115
id="theme-switch"></p-inputSwitch>
2216
</div>
2317
</div>
2418
</div>
2519

26-
@if (showMainHeader) {
2720
<div class="toolbar-row second">
2821
<div class="p-toolbar-group-start">
2922
<div class="social">
@@ -58,6 +51,5 @@ <h1>{{blogName}}</h1>
5851
}
5952
</div>
6053
</div>
61-
}
6254

6355
</p-toolbar>

src/app/components/header/header.component.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ import { InputSwitchModule } from "primeng/inputswitch";
1515
import { DialogModule } from "primeng/dialog";
1616
import { SettingsDialogComponent } from "../../partials/settings-dialog/settings-dialog.component";
1717
import { FollowDialogComponent } from "../../partials/follow-dialog/follow-dialog.component";
18-
import { SidenavComponent } from "../sidenav/sidenav.component";
1918

2019
@Component({
2120
selector: "app-header",
2221
standalone: true,
2322
imports: [
2423
AsyncPipe,
25-
SidenavComponent,
2624
SearchDialogComponent,
2725
SettingsDialogComponent,
2826
FollowDialogComponent,
@@ -38,7 +36,6 @@ import { SidenavComponent } from "../sidenav/sidenav.component";
3836
styleUrl: "./header.component.scss",
3937
})
4038
export class HeaderComponent implements OnInit, OnDestroy {
41-
showMainHeader: boolean = true;
4239
blogURL!: string;
4340
blogInfo!: BlogInfo;
4441
blogId: string = "";
@@ -85,12 +82,6 @@ export class HeaderComponent implements OnInit, OnDestroy {
8582
this.blogService.getSeriesList(this.blogURL).subscribe((data) => {
8683
this.seriesList = data;
8784
});
88-
this.router.events.subscribe((event) => {
89-
if (event instanceof NavigationEnd) {
90-
this.showMainHeader =
91-
!this.route.snapshot.firstChild?.paramMap.has("postSlug");
92-
}
93-
});
9485
}
9586

9687
onThemeChange(theme: string): void {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<app-header />
2+
<div class="content">
3+
<router-outlet />
4+
</div>
5+
<app-footer />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.content {
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
5+
min-height: 74vh;
6+
width: 100%;
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { LayoutComponent } from './layout.component';
4+
5+
describe('LayoutComponent', () => {
6+
let component: LayoutComponent;
7+
let fixture: ComponentFixture<LayoutComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
imports: [LayoutComponent]
12+
})
13+
.compileComponents();
14+
15+
fixture = TestBed.createComponent(LayoutComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component } from '@angular/core';
2+
import { HeaderComponent } from '../header/header.component';
3+
import { FooterComponent } from '../footer/footer.component';
4+
import { RouterOutlet } from '@angular/router';
5+
6+
@Component({
7+
selector: 'app-layout',
8+
standalone: true,
9+
imports: [HeaderComponent, FooterComponent, RouterOutlet],
10+
templateUrl: './layout.component.html',
11+
styleUrl: './layout.component.scss'
12+
})
13+
export class LayoutComponent {
14+
15+
}

src/app/components/post-details/post-details.component.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
<div class="post-details-page">
2+
<p-toolbar>
3+
<div class="p-toolbar-group-start">
4+
<app-sidenav></app-sidenav>
5+
<a routerLink="/" class="logo">
6+
<h1>{{blogName}}</h1>
7+
</a>
8+
</div>
9+
<div class="p-toolbar-group-end">
10+
<app-search-dialog [blogId]="blogId"></app-search-dialog>
11+
<p-inputSwitch [(ngModel)]="checked" (click)="onThemeChange(checked ? 'dark' : 'light')"
12+
id="theme-switch"></p-inputSwitch>
13+
</div>
14+
</p-toolbar>
15+
216
@if (post$ | async; as post) {
317
<article>
418
<h1 class="title">{{ post.title }}</h1>
@@ -34,4 +48,5 @@ <h1 class="title">{{ post.title }}</h1>
3448
<div class="content" [innerHTML]="post.content.html | sanitizerHtml" youtubeVideoEmbed></div>
3549
</article>
3650
}
51+
<app-footer></app-footer>
3752
</div>

src/app/components/post-details/post-details.component.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
.post-details-page {
2+
p-toolbar {
3+
.p-toolbar-group-start {
4+
h1 {
5+
font-size: 1.3rem;
6+
font-weight: 500;
7+
margin: 0;
8+
}
9+
}
10+
11+
.p-toolbar-group-end {
12+
gap: 0.625rem;
13+
}
14+
}
15+
216
article {
317
margin: 0 auto;
418
max-width: 50vw;

0 commit comments

Comments
 (0)