blob: a0b52f045e855e15730df233d689674b92d29494 (
plain) (
blame)
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
|
import TabPresenter from '../presenters/TabPresenter';
export default class TabSelectUseCase {
private tabPresenter: TabPresenter;
constructor() {
this.tabPresenter = new TabPresenter();
}
async selectPrev(count: number): Promise<any> {
let tabs = await this.tabPresenter.getAll();
if (tabs.length < 2) {
return;
}
let tab = tabs.find(t => t.active);
if (!tab) {
return;
}
let select = (tab.index - count + tabs.length) % tabs.length;
return this.tabPresenter.select(tabs[select].id as number);
}
async selectNext(count: number): Promise<any> {
let tabs = await this.tabPresenter.getAll();
if (tabs.length < 2) {
return;
}
let tab = tabs.find(t => t.active);
if (!tab) {
return;
}
let select = (tab.index + count) % tabs.length;
return this.tabPresenter.select(tabs[select].id as number);
}
async selectFirst(): Promise<any> {
let tabs = await this.tabPresenter.getAll();
return this.tabPresenter.select(tabs[0].id as number);
}
async selectLast(): Promise<any> {
let tabs = await this.tabPresenter.getAll();
return this.tabPresenter.select(tabs[tabs.length - 1].id as number);
}
async selectPrevSelected(): Promise<any> {
let tabId = await this.tabPresenter.getLastSelectedId();
if (tabId === null || typeof tabId === 'undefined') {
return Promise.resolve();
}
return this.tabPresenter.select(tabId);
}
}
|