Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const routes: Routes = [
{
path: 'subscriptions',
loadComponent: async () => {
const c = await import('./pages/subscriptions/subscriptions-page.component')
const c = await import('./pages/subscriptions-page/subscriptions-page')
return c.SubscriptionsPage
},
data: { title: 'Subscriptions' },
Expand Down
12 changes: 12 additions & 0 deletions src/app/components/nav/nav.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ mat-sidenav-content {
.page-content {
overflow: auto;
}

.title {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 100%;
}

.title h2 {
font-size: smaller;
}
5 changes: 4 additions & 1 deletion src/app/components/nav/nav.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
</button>
}
<h1>{{ currentTitle() }}</h1>
<div class="title">
<h1>{{ currentTitle() }}</h1>
<h2>{{ currentSubtitle() }}</h2>
</div>
</mat-toolbar>
<div class="page-content">
<ng-content select="router-outlet"/>
Expand Down
10 changes: 9 additions & 1 deletion src/app/components/nav/nav.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Component, DestroyRef, inject, OnInit, signal, viewChild } from '@angular/core'
import {
Component,
DestroyRef,
inject,
OnInit,
signal,
viewChild
} from '@angular/core'
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'
import { AsyncPipe } from '@angular/common'
import { MatToolbarModule } from '@angular/material/toolbar'
Expand Down Expand Up @@ -35,6 +42,7 @@ export class NavComponent implements OnInit {
private sideNav = viewChild<MatSidenav>('drawer')

currentTitle = toSignal(this.titleService.$currentTitle)
currentSubtitle = toSignal(this.titleService.$currentSubtitle)

isHandset = signal<boolean>(false)

Expand Down
41 changes: 35 additions & 6 deletions src/app/pages/home/home-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MatToolbarModule } from '@angular/material/toolbar'
import { MatButtonToggleModule } from '@angular/material/button-toggle'
import { MatIconModule } from '@angular/material/icon'
import { RowSpacer } from '../../components/row-spacer/row-spacer'
import { Router } from '@angular/router'
import { ActivatedRoute, Router } from '@angular/router'
import { Article } from '../../entities/article/article.types'
import { MatPaginatorModule } from '@angular/material/paginator'
import { TagService } from '../../services/tag-service'
Expand Down Expand Up @@ -44,6 +44,7 @@ import { SortOrder } from '../../entities/base/base.enums'
export class HomePage implements OnInit {
feedService = inject(FeedService)
router = inject(Router)
route = inject(ActivatedRoute)
destroyRef = inject(DestroyRef)
tagService = inject(TagService)
titleService = inject(TitleService)
Expand All @@ -54,6 +55,7 @@ export class HomePage implements OnInit {

$readFilter = new BehaviorSubject(true)
$favFilter = new BehaviorSubject(false)
$subscriptionFilter = new BehaviorSubject<string | null>(null)
$dateOrder = new BehaviorSubject(SortOrder.Desc)

favTagId = signal<string>('')
Expand Down Expand Up @@ -93,9 +95,10 @@ export class HomePage implements OnInit {
this.pageService.$currentPage,
this.$favFilter,
this.$readFilter,
this.$subscriptionFilter,
this.$dateOrder,
]).pipe(
switchMap(([perPage, pageNumber, fav, read, dateSort]) => {
switchMap(([perPage, pageNumber, fav, read, subscription, dateSort]) => {
const filters: Record<string, string | boolean> = {}

if (read) {
Expand All @@ -106,6 +109,10 @@ export class HomePage implements OnInit {
filters['tags'] = favTag
}

if (subscription) {
filters['subscription'] = subscription
}

return this.feedService.getAllArticles({
pagination: {
perPage,
Expand All @@ -124,9 +131,31 @@ export class HomePage implements OnInit {
if (result) {
this.articles.set(result.result)
this.pageService.setTotalResults(result.total)
this.titleService.setTitle(`News: ${result.total} articles`)
this.titleService.setTitle(`Articles: ${result.total} articles`)
} else {
this.titleService.setTitle('News')
this.titleService.setTitle('Articles')
}
})

this.route.queryParams
.pipe(
takeUntilDestroyed(this.destroyRef),
switchMap((params) => {
const subscriptionId: string = params['subscription']
if (!subscriptionId) {
return of(null)
}
return this.feedService.getOneSubscription({ subscriptionId })
}),
catchError((e) => {
console.error(e)
return of(null)
}),
)
.subscribe((feed) => {
if (feed) {
this.titleService.setSubtitle(feed.title)
this.$subscriptionFilter.next(feed._id)
}
})
}
Expand Down Expand Up @@ -165,9 +194,9 @@ export class HomePage implements OnInit {
if (filter === 'read') {
this.$readFilter.next(!this.$readFilter.value)
} else {
this.pageService.setCurrentPage(1)
this.$favFilter.next(!this.$favFilter.value)
}
this.$favFilter.next(!this.$favFilter.value)
this.pageService.setCurrentPage(1)
}

orderHandler(param: 'date') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
:host .mat-mdc-paginator {
background: transparent;
}

.card {
cursor: pointer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
} @else {
@defer {
@for (f of feeds(); track f._id) {
<mat-card>
<mat-card
class="card"
routerLink="/home"
[queryParams]="{ subscription: f._id }"
>
<mat-card-header>
<mat-card-title>{{ f.title }}</mat-card-title>
<app-row-spacer/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import { Paginator } from '../../components/paginator/paginator'
import { PageService } from '../../services/page-service'
import { TitleService } from '../../services/title-service'
import { scrollUp } from '../../../utils'
import { RouterLink } from '@angular/router'

@Component({
selector: 'app-subscriptions',
selector: 'app-subscriptions-page',
imports: [
MatCardModule,
MatToolbarModule,
Expand All @@ -32,9 +33,10 @@ import { scrollUp } from '../../../utils'
MatPaginatorModule,
LinkTrimPipe,
Paginator,
RouterLink,
],
templateUrl: './subscriptions-page.component.html',
styleUrl: './subscriptions-page.component.css',
templateUrl: './subscriptions-page.html',
styleUrl: './subscriptions-page.css',
})
export class SubscriptionsPage implements OnInit {
constructor() {
Expand Down
7 changes: 7 additions & 0 deletions src/app/services/title-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ export class TitleService {
private $$currentTitle = new BehaviorSubject<string>('')
$currentTitle = this.$$currentTitle.asObservable()

private $$currentSubtitle = new BehaviorSubject<string | null>(null)
$currentSubtitle = this.$$currentSubtitle.asObservable()

setTitle(title: string) {
this.$$currentTitle.next(title)
this.pageTitleService.setTitle(title)
}

setSubtitle(subtitle: string | null) {
this.$$currentSubtitle.next(subtitle)
}
}