mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-08-30 23:00:11 -04:00
Mershing
This commit is contained in:
commit
724822f255
@ -2,11 +2,12 @@ import {HttpClient} from "@angular/common/http";
|
||||
|
||||
export class Page<T>
|
||||
{
|
||||
this: string
|
||||
next: string
|
||||
first: string
|
||||
count: number
|
||||
items: T[]
|
||||
this: string;
|
||||
next: string;
|
||||
first: string;
|
||||
count: number;
|
||||
items: T[];
|
||||
private _isLoading: boolean = false;
|
||||
|
||||
constructor(init?:Partial<Page<T>>)
|
||||
{
|
||||
@ -15,17 +16,20 @@ export class Page<T>
|
||||
|
||||
loadNext(client: HttpClient)
|
||||
{
|
||||
if (this.next == null)
|
||||
if (this.next == null || this._isLoading)
|
||||
return;
|
||||
|
||||
this._isLoading = true;
|
||||
client.get<Page<T>>(this.next).subscribe(x =>
|
||||
{
|
||||
this.items.push(...x.items);
|
||||
this.count += x.count;
|
||||
this.next = x.next;
|
||||
this.this = x.this;
|
||||
this._isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
changeType(type: string)
|
||||
{
|
||||
return this.first.replace(/\/\w*($|\?)/, `/${type}$1`)
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable } from "@angular/core";
|
||||
import { Page } from "../models/page";
|
||||
import { Observable, of } from "rxjs"
|
||||
import { map } from "rxjs/operators"
|
||||
import { Observable, of } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: "root"
|
||||
})
|
||||
export class PreLoaderService
|
||||
{
|
||||
@ -15,7 +15,7 @@ export class PreLoaderService
|
||||
|
||||
load<T>(route: string): Observable<T[]>
|
||||
{
|
||||
let loaded = this.cache.find(x => x[0] == route);
|
||||
let loaded = this.cache.find(x => x[0] === route);
|
||||
if (loaded != null)
|
||||
return of(loaded[1]);
|
||||
return this.http.get<Page<T>>(route).pipe(map(newData =>
|
||||
|
Loading…
x
Reference in New Issue
Block a user