Skip to content

Commit

Permalink
fix: add withFetch()
Browse files Browse the repository at this point in the history
  • Loading branch information
rodzyk committed Aug 23, 2024
1 parent c1309a8 commit 5ceca10
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { LOCALE_ID, NgModule, isDevMode } from '@angular/core';
import { LOCALE_ID, NgModule, isDevMode, provideZoneChangeDetection } from '@angular/core';
import { BrowserModule, provideClientHydration } from '@angular/platform-browser';

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

registerLocaleData(localeUk)

@NgModule({ declarations: [
@NgModule({
declarations: [
AppComponent,
PageNotFoundComponent
],
Expand All @@ -26,5 +27,11 @@ registerLocaleData(localeUk)
// or after 30 seconds (whichever comes first).
registrationStrategy: 'registerWhenStable:30000'
}),
SharedModule], providers: [provideHttpClient(withInterceptorsFromDi()), provideClientHydration()] })
SharedModule],
providers: [
provideZoneChangeDetection({ eventCoalescing: true }),
provideClientHydration(),
provideHttpClient(withFetch())
]
})
export class AppModule { }
7 changes: 6 additions & 1 deletion src/app/history/data-access/history.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { inject, Injectable, PLATFORM_ID } from '@angular/core';
import Dexie from 'dexie';

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

platformId = inject(PLATFORM_ID)

constructor() {
this.createDatabase();
}

private createDatabase() {

this.db = new Dexie(HISTORY_DB_NAME);
this.db.version(1).stores({
history: '++id,site,post_id,title,cover,episode,created,updated'
});
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/data-access/embed-halper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class EmbedHalperService {
constructor() { }

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

const msg = { type, message }

Expand Down
4 changes: 3 additions & 1 deletion src/app/shared/data-access/viewer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ViewerService {

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

keyboard: boolean = (navigator as any).keyboard;
keyboard: boolean = (isPlatformBrowser(this.platformId)) && (navigator as any).keyboard;

constructor() {
this.initNightlight();
Expand All @@ -50,6 +50,8 @@ export class ViewerService {
}

initViewModeOption() {
if(!isPlatformBrowser(this.platformId)) return;

const localOpt: ViewModeOption = JSON.parse(localStorage?.getItem(VIEW_MODE_OPT_NAME) ?? '{}');
const opt: ViewModeOption = this.getViewModeOptionByCode(localOpt?.code) ?? VIEV_MODE_OPTIONS[0]
this.setViewModeOption(opt);
Expand Down
2 changes: 2 additions & 0 deletions src/app/shared/ui/viewer/viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export class ViewerComponent implements AfterViewInit {

activeIndexs: WritableSignal<number[]> = signal([])
initActiveIndexes() {
if (!isPlatformBrowser(this.platformId)) return

const isPageMode = this.viewer.viewModeOption().mode == 'pages';

const viewRect: DOMRect = isPageMode
Expand Down

0 comments on commit 5ceca10

Please sign in to comment.