Kavita/UI/Web/src/app/_services/nav.service.ts
Joseph Milazzo 85f3b620af
Bugfix polishing (#1245)
* Fixed a bug where volumes that are a range fail to generate series detail

* Moved tags closer to genre instead of between different people

* Optimized the query for On Deck

* Adjusted mime types to map to cbX types instead of their generic compression methods.

* Added wiki documentation into invite user flow and register admin user to help users understand email isn't required and they can host their own service.

* Refactored the document height to be set and removed on nav service, so the book reader and manga reader aren't broken.

* Refactored On Deck to first be completely streamed to UI, without having to do any processing in memory. Rewrote the query so that we sort by progress then chapter added. Progress is 30 days inclusive, chapter added is 7 days.

* Fixed an issue where epub date parsing would sometimes fail when it's only a year or not a year at all

* Fixed a bug where incognito mode would report progress

* Fixed a bug where bulk selection in storyline tab wouldn't properly run the action on the correct chapters (if selecting from volume -> chapter).

* Removed a - 1 from total page from card progress bar as the original bug was fixed some time ago

* Fixed a bug where the logic for filtering out a progress event for current logged in user didn't check properly when user is logged out.

* When a file doesn't exist and we are trying to read, throw a kavita exception to the UI layer and log.

* Removed unneeded variable and added some jsdoc
2022-05-08 09:15:43 -07:00

81 lines
2.6 KiB
TypeScript

import { DOCUMENT } from '@angular/common';
import { Inject, Injectable, Renderer2, RendererFactory2 } from '@angular/core';
import { ReplaySubject, take } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class NavService {
public localStorageSideNavKey = 'kavita--sidenav--expanded';
private navbarVisibleSource = new ReplaySubject<boolean>(1);
/**
* If the top Nav bar is rendered or not
*/
navbarVisible$ = this.navbarVisibleSource.asObservable();
private sideNavCollapseSource = new ReplaySubject<boolean>(1);
/**
* If the Side Nav is in a collapsed state or not.
*/
sideNavCollapsed$ = this.sideNavCollapseSource.asObservable();
private sideNavVisibilitySource = new ReplaySubject<boolean>(1);
/**
* If the side nav is rendered or not into the DOM.
*/
sideNavVisibility$ = this.sideNavVisibilitySource.asObservable();
private renderer: Renderer2;
constructor(@Inject(DOCUMENT) private document: Document, rendererFactory: RendererFactory2) {
this.renderer = rendererFactory.createRenderer(null, null);
this.showNavBar();
const sideNavState = (localStorage.getItem(this.localStorageSideNavKey) === 'true') || false;
this.sideNavCollapseSource.next(sideNavState);
this.showSideNav();
}
/**
* Shows the top nav bar. This should be visible on all pages except the reader.
*/
showNavBar() {
this.renderer.setStyle(this.document.querySelector('body'), 'margin-top', '56px');
this.renderer.setStyle(this.document.querySelector('body'), 'height', 'calc(var(--vh)*100 - 56px)');
this.renderer.setStyle(this.document.querySelector('html'), 'height', 'calc(var(--vh)*100 - 56px)');
this.navbarVisibleSource.next(true);
}
/**
* Hides the top nav bar.
*/
hideNavBar() {
this.renderer.setStyle(this.document.querySelector('body'), 'margin-top', '0px');
this.renderer.removeStyle(this.document.querySelector('body'), 'height');
this.renderer.removeStyle(this.document.querySelector('html'), 'height');
this.navbarVisibleSource.next(false);
}
/**
* Shows the side nav. When being visible, the side nav will automatically return to previous collapsed state.
*/
showSideNav() {
this.sideNavVisibilitySource.next(true);
}
/**
* Hides the side nav. This is useful for the readers and login page.
*/
hideSideNav() {
this.sideNavVisibilitySource.next(false);
}
toggleSideNav() {
this.sideNavCollapseSource.pipe(take(1)).subscribe(val => {
if (val === undefined) val = false;
const newVal = !(val || false);
this.sideNavCollapseSource.next(newVal);
localStorage.setItem(this.localStorageSideNavKey, newVal + '');
});
}
}