Skip to content

Commit

Permalink
Move logbook unsetting on back from app to logbook
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Aug 21, 2023
1 parent 129eac8 commit e5e4ece
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
12 changes: 0 additions & 12 deletions scilog/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,4 @@ describe('AppComponent', () => {
// expect(app.title).toEqual('SciLog');
// });

it('should unset the logbook', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
const popStateEvent = new PopStateEvent('popstate');
Object.defineProperty(
popStateEvent,
'target',
{writable: false, value: {location: {pathname: '/overview'}}}
);
window.dispatchEvent(popStateEvent);
expect(app['logbookInfo'].logbookInfo).toBeNull();
});
});
12 changes: 2 additions & 10 deletions scilog/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, HostListener, OnInit } from '@angular/core';
import { LogbookInfoService } from './core/logbook-info.service';
import { Component, OnInit } from '@angular/core';


@Component({
Expand All @@ -12,8 +11,7 @@ export class AppComponent implements OnInit {
light_mode = true;
disable_log = false;

constructor(private logbookInfo: LogbookInfoService) {
}
constructor() {}

ngOnInit(): void {

Expand All @@ -31,10 +29,4 @@ export class AppComponent implements OnInit {
}
}

@HostListener('window:popstate', ['$event'])
onPopState(event: Event & {target: Window}) {
if (event.target.location.pathname === '/overview')
this.logbookInfo.logbookInfo = null;
}

}
12 changes: 12 additions & 0 deletions scilog/src/app/logbook/logbook.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ describe('LogbookComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should unset the logbook', () => {
const popStateEvent = new PopStateEvent('popstate');
Object.defineProperty(
popStateEvent,
'target',
{writable: false, value: {location: {pathname: '/overview'}}}
);
window.dispatchEvent(popStateEvent);
expect(component['logbookInfo'].logbookInfo).toBeNull();
});

});
9 changes: 7 additions & 2 deletions scilog/src/app/logbook/logbook.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, ComponentFactoryResolver } from '@angular/core';
import { Component, OnInit, HostListener } from '@angular/core';
import { ChangeStreamService } from '@shared/change-stream.service';
import { ChangeStreamNotification } from '@shared/changestreamnotification.model'
import { MediaObserver, MediaChange } from '@angular/flex-layout';
import { MediaObserver } from '@angular/flex-layout';
import { Subscription } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import { LogbookInfoService } from '@shared/logbook-info.service';
Expand Down Expand Up @@ -149,5 +149,10 @@ export class LogbookComponent implements OnInit {
(subscription) => subscription.unsubscribe());
}

@HostListener('window:popstate', ['$event'])
onPopState(event: Event & {target: Window}) {
if (event.target.location.pathname === '/overview')
this.logbookInfo.logbookInfo = null;
}

}

0 comments on commit e5e4ece

Please sign in to comment.