-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathStorageUpload.tsx
More file actions
151 lines (137 loc) · 4.57 KB
/
Copy pathStorageUpload.tsx
File metadata and controls
151 lines (137 loc) · 4.57 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
import React, { useEffect } from 'react';
import * as remote from '@electron/remote';
import cx from 'classnames';
import { Services } from 'components-react/service-provider';
import { useVuex } from 'components-react/hooks';
import { $t } from 'services/i18n';
import Translate from 'components-react/shared/Translate';
import UploadProgress from './UploadProgress';
import styles from './ExportModal.m.less';
import VideoPreview from './VideoPreview';
import { EPlatformCallResult } from 'services/platforms';
import { EUploadPlatform } from 'services/highlighter/models/highlighter.models';
import { ModalLayout } from 'components-react/shared/ModalLayout';
import { has } from 'lodash';
import { Modal } from 'antd';
export default function StorageUpload(p: { onClose: () => void; platform: EUploadPlatform }) {
const { UserService, HighlighterService, SharedStorageService } = Services;
const { uploadInfo, hasSLID } = useVuex(() => ({
uploadInfo: HighlighterService.getUploadInfo(HighlighterService.views.uploadInfo, p.platform),
hasSLID: !!UserService.views.auth?.slid?.id,
}));
const [showSlidLoginModal, setShowSlidLoginModal] = React.useState(false);
function uploadStorage() {
// First check if there is an existing upload for another platform
const existingUpload = HighlighterService.views.state.uploads.find(
upload =>
[
EUploadPlatform.CROSSCLIP,
EUploadPlatform.TYPESTUDIO,
EUploadPlatform.VIDEOEDITOR,
].includes(upload.platform) && upload.videoId,
);
if (existingUpload?.videoId) {
HighlighterService.SET_UPLOAD_INFO({
platform: p.platform,
videoId: existingUpload.videoId,
});
} else {
HighlighterService.actions.uploadStorage(p.platform);
}
}
useEffect(() => {
if (uploadInfo?.videoId) {
remote.shell.openExternal(
SharedStorageService.views.getPlatformLink(p.platform, uploadInfo.videoId),
);
p.onClose();
}
}, [uploadInfo?.videoId]);
// Clear all errors when this component unmounts
useEffect(() => {
return () => HighlighterService.actions.dismissError();
}, []);
if (uploadInfo?.uploading && uploadInfo.platform === p.platform) {
return <UploadProgress platform={p.platform} dense />;
}
return (
<>
<Modal
visible={showSlidLoginModal}
onCancel={() => setShowSlidLoginModal(false)}
closable={true}
destroyOnClose={true}
footer={null}
title={$t('Sign in with Streamlabs ID')}
width={400}
>
<GetSLID onLogin={uploadStorage} />
</Modal>
{uploadInfo?.videoId ? (
<button
className={styles.uploadButton}
onClick={() => {
if (!uploadInfo.videoId) {
return;
}
remote.shell.openExternal(
SharedStorageService.views.getPlatformLink(p.platform, uploadInfo.videoId),
);
}}
>
{$t('Open')}
</button>
) : (
<button
disabled={uploadInfo?.uploading}
className={styles.uploadButton}
onClick={() => {
if (!hasSLID) {
setShowSlidLoginModal(true);
} else {
uploadStorage();
}
}}
>
{$t('Upload')}
</button>
)}
</>
);
}
export function GetSLID(p: { onLogin?: () => void }) {
const { UserService, OnboardingService } = Services;
async function clickLink(signup?: boolean) {
let resp: EPlatformCallResult;
const platform = UserService.views.platform?.type;
if (UserService.views.isLoggedIn) {
resp = await UserService.actions.return.startSLMerge();
} else {
resp = await UserService.actions.return.startSLAuth({ signup });
}
if (resp !== EPlatformCallResult.Success) return;
if (platform) {
UserService.actions.setPrimaryPlatform(platform);
} else {
OnboardingService.actions.start({ isLogin: true });
}
if (p.onLogin) p.onLogin();
}
return (
<div className={styles.crossclipContainer}>
<h2 className={styles.signUpTitle}>{$t('This feature requires a Streamlabs ID')}</h2>
<button
className="button button--action"
style={{ width: '300px', margin: '32px' }}
onClick={() => clickLink(true)}
>
{$t('Sign up for Streamlabs ID')}
</button>
<span className={styles.login}>
<Translate message="Already have a Streamlabs ID? <link>Login</link>">
<a slot="link" onClick={() => clickLink()} />
</Translate>
</span>
</div>
);
}