All files / app/component/subscription-bar subscription-bar.component.ts

88.88% Statements 32/36
52.63% Branches 10/19
80% Functions 8/10
88.88% Lines 24/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68  2x       2x                               2x 2x   2x 2x   2x     2x 2x 2x 2x 2x 2x 2x 2x 2x   2x   2x 1x       2x       4x 2x       2x       2x              
import { Location } from '@angular/common';
import { AfterViewInit, Component, ElementRef, OnDestroy } from '@angular/core';
import { RouterLink, RouterLinkActive } from '@angular/router';
import { autorun, IReactionDisposer } from 'mobx';
import { MobxAngularModule } from 'mobx-angular';
import { TitleDirective } from '../../directive/title.directive';
import { AdminService } from '../../service/admin.service';
import { ExtService } from '../../service/api/ext.service';
import { ConfigService } from '../../service/config.service';
import { EditorService, TagPreview } from '../../service/editor.service';
import { HelpService } from '../../service/help.service';
import { ModService } from '../../service/mod.service';
import { Store } from '../../store/store';
 
@Component({
  selector: 'app-subscription-bar',
  templateUrl: './subscription-bar.component.html',
  styleUrls: ['./subscription-bar.component.scss'],
  host: { 'class': 'subscription-bar' },
  imports: [MobxAngularModule, RouterLink, RouterLinkActive, TitleDirective]
})
export class SubscriptionBarComponentI implements AfterViewInit, OnDestroy {
  private disposers: IReactionDisposer[] = [];
 
  bookmarks: TagPreview[] = [];
  subs: TagPreview[] = [];
 
  private startIndex = this.currentIndex;
 
  constructor(
    public config: ConfigService,
    public store: Store,
    public themes: ModService,
    public admin: AdminService,
    private editor: EditorService,
    private exts: ExtService,
    public location: Location,
    private el: ElementRef,
    private help: HelpService,
  ) {
    this.disposers.push(autorun(() => this.editor.getBookmarksPreview(this.store.account.bookmarks, this.store.account.origin)
      .subscribe(xs => this.bookmarks = xs)));
    this.disposers.push(autorun(() => this.exts.getCachedExts(this.store.account.subs)
      .subscribe(xs => this.subs = xs)));
  }
 
  ngAfterViewInit() {
    this.help.pushStep(this.el?.nativeElement, $localize`The top bar holds bookmarks and subscriptions.`);
  }
 
  ngOnDestroy() {
    for (const dispose of this.disposers) dispose();
    this.disposers.length = 0;
  }
 
  get currentIndex() {
    Iif ('navigation' in window) {
      // @ts-ignore
      return navigation.currentEntry?.index || 0
    }
    return 0;
  }
 
  back() {
    if (this.currentIndex > this.startIndex) this.location.back();
  }
}