Skip to content

Commit

Permalink
use http instead of fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Jun 20, 2024
1 parent 954bf3f commit 0e9c45d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 24 deletions.
16 changes: 11 additions & 5 deletions src/app/cards.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { inject, Injectable } from '@angular/core';
import { decompress } from 'compress-json';
import { sortBy } from 'lodash';

import { HttpClient } from '@angular/common/http';
import { type ICard, type IProductFilter } from '../../interfaces';
import { numericalOperator } from '../../search/operators/_helpers';
import { parseQuery, type ParserOperator } from '../../search/search';
Expand All @@ -17,18 +18,23 @@ export class CardsService {
private cardsByName: Record<string, ICard> = {};
private cardsById: Record<string, ICard> = {};

private http = inject(HttpClient);
private metaService = inject(MetaService);

public get allCards(): ICard[] {
return this.cards;
}

public async init() {
const cardData = await fetch(`${environment.baseUrl}/cards.min.json`);
const realData = await cardData.json();

const allCards = decompress(realData);
this.setCards(allCards);
return (
this.http
.get(`${environment.baseUrl}/cards.min.json`)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.subscribe((realData: any) => {
const allCards = decompress(realData);
this.setCards(allCards);
})
);
}

private setCards(cards: ICard[]) {
Expand Down
14 changes: 10 additions & 4 deletions src/app/changelog.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable, signal, type WritableSignal } from '@angular/core';
import { sortBy } from 'lodash';
import type { IChangelogEntry } from '../../interfaces';
Expand All @@ -8,17 +9,22 @@ import { LocaleService } from './locale.service';
providedIn: 'root',
})
export class ChangelogService {
private http = inject(HttpClient);
private localeService = inject(LocaleService);

private changelogByProductIdAndLocale: WritableSignal<
Record<string, Record<string, IChangelogEntry[]>>
> = signal({});

public async init() {
const faqData = await fetch(`${environment.baseUrl}/changelog.json`);
const realData = await faqData.json();

this.parseLocaleFAQs(realData);
return (
this.http
.get(`${environment.baseUrl}/changelog.json`)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.subscribe((realData: any) => {
this.parseLocaleFAQs(realData);
})
);
}

private parseLocaleFAQs(
Expand Down
14 changes: 10 additions & 4 deletions src/app/errata.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable, signal, type WritableSignal } from '@angular/core';
import { sortBy } from 'lodash';
import type { ICardErrata, ICardErrataEntry } from '../../interfaces';
Expand All @@ -8,6 +9,7 @@ import { LocaleService } from './locale.service';
providedIn: 'root',
})
export class ErrataService {
private http = inject(HttpClient);
private localeService = inject(LocaleService);

private errataByProductIdAndLocale: WritableSignal<
Expand All @@ -19,10 +21,14 @@ export class ErrataService {
> = signal({});

public async init() {
const errataData = await fetch(`${environment.baseUrl}/errata.json`);
const realData = await errataData.json();

this.parseLocaleErrata(realData);
return (
this.http
.get(`${environment.baseUrl}/errata.json`)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.subscribe((realData: any) => {
this.parseLocaleErrata(realData);
})
);
}

private parseLocaleErrata(
Expand Down
14 changes: 10 additions & 4 deletions src/app/faq.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable, signal, type WritableSignal } from '@angular/core';
import { sortBy } from 'lodash';
import type { ICardFAQ, ICardFAQEntry } from '../../interfaces';
Expand All @@ -8,6 +9,7 @@ import { LocaleService } from './locale.service';
providedIn: 'root',
})
export class FAQService {
private http = inject(HttpClient);
private localeService = inject(LocaleService);

private faqByProductIdAndLocale: WritableSignal<
Expand All @@ -19,10 +21,14 @@ export class FAQService {
> = signal({});

public async init() {
const faqData = await fetch(`${environment.baseUrl}/faq.json`);
const realData = await faqData.json();

this.parseLocaleFAQs(realData);
return (
this.http
.get(`${environment.baseUrl}/faq.json`)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.subscribe((realData: any) => {
this.parseLocaleFAQs(realData);
})
);
}

private parseLocaleFAQs(faqData: Record<string, Record<string, ICardFAQ[]>>) {
Expand Down
20 changes: 13 additions & 7 deletions src/app/meta.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject, Injectable } from '@angular/core';

import { HttpClient } from '@angular/common/http';
import { get } from 'lodash';
import type { IProduct, IProductFilter } from '../../interfaces';
import { environment } from '../environments/environment';
Expand All @@ -9,6 +10,7 @@ import { LocaleService } from './locale.service';
providedIn: 'root',
})
export class MetaService {
private http = inject(HttpClient);
private localeService = inject(LocaleService);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -27,16 +29,20 @@ export class MetaService {
}

public async init() {
const metaData = await fetch(`${environment.baseUrl}/meta.json`);
const realData = await metaData.json();
return (
this.http
.get(`${environment.baseUrl}/meta.json`)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.subscribe((realData: any) => {
this.siteConfig = realData.config;

this.siteConfig = realData.config;
this.allProducts = realData.products;

this.allProducts = realData.products;
this.localeService.setLocales(realData.locales);

this.localeService.setLocales(realData.locales);

this.loadExternals();
this.loadExternals();
})
);
}

private loadExternals() {
Expand Down

0 comments on commit 0e9c45d

Please sign in to comment.