From ffb6b6955e2fec19f8f3fd7e95776519c0f6b9b7 Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 23 May 2024 22:17:15 -0400 Subject: [PATCH] Move some misc classes into the 'helpers' directory --- src/app/api/client.service.ts | 4 ++-- src/app/api/data-fetching.ts | 7 ------- .../api/interceptors/api-base.interceptor.ts | 2 +- src/app/app.config.ts | 14 +++----------- .../ui/text/code-block.component.ts | 2 +- src/app/helpers/data-fetching.ts | 19 +++++++++++++++++++ src/app/{api => helpers}/lazy-subject.ts | 0 src/app/{api => helpers}/scrollable.ts | 2 +- .../activity-listing.component.ts | 2 +- .../level-listing/level-listing.component.ts | 2 +- .../photo-listing/photo-listing.component.ts | 2 +- src/app/services/embed.service.ts | 2 +- 12 files changed, 31 insertions(+), 27 deletions(-) delete mode 100644 src/app/api/data-fetching.ts create mode 100644 src/app/helpers/data-fetching.ts rename src/app/{api => helpers}/lazy-subject.ts (100%) rename src/app/{api => helpers}/scrollable.ts (63%) diff --git a/src/app/api/client.service.ts b/src/app/api/client.service.ts index 6065d3f7..7b93ba3d 100644 --- a/src/app/api/client.service.ts +++ b/src/app/api/client.service.ts @@ -1,7 +1,7 @@ import {Injectable} from '@angular/core'; import {HttpClient, HttpParams} from "@angular/common/http"; import {Instance} from "./types/instance"; -import {LazySubject} from "./lazy-subject"; +import {LazySubject} from "../helpers/lazy-subject"; import {LevelCategory} from "./types/levels/level-category"; import {Room} from "./types/rooms/room"; import {Level} from "./types/levels/level"; @@ -9,7 +9,7 @@ import {ListWithData} from "./list-with-data"; import {User} from "./types/users/user"; import {ActivityPage} from "./types/activity/activity-page"; import {Photo} from "./types/photos/photo"; -import {Observable, of} from "rxjs"; +import {Observable} from "rxjs"; export const defaultPageSize: number = 40; diff --git a/src/app/api/data-fetching.ts b/src/app/api/data-fetching.ts deleted file mode 100644 index cd8a683e..00000000 --- a/src/app/api/data-fetching.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function getApiBaseUrl(): string { - return "https://lbp.littlebigrefresh.com/api/v3"; -} - -export function getImageLink(hash: string): string { - return `${getApiBaseUrl()}/assets/${hash}/image`; -} diff --git a/src/app/api/interceptors/api-base.interceptor.ts b/src/app/api/interceptors/api-base.interceptor.ts index 68de971c..49590d06 100644 --- a/src/app/api/interceptors/api-base.interceptor.ts +++ b/src/app/api/interceptors/api-base.interceptor.ts @@ -1,6 +1,6 @@ import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; import {Observable} from 'rxjs'; -import {getApiBaseUrl} from "../data-fetching"; +import {getApiBaseUrl} from "../../helpers/data-fetching"; export class ApiBaseInterceptor implements HttpInterceptor { intercept(req: HttpRequest, next: HttpHandler): Observable> { diff --git a/src/app/app.config.ts b/src/app/app.config.ts index e768684f..c18ee549 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -7,8 +7,8 @@ import { routes } from './app.routes'; import { provideClientHydration } from '@angular/platform-browser'; import {ApiBaseInterceptor} from "./api/interceptors/api-base.interceptor"; import {APIv3Interceptor} from "./api/interceptors/apiv3.interceptor"; -import {IMAGE_LOADER, ImageLoaderConfig} from "@angular/common"; -import {getImageLink} from "./api/data-fetching"; +import {IMAGE_LOADER} from "@angular/common"; +import {loadImage} from "./helpers/data-fetching"; export const appConfig: ApplicationConfig = { providers: [ @@ -19,15 +19,7 @@ export const appConfig: ApplicationConfig = { useInterceptor(APIv3Interceptor), { provide: IMAGE_LOADER, - useValue: (config: ImageLoaderConfig) => { - if(config.src.startsWith("/")) return config.src; - - // Only consider SHA1 asset hashes - // Naturally filters out GUIDs, and blank hashes. - if(config.src.length != 40) return "/assets/missingLevel.svg"; - - return getImageLink(config.src); - } + useValue: loadImage, } ] }; diff --git a/src/app/components/ui/text/code-block.component.ts b/src/app/components/ui/text/code-block.component.ts index e0dbb651..3bed905a 100644 --- a/src/app/components/ui/text/code-block.component.ts +++ b/src/app/components/ui/text/code-block.component.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; -import {ContainerComponent} from "./container.component"; +import {ContainerComponent} from "../container.component"; @Component({ selector: 'app-codeblock', diff --git a/src/app/helpers/data-fetching.ts b/src/app/helpers/data-fetching.ts new file mode 100644 index 00000000..4a85b31d --- /dev/null +++ b/src/app/helpers/data-fetching.ts @@ -0,0 +1,19 @@ +import {ImageLoaderConfig} from "@angular/common"; + +export function getApiBaseUrl(): string { + return "https://lbp.littlebigrefresh.com/api/v3"; +} + +export function getImageLink(hash: string): string { + return `${getApiBaseUrl()}/assets/${hash}/image`; +} + +export function loadImage(config: ImageLoaderConfig) { + if(config.src.startsWith("/")) return config.src; + + // Only consider SHA1 asset hashes + // Naturally filters out GUIDs, and blank hashes. + if(config.src.length != 40) return "/assets/missingLevel.svg"; + + return getImageLink(config.src); +} diff --git a/src/app/api/lazy-subject.ts b/src/app/helpers/lazy-subject.ts similarity index 100% rename from src/app/api/lazy-subject.ts rename to src/app/helpers/lazy-subject.ts diff --git a/src/app/api/scrollable.ts b/src/app/helpers/scrollable.ts similarity index 63% rename from src/app/api/scrollable.ts rename to src/app/helpers/scrollable.ts index af7a6b51..93f8f8f8 100644 --- a/src/app/api/scrollable.ts +++ b/src/app/helpers/scrollable.ts @@ -1,4 +1,4 @@ -import {RefreshApiListInfo} from "./refresh-api-list-info"; +import {RefreshApiListInfo} from "../api/refresh-api-list-info"; export interface Scrollable { isLoading: boolean; diff --git a/src/app/pages/activity-listing/activity-listing.component.ts b/src/app/pages/activity-listing/activity-listing.component.ts index 8b6c43c5..2bcc5b7c 100644 --- a/src/app/pages/activity-listing/activity-listing.component.ts +++ b/src/app/pages/activity-listing/activity-listing.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import {PageTitleComponent} from "../../components/ui/text/page-title.component"; -import { Scrollable } from '../../api/scrollable'; +import { Scrollable } from '../../helpers/scrollable'; import {defaultListInfo, RefreshApiListInfo} from '../../api/refresh-api-list-info'; import {ActivityPage} from "../../api/types/activity/activity-page"; import {ClientService} from "../../api/client.service"; diff --git a/src/app/pages/level-listing/level-listing.component.ts b/src/app/pages/level-listing/level-listing.component.ts index c8be9451..b9cd5840 100644 --- a/src/app/pages/level-listing/level-listing.component.ts +++ b/src/app/pages/level-listing/level-listing.component.ts @@ -9,7 +9,7 @@ import {ResponsiveGridComponent} from "../../components/ui/responsive-grid.compo import {Level} from "../../api/types/levels/level"; import {LevelPreviewComponent} from "../../components/items/level-preview.component"; import {ContainerComponent} from "../../components/ui/container.component"; -import {Scrollable} from "../../api/scrollable"; +import {Scrollable} from "../../helpers/scrollable"; import {defaultListInfo, RefreshApiListInfo} from "../../api/refresh-api-list-info"; import {InfiniteScrollerComponent} from "../../components/ui/infinite-scroller.component"; diff --git a/src/app/pages/photo-listing/photo-listing.component.ts b/src/app/pages/photo-listing/photo-listing.component.ts index d7d74aae..2eeed60e 100644 --- a/src/app/pages/photo-listing/photo-listing.component.ts +++ b/src/app/pages/photo-listing/photo-listing.component.ts @@ -2,7 +2,7 @@ import { Component } from '@angular/core'; import {PageTitleComponent} from "../../components/ui/text/page-title.component"; import {ClientService} from "../../api/client.service"; import {Photo} from "../../api/types/photos/photo"; -import {Scrollable} from "../../api/scrollable"; +import {Scrollable} from "../../helpers/scrollable"; import {defaultListInfo, RefreshApiListInfo} from "../../api/refresh-api-list-info"; import {ContainerComponent} from "../../components/ui/container.component"; import {InfiniteScrollerComponent} from "../../components/ui/infinite-scroller.component"; diff --git a/src/app/services/embed.service.ts b/src/app/services/embed.service.ts index be8d4e05..d3e29d02 100644 --- a/src/app/services/embed.service.ts +++ b/src/app/services/embed.service.ts @@ -5,7 +5,7 @@ import {Injectable} from "@angular/core"; import {User} from "../api/types/users/user"; import {ClientService} from "../api/client.service"; import {Photo} from "../api/types/photos/photo"; -import {getImageLink} from "../api/data-fetching"; +import {getImageLink} from "../helpers/data-fetching"; import {TitleService} from "./title.service"; @Injectable({providedIn: 'root'})