Skip to content

Commit

Permalink
Changes the redirect for the app setup to the current app page, valid…
Browse files Browse the repository at this point in the history
…ates apps list if there is any fetching app, changes the active color of the plug to blue
  • Loading branch information
leymytel committed Jul 17, 2019
1 parent a303ec8 commit a7e79e4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/app/core/services/cache.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { LocalStorageService } from './local-storage.service';

@Injectable()
export class CacheService {
DEFAULT_MAX_AGE = 30; // in minutes
private readonly DEFAULT_MAX_AGE = 30; // in minutes

constructor(private localStorage: LocalStorageService) {}

get<T>(key: string, fallback?: Observable<any>, maxAge?: number): Observable<T> {
get<T>(key: string, fallback?: Observable<any>, maxAge?: number, needsValidation: boolean = false): Observable<T> {
let cache$ = this.localStorage.getItem<T>(key);

if (!maxAge) {
Expand All @@ -23,7 +23,9 @@ export class CacheService {
if (fallback && fallback instanceof Observable) {
cache$ = fallback.pipe(
tap((records) => {
this.localStorage.setItem(key, records, maxAge);
if (!needsValidation) {
this.store(key, records, maxAge);
}
}),
catchError(() => {
return of([]);
Expand All @@ -37,6 +39,10 @@ export class CacheService {
return cache$;
}

store(key: string, payload: any, maxAge: number) {
this.localStorage.setItem(key, payload, maxAge);
}

removeFromCache(key: string) {
this.localStorage.removeItem(key);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/services/local-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class LocalStorageService {
constructor(private store: Store) {}

public setItem<T>(key: string, payload: T, maxAge: number) {
const value: HatCache<T> = {value: payload, date: addMinutes(new Date(), maxAge) };
const value: HatCache<T> = { value: payload, date: addMinutes(new Date(), maxAge) };
this.syncWithLocalStorage(key, value);
this.store.setItem(key, value);
}
Expand Down
28 changes: 26 additions & 2 deletions src/app/explore/hat-applications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export class HatApplicationsService {
private hatUrl: string;
readonly applicationKey = 'applications';
readonly applicationMaxAge = 20; // in minutes
readonly applicationMaxAgeShort = 1; // in minutes

private _dataplugs$: ReplaySubject<HatApplication[]> = <ReplaySubject<HatApplication[]>>new ReplaySubject(1);

constructor(private authSvc: AuthService,
Expand All @@ -37,7 +39,17 @@ export class HatApplicationsService {
}

getAppList(): Observable<HatApplication[]> {
return this.cacheSvc.get<HatApplication[]>(this.applicationKey, this.hatSvc.getApplicationList(), this.applicationMaxAge);
return this.cacheSvc.get<HatApplication[]>(this.applicationKey, this.getApplicationLisApi(), this.applicationMaxAge, true);
}

getApplicationLisApi(): Observable<HatApplication[]> {
return this.hatSvc.getApplicationList().pipe(tap(
apps => {
const hasStatus = this.applicationListHasStatus(apps, ['fetching']);

this.cacheSvc.store(this.applicationKey, apps, hasStatus ? this.applicationMaxAgeShort : this.applicationMaxAge);
}
));
}

getApplicationDetails(application: string): Observable<HatApplication> {
Expand Down Expand Up @@ -65,8 +77,9 @@ export class HatApplicationsService {

generateHatLoginLink(id: string, setup: HatApplicationSetup): string {
const redirectUrl = setup.url || setup.iosUrl || '';
const redirectRumpel = window.location.href.replace('#', '%23');

return `https://${this.hatUrl}/#/hatlogin?name=${id}&redirect=${redirectUrl}%3Fredirect=https://${this.hatUrl}/%23/feed`;
return `https://${this.hatUrl}/#/hatlogin?name=${id}&redirect=${redirectUrl}%3Fredirect=${redirectRumpel}`;
}

getAppStatus(app: HatApplication): 'goto' | 'running' | 'fetching' | 'failing' | 'untouched' | 'update' {
Expand All @@ -83,6 +96,17 @@ export class HatApplicationsService {
return 'untouched';
}
}
applicationListHasStatus(apps: HatApplication[], status: string[]): boolean {
for (const app of apps) {
const appStatus = this.getAppStatus(app);
if (status.indexOf(appStatus) !== -1) {

return true;
}
}

return false;
}

get dataplugs$(): Observable<HatApplication[]> {
return this._dataplugs$.asObservable();
Expand Down
2 changes: 1 addition & 1 deletion src/app/she/she-feed/she-feed.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class SheFeedComponent implements OnInit, AfterViewChecked, OnDestroy {
*/
refreshFeedData() {
// initialize the feed arrays
this.sheFeedSvc.clear();
// this.sheFeedSvc.clear();
this.feedSlicedArray = null;
this.feedArray = null;
this.feed$ = null;
Expand Down
2 changes: 1 addition & 1 deletion src/app/style/_branding.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$app-accent-color: #6297b1;
$app-contrast-color: #F0C400;

$app-active-color: #66B951;
$app-active-color: #6297b1;
$app-failing-color: #E45151;
$app-update-color: #f5a623;

Expand Down

0 comments on commit a7e79e4

Please sign in to comment.