Sengi-Windows-MacOS-Linux/src/app/app.component.ts

116 lines
3.6 KiB
TypeScript
Raw Normal View History

2018-09-10 03:55:16 +02:00
import { Component, OnInit, OnDestroy } from '@angular/core';
2019-03-10 03:49:07 +01:00
import { Subscription, Observable, Subject } from 'rxjs';
import { debounceTime, map } from 'rxjs/operators';
2019-02-11 04:23:10 +01:00
import { Select } from '@ngxs/store';
// import { ElectronService } from 'ngx-electron';
2018-03-15 01:48:52 +01:00
2019-07-04 01:55:33 +02:00
import { NavigationService, LeftPanelType, OpenLeftPanelEvent } from './services/navigation.service';
2019-02-11 04:23:10 +01:00
import { StreamElement } from './states/streams.state';
2019-02-26 05:38:15 +01:00
import { OpenMediaEvent } from './models/common.model';
2019-03-08 05:24:23 +01:00
import { ToolsService } from './services/tools.service';
import { MediaService } from './services/media.service';
2018-03-15 01:48:52 +01:00
@Component({
2019-02-11 04:23:10 +01:00
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
2018-03-15 01:48:52 +01:00
})
2019-02-26 05:38:15 +01:00
export class AppComponent implements OnInit, OnDestroy {
2019-02-11 04:23:10 +01:00
title = 'Sengi';
floatingColumnActive: boolean;
tutorialActive: boolean;
2019-02-26 05:38:15 +01:00
// mediaViewerActive: boolean = false;
openedMediaEvent: OpenMediaEvent
2019-02-25 06:04:09 +01:00
2019-02-11 04:23:10 +01:00
private columnEditorSub: Subscription;
2019-02-26 05:38:15 +01:00
private openMediaSub: Subscription;
private streamSub: Subscription;
2019-03-10 03:49:07 +01:00
private dragoverSub: Subscription;
2019-02-11 04:23:10 +01:00
@Select(state => state.streamsstatemodel.streams) streamElements$: Observable<StreamElement[]>;
2019-03-08 05:24:23 +01:00
constructor(
private readonly toolsService: ToolsService,
private readonly mediaService: MediaService,
private readonly navigationService: NavigationService) {
2019-02-11 04:23:10 +01:00
}
ngOnInit(): void {
2019-02-26 05:38:15 +01:00
this.streamSub = this.streamElements$.subscribe((streams: StreamElement[]) => {
if (streams && streams.length === 0) {
2019-02-11 04:23:10 +01:00
this.tutorialActive = true;
} else {
this.tutorialActive = false;
}
});
2019-07-04 01:55:33 +02:00
this.columnEditorSub = this.navigationService.activatedPanelSubject.subscribe((event: OpenLeftPanelEvent) => {
if (event.type === LeftPanelType.Closed) {
2019-02-11 04:23:10 +01:00
this.floatingColumnActive = false;
} else {
this.floatingColumnActive = true;
}
});
2019-02-26 05:38:15 +01:00
this.openMediaSub = this.navigationService.activatedMediaSubject.subscribe((openedMediaEvent: OpenMediaEvent) => {
if (openedMediaEvent) {
this.openedMediaEvent = openedMediaEvent;
// this.mediaViewerActive = true;
2019-03-08 04:33:10 +01:00
2019-02-26 05:38:15 +01:00
}
});
2019-03-10 03:49:07 +01:00
this.dragoverSub = this.dragoverSubject
.pipe(
debounceTime(1500)
2019-03-10 03:49:07 +01:00
)
.subscribe(() => {
2019-03-10 03:49:07 +01:00
this.drag = false;
})
2019-02-11 04:23:10 +01:00
}
ngOnDestroy(): void {
2019-02-26 05:38:15 +01:00
this.streamSub.unsubscribe();
2019-02-11 04:23:10 +01:00
this.columnEditorSub.unsubscribe();
2019-02-26 05:38:15 +01:00
this.openMediaSub.unsubscribe();
2019-03-10 03:49:07 +01:00
this.dragoverSub.unsubscribe();
2019-02-26 05:38:15 +01:00
}
2019-03-08 04:33:10 +01:00
closeMedia() {
2019-02-26 05:38:15 +01:00
this.openedMediaEvent = null;
2019-02-11 04:23:10 +01:00
}
2019-03-10 03:49:07 +01:00
private dragoverSubject = new Subject<boolean>();
2019-03-08 04:33:10 +01:00
drag: boolean;
dragenter(event): boolean {
event.stopPropagation();
2019-03-08 05:24:23 +01:00
event.preventDefault();
2019-03-08 04:33:10 +01:00
this.drag = true;
return false;
}
dragleave(event): boolean {
event.stopPropagation();
2019-03-08 05:24:23 +01:00
event.preventDefault();
2019-03-08 04:33:10 +01:00
this.drag = false;
return false;
}
2019-03-08 05:24:23 +01:00
dragover(event): boolean {
2019-03-10 03:49:07 +01:00
// console.warn('dragover');
2019-03-08 04:33:10 +01:00
event.stopPropagation();
event.preventDefault();
2019-03-10 03:49:07 +01:00
this.dragoverSubject.next(true);
2019-03-08 04:33:10 +01:00
return false;
}
2019-03-10 03:49:07 +01:00
drop(event): boolean {
2019-03-08 04:33:10 +01:00
event.stopPropagation();
2019-03-08 05:24:23 +01:00
event.preventDefault();
2019-03-08 04:33:10 +01:00
this.drag = false;
2019-03-08 05:24:23 +01:00
let files = <File[]>event.dataTransfer.files;
const selectedAccount = this.toolsService.getSelectedAccounts()[0];
2019-03-10 19:36:22 +01:00
this.mediaService.uploadMedia(selectedAccount, files);
2019-03-08 04:33:10 +01:00
return false;
}
2018-03-15 01:48:52 +01:00
}