Sengi-Windows-MacOS-Linux/src/app/services/navigation.service.ts

88 lines
2.7 KiB
TypeScript
Raw Normal View History

2018-09-10 03:55:16 +02:00
import { Injectable } from '@angular/core';
2019-02-26 05:38:15 +01:00
import { BehaviorSubject, Subject } from 'rxjs';
2018-09-11 07:54:23 +02:00
import { AccountWrapper } from '../models/account.models';
2019-07-08 00:58:56 +02:00
import { OpenMediaEvent, StatusWrapper } from '../models/common.model';
2018-09-10 03:55:16 +02:00
@Injectable()
export class NavigationService {
2018-09-22 06:22:51 +02:00
private accountToManage: AccountWrapper;
2019-07-04 01:55:33 +02:00
activatedPanelSubject = new BehaviorSubject<OpenLeftPanelEvent>(new OpenLeftPanelEvent(LeftPanelType.Closed));
2019-02-26 05:38:15 +01:00
activatedMediaSubject: Subject<OpenMediaEvent> = new Subject<OpenMediaEvent>();
2022-11-19 18:16:31 +01:00
columnSelectedSubject = new BehaviorSubject<number>(-1);
2018-09-10 03:55:16 +02:00
2018-09-22 06:22:51 +02:00
constructor() { }
2018-09-10 03:55:16 +02:00
2018-09-22 06:22:51 +02:00
openColumnEditor(acc: AccountWrapper) {
this.accountToManage = acc;
2019-07-04 01:55:33 +02:00
const newEvent = new OpenLeftPanelEvent(LeftPanelType.ManageAccount);
this.activatedPanelSubject.next(newEvent);
2018-09-22 06:22:51 +02:00
}
2018-09-22 06:22:51 +02:00
openPanel(type: LeftPanelType){
2019-07-04 01:55:33 +02:00
const newEvent = new OpenLeftPanelEvent(type);
this.activatedPanelSubject.next(newEvent);
2018-09-22 06:22:51 +02:00
}
closePanel() {
2019-07-04 01:55:33 +02:00
const newEvent = new OpenLeftPanelEvent(LeftPanelType.Closed);
this.activatedPanelSubject.next(newEvent);
2018-09-22 06:22:51 +02:00
this.accountToManage = null;
}
2019-07-04 01:55:33 +02:00
replyToUser(userHandle: string, isDirectMessage: boolean = false) {
const action = isDirectMessage ? LeftPanelAction.DM : LeftPanelAction.Mention;
const newEvent = new OpenLeftPanelEvent(LeftPanelType.CreateNewStatus, action, userHandle);
this.activatedPanelSubject.next(newEvent);
}
2019-07-08 00:58:56 +02:00
redraft(status: StatusWrapper){
const newEvent = new OpenLeftPanelEvent(LeftPanelType.CreateNewStatus, LeftPanelAction.Redraft, null, status);// statusContent.replace(/<[^>]*>/g, ''));
2019-07-06 06:20:03 +02:00
this.activatedPanelSubject.next(newEvent);
}
2022-11-19 18:16:31 +01:00
edit(status: StatusWrapper){
const newEvent = new OpenLeftPanelEvent(LeftPanelType.EditStatus, LeftPanelAction.Edit, null, status);
this.activatedPanelSubject.next(newEvent);
}
2018-09-22 06:22:51 +02:00
columnSelected(index: number): void {
this.columnSelectedSubject.next(index);
}
getAccountToManage(): AccountWrapper {
return this.accountToManage;
}
2019-02-26 05:38:15 +01:00
openMedia(openMediaEvent: OpenMediaEvent): void{
this.activatedMediaSubject.next(openMediaEvent);
}
2018-09-10 03:55:16 +02:00
}
2018-09-22 06:22:51 +02:00
2019-07-04 01:55:33 +02:00
export class OpenLeftPanelEvent {
constructor(
public type: LeftPanelType,
public action: LeftPanelAction = LeftPanelAction.None,
2019-07-06 06:20:03 +02:00
public userHandle: string = null,
2019-07-08 00:58:56 +02:00
public status: StatusWrapper = null) {
2019-07-04 01:55:33 +02:00
}
}
export enum LeftPanelAction {
None = 0,
DM = 1,
2019-07-06 06:20:03 +02:00
Mention = 2,
Redraft = 3,
2022-11-19 18:16:31 +01:00
Edit = 4,
2019-07-04 01:55:33 +02:00
}
2018-09-22 06:22:51 +02:00
export enum LeftPanelType {
Closed = 0,
2019-08-25 07:43:47 +02:00
ManageAccount = 1,
CreateNewStatus = 2,
2018-09-22 06:22:51 +02:00
Search = 3,
AddNewAccount = 4,
2019-08-25 07:43:47 +02:00
Settings = 5,
2022-11-19 18:16:31 +01:00
ScheduledStatuses = 6,
EditStatus = 7,
2018-09-22 06:22:51 +02:00
}