-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathMobileApp.jsx
85 lines (79 loc) · 3.24 KB
/
MobileApp.jsx
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
import { h, Fragment } from 'preact';
import cn from 'classnames';
import styles from './MobileApp.module.css';
import { Player, PlayerError } from './Player.jsx';
import { YouTubeError } from './YouTubeError';
import { usePlatformName, useSettings } from '../providers/SettingsProvider.jsx';
import { SwitchBarMobile } from './SwitchBarMobile.jsx';
import { MobileWordmark } from './Wordmark.jsx';
import { SwitchProvider } from '../providers/SwitchProvider.jsx';
import { createAppFeaturesFrom } from '../features/app.js';
import { MobileButtons } from './MobileButtons.jsx';
import { OrientationProvider } from '../providers/OrientationProvider.jsx';
import { FocusMode } from './FocusMode.jsx';
import { useTelemetry } from '../types.js';
import { useYouTubeError } from '../providers/YouTubeErrorProvider';
const DISABLED_HEIGHT = 450;
/**
* @param {object} props
* @param {import("../embed-settings.js").EmbedSettings|null} props.embed
*/
export function MobileApp({ embed }) {
const settings = useSettings();
const telemetry = useTelemetry();
const youtubeError = useYouTubeError();
const features = createAppFeaturesFrom(settings);
return (
<>
{!youtubeError && features.focusMode()}
<OrientationProvider
onChange={(orientation) => {
if (youtubeError) return;
if (orientation === 'portrait') {
return FocusMode.enable();
}
// landscape
// if the height is too low, just disable it
if (window.innerHeight < DISABLED_HEIGHT) {
FocusMode.disable();
telemetry.landscapeImpression();
return;
}
return FocusMode.enable();
}}
/>
<MobileLayout embed={embed} />
</>
);
}
/**
* @param {object} props
* @param {import("../embed-settings.js").EmbedSettings|null} props.embed
*/
function MobileLayout({ embed }) {
const platformName = usePlatformName();
const youtubeError = useYouTubeError();
const settings = useSettings();
const showCustomError = youtubeError && settings.customError?.state === 'enabled';
return (
<main class={styles.main} data-youtube-error={!!youtubeError}>
<div class={cn(styles.filler, styles.hideInFocus)} />
<div class={styles.embed}>
{embed === null && <PlayerError layout={'mobile'} kind={'invalid-id'} />}
{embed !== null && showCustomError && <YouTubeError layout={'mobile'} kind={youtubeError} />}
{embed !== null && !showCustomError && <Player src={embed.toEmbedUrl()} layout={'mobile'} />}
</div>
<div class={cn(styles.logo, styles.hideInFocus)}>
<MobileWordmark />
</div>
<div class={cn(styles.switch, styles.hideInFocus)}>
<SwitchProvider>
<SwitchBarMobile platformName={platformName} />
</SwitchProvider>
</div>
<div class={cn(styles.buttons, styles.hideInFocus)}>
<MobileButtons embed={embed} />
</div>
</main>
);
}