Skip to content

Commit

Permalink
Move some misc classes into the 'helpers' directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed May 24, 2024
1 parent e2ac3cd commit ffb6b69
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/app/api/client.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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";
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;

Expand Down
7 changes: 0 additions & 7 deletions src/app/api/data-fetching.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/api/interceptors/api-base.interceptor.ts
Original file line number Diff line number Diff line change
@@ -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<any>, next: HttpHandler): Observable<HttpEvent<any>> {
Expand Down
14 changes: 3 additions & 11 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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,
}
]
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/ui/text/code-block.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import {ContainerComponent} from "./container.component";
import {ContainerComponent} from "../container.component";

@Component({
selector: 'app-codeblock',
Expand Down
19 changes: 19 additions & 0 deletions src/app/helpers/data-fetching.ts
Original file line number Diff line number Diff line change
@@ -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);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {RefreshApiListInfo} from "./refresh-api-list-info";
import {RefreshApiListInfo} from "../api/refresh-api-list-info";

export interface Scrollable {
isLoading: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/level-listing/level-listing.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/photo-listing/photo-listing.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/embed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down

0 comments on commit ffb6b69

Please sign in to comment.