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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
import { Component } from 'react';
import { observer } from 'mobx-react';
import TabBarSortableList from './TabBarSortableList';
import Service from '../../../models/Service';
interface IProps {
useHorizontalStyle: boolean;
showMessageBadgeWhenMutedSetting: boolean;
showServiceNameSetting: boolean;
showMessageBadgesEvenWhenMuted: boolean;
services: Service[];
setActive: (args: { serviceId: string }) => void;
openSettings: (args: { path: string }) => void;
enableToolTip: () => void;
disableToolTip: () => void;
reorder: (args: { oldIndex: number; newIndex: number }) => void;
reload: (args: { serviceId: string }) => void;
toggleNotifications: (args: { serviceId: string }) => void;
toggleAudio: (args: { serviceId: string }) => void;
toggleDarkMode: (args: { serviceId: string }) => void;
deleteService: (args: { serviceId: string }) => void;
clearCache: (args: { serviceId: string }) => void;
hibernateService: (args: { serviceId: string }) => void;
wakeUpService: (args: { serviceId: string }) => void;
updateService: (args: {
serviceId: string;
serviceData: { isEnabled: boolean; isMediaPlaying: boolean };
redirect: boolean;
}) => void;
}
@observer
class TabBar extends Component<IProps> {
onSortEnd = ({ oldIndex, newIndex }) => {
const { enableToolTip, reorder } = this.props;
enableToolTip();
reorder({ oldIndex, newIndex });
};
shouldPreventSorting = event => event.target.tagName !== 'LI';
toggleService = (args: { serviceId: string; isEnabled: boolean }) => {
const { updateService } = this.props;
if (args.serviceId) {
updateService({
serviceId: args.serviceId,
serviceData: {
isEnabled: args.isEnabled,
isMediaPlaying: false,
},
redirect: false,
});
}
};
disableService({ serviceId }) {
this.toggleService({ serviceId, isEnabled: false });
}
enableService({ serviceId }) {
this.toggleService({ serviceId, isEnabled: true });
}
hibernateService({ serviceId }) {
if (serviceId) {
this.props.hibernateService({ serviceId });
}
}
wakeUpService({ serviceId }) {
if (serviceId) {
this.props.wakeUpService({ serviceId });
}
}
render() {
const {
services,
setActive,
openSettings,
disableToolTip,
reload,
toggleNotifications,
toggleAudio,
toggleDarkMode,
deleteService,
clearCache,
useHorizontalStyle,
showMessageBadgeWhenMutedSetting,
showServiceNameSetting,
showMessageBadgesEvenWhenMuted,
} = this.props;
const axis = useHorizontalStyle ? 'x' : 'y';
return (
<div>
<TabBarSortableList
// @ts-expect-error Fix me
services={services}
setActive={setActive}
onSortEnd={this.onSortEnd}
onSortStart={disableToolTip}
shouldCancelStart={this.shouldPreventSorting}
reload={reload}
toggleNotifications={toggleNotifications}
toggleAudio={toggleAudio}
toggleDarkMode={toggleDarkMode}
deleteService={deleteService}
clearCache={clearCache}
disableService={args => this.disableService(args)}
enableService={args => this.enableService(args)}
hibernateService={args => this.hibernateService(args)}
wakeUpService={args => this.wakeUpService(args)}
openSettings={openSettings}
distance={20}
axis={axis}
lockAxis={axis}
helperClass="is-reordering"
showMessageBadgeWhenMutedSetting={showMessageBadgeWhenMutedSetting}
showServiceNameSetting={showServiceNameSetting}
showMessageBadgesEvenWhenMuted={showMessageBadgesEvenWhenMuted}
/>
</div>
);
}
}
export default TabBar;
|