-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
196 lines (153 loc) · 5.95 KB
/
App.jsx
File metadata and controls
196 lines (153 loc) · 5.95 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import './App.css';
import '@streamfinity/streamfinity-branding/dist/index.css';
import React, { useEffect, useState } from 'react';
import moment from 'moment';
import { useShallow } from 'zustand/react/shallow';
import { useTranslation } from 'react-i18next';
import useAuth, { STATE_LIVE, STATE_OWN_VIDEO } from '~/hooks/useAuth';
import { useAppStore } from '~/entries/contentScript/state';
import ReactionPolicyNotice from '~/entries/contentScript/components/ReactionPolicyNotice';
import { WINDOW_NAVIGATE } from '~/events';
import StatusNotice from '~/entries/contentScript/components/StatusNotice';
import ReactionsHistoryNotice from '~/entries/contentScript/components/ReactionsHistoryNotice';
import WatchedVideosObserver from '~/entries/contentScript/components/headless/WatchedVideosObserver';
import PlayerProgressListener from '~/entries/contentScript/components/headless/PlayerProgressListener';
import { setTheme } from '~/common/bridge';
import LoginButton from '~/components/LoginButton';
import SubmitSuggestionNotice from '~/entries/contentScript/components/SubmitSuggestionNotice';
import MarkReactionNotice from '~/entries/contentScript/components/MarkReactionNotice';
import OriginalVideoNotice from '~/entries/contentScript/components/OriginalVideoNotice';
import AppContainer from '~/entries/contentScript/components/AppContainer';
import StreamerModeNotice from '~/entries/contentScript/components/StreamerModeNotice';
import { usePage } from '~/hooks/usePage';
import { useBackgroundEvents } from '~/entries/contentScript/hooks/useBackgroundEvents';
import AnalyticsNotice from '~/entries/contentScript/components/AnalyticsNotice';
import {
storageGetCompact, storageSetCompact, storageGetMinimized, storageSetMinimized,
} from '~/entries/background/common/storage';
function App() {
const { t, i18n } = useTranslation();
const {
user, loadingAuth, liveStream, login, state, isIncognito, isTrackingVideos,
} = useAuth();
const [setCurrentUrl, isDarkMode, isDeviceDarkMode, isCompact, setIsCompact, isMinimized, setIsMinimized] = useAppStore(
useShallow((storeState) => ([
storeState.setCurrentUrl,
storeState.isDarkMode,
storeState.isDeviceDarkMode,
storeState.isCompact,
storeState.setIsCompact,
storeState.isMinimized,
storeState.setIsMinimized,
])),
);
// Set language
useEffect(() => {
if (user?.locale_frontend && i18n.language !== user.locale_frontend) {
i18n.changeLanguage(user.locale_frontend);
}
}, [user, i18n]);
// Add page effect which collects url + channel info
usePage();
// Listen for messages sent by background via browser.tabs.sendMessage
useBackgroundEvents();
// Location navigation listener
useEffect(() => {
setCurrentUrl(window.location.href);
/** @param {CustomEvent} event */
function onChangePage(event) {
setCurrentUrl(event.detail.currentUrl);
}
window.addEventListener(WINDOW_NAVIGATE, onChangePage);
return () => {
window.removeEventListener(WINDOW_NAVIGATE, onChangePage);
};
}, []);
// Compact mode
useEffect(() => {
(async () => {
const current = await storageGetCompact();
if (isCompact === null) {
setIsCompact(!!current);
} else if (current !== isCompact) {
await storageSetCompact(isCompact);
}
})();
}, [isCompact]);
// Minimize listener
useEffect(() => {
(async () => {
const current = await storageGetMinimized();
if (isMinimized === null) {
setIsMinimized(!!current);
} else if (current !== isMinimized) {
await storageSetMinimized(isMinimized);
}
})();
}, [isMinimized]);
// Theme listener
useEffect(() => {
setTheme({ isDark: isDeviceDarkMode });
}, [isDeviceDarkMode]);
// User item
const [toggleLogout, setToggleLogout] = useState(false);
useEffect(() => {
const countdown = setTimeout(() => setToggleLogout(false), 5000);
return () => {
clearTimeout(countdown);
};
}, [toggleLogout]);
if (!user) {
return (
<AppContainer dark={isDarkMode}>
<OriginalVideoNotice />
<ReactionPolicyNotice />
<p className="text-sm text-gray-500">
{t('auth.loginDescription')}
</p>
<LoginButton
loading={loadingAuth}
onClick={login}
/>
</AppContainer>
);
}
return (
<AppContainer
dark={isDarkMode}
state={state}
isTrackingVideos={isTrackingVideos}
liveStream={liveStream}
>
{user && (
<StatusNotice
state={state}
liveStream={liveStream}
/>
)}
{isIncognito && (
<div className="text-center text-sm">
{t('incognito.title', { time: moment(user.extension_invisible_until).format('HH:mm') })}
</div>
)}
{state === STATE_OWN_VIDEO && (
<AnalyticsNotice />
)}
<OriginalVideoNotice />
<ReactionPolicyNotice />
<ReactionsHistoryNotice truncateNames={state === STATE_LIVE} />
{state !== STATE_LIVE && (
<SubmitSuggestionNotice />
)}
{state !== STATE_LIVE && (
<MarkReactionNotice />
)}
{state === STATE_LIVE && (
<StreamerModeNotice />
)}
<PlayerProgressListener active={isTrackingVideos} />
<WatchedVideosObserver />
</AppContainer>
);
}
export default App;