Skip to content

Commit 23b2574

Browse files
authored
Merge pull request #23 from chytanka/develop
fix: add withFetch()
2 parents a8094d7 + 5ceca10 commit 23b2574

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

src/app/app.module.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { LOCALE_ID, NgModule, isDevMode } from '@angular/core';
1+
import { LOCALE_ID, NgModule, isDevMode, provideZoneChangeDetection } from '@angular/core';
22
import { BrowserModule, provideClientHydration } from '@angular/platform-browser';
33

44
import { AppRoutingModule } from './app-routing.module';
55
import { AppComponent } from './app.component';
6-
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
6+
import { provideHttpClient, withFetch, withInterceptorsFromDi } from '@angular/common/http';
77
import { ServiceWorkerModule } from '@angular/service-worker';
88
import { PageNotFoundComponent } from './page-not-found.component';
99
import { SharedModule } from './shared/shared.module';
@@ -14,7 +14,8 @@ import localeUk from "@angular/common/locales/uk";
1414

1515
registerLocaleData(localeUk)
1616

17-
@NgModule({ declarations: [
17+
@NgModule({
18+
declarations: [
1819
AppComponent,
1920
PageNotFoundComponent
2021
],
@@ -26,5 +27,11 @@ registerLocaleData(localeUk)
2627
// or after 30 seconds (whichever comes first).
2728
registrationStrategy: 'registerWhenStable:30000'
2829
}),
29-
SharedModule], providers: [provideHttpClient(withInterceptorsFromDi()), provideClientHydration()] })
30+
SharedModule],
31+
providers: [
32+
provideZoneChangeDetection({ eventCoalescing: true }),
33+
provideClientHydration(),
34+
provideHttpClient(withFetch())
35+
]
36+
})
3037
export class AppModule { }

src/app/history/data-access/history.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Injectable } from '@angular/core';
1+
import { isPlatformBrowser } from '@angular/common';
2+
import { inject, Injectable, PLATFORM_ID } from '@angular/core';
23
import Dexie from 'dexie';
34

45
const HISTORY_DB_NAME: string = `ChytankaHistoryDB`;
@@ -10,18 +11,22 @@ const HISTORY_TABLE_NAME: string = `history`;
1011
export class HistoryService {
1112
private db!: Dexie;
1213

14+
platformId = inject(PLATFORM_ID)
15+
1316
constructor() {
1417
this.createDatabase();
1518
}
1619

1720
private createDatabase() {
21+
1822
this.db = new Dexie(HISTORY_DB_NAME);
1923
this.db.version(1).stores({
2024
history: '++id,site,post_id,title,cover,episode,created,updated'
2125
});
2226
}
2327

2428
async addHistory(site: string, post_id: string, title: string, cover: string, episode: any) {
29+
if(!isPlatformBrowser(this.platformId)) return;
2530
// await this.db.table(HISTORY_TABLE_NAME).add({ site, post_id, title, cover });
2631
const existingEntry = await this.db.table(HISTORY_TABLE_NAME).where({ site, post_id: post_id }).first();
2732

src/app/shared/data-access/embed-halper.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class EmbedHalperService {
1313
constructor() { }
1414

1515
postMessage(message: any, type: string, targetOrigin: string = "*") {
16-
if (!window.top || !isPlatformBrowser(this.platformId)) return
16+
if (!isPlatformBrowser(this.platformId) || !window.top) return
1717

1818
const msg = { type, message }
1919

src/app/shared/data-access/viewer.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ViewerService {
2828

2929
nightlight: WritableSignal<number> = signal(0);
3030

31-
keyboard: boolean = (navigator as any).keyboard;
31+
keyboard: boolean = (isPlatformBrowser(this.platformId)) && (navigator as any).keyboard;
3232

3333
constructor() {
3434
this.initNightlight();
@@ -50,6 +50,8 @@ export class ViewerService {
5050
}
5151

5252
initViewModeOption() {
53+
if(!isPlatformBrowser(this.platformId)) return;
54+
5355
const localOpt: ViewModeOption = JSON.parse(localStorage?.getItem(VIEW_MODE_OPT_NAME) ?? '{}');
5456
const opt: ViewModeOption = this.getViewModeOptionByCode(localOpt?.code) ?? VIEV_MODE_OPTIONS[0]
5557
this.setViewModeOption(opt);

src/app/shared/ui/viewer/viewer.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export class ViewerComponent implements AfterViewInit {
103103

104104
activeIndexs: WritableSignal<number[]> = signal([])
105105
initActiveIndexes() {
106+
if (!isPlatformBrowser(this.platformId)) return
107+
106108
const isPageMode = this.viewer.viewModeOption().mode == 'pages';
107109

108110
const viewRect: DOMRect = isPageMode

0 commit comments

Comments
 (0)