mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
Merge pull request #334 from Stremio/feat/settings-trakt-addon
Feat: settings trakt auth
This commit is contained in:
commit
3f24573806
5 changed files with 51 additions and 14 deletions
14
package-lock.json
generated
14
package-lock.json
generated
|
|
@ -12,7 +12,7 @@
|
|||
"@babel/runtime": "7.16.0",
|
||||
"@sentry/browser": "6.13.3",
|
||||
"@stremio/stremio-colors": "5.0.1",
|
||||
"@stremio/stremio-core-web": "0.44.10",
|
||||
"@stremio/stremio-core-web": "0.44.11",
|
||||
"@stremio/stremio-icons": "4.0.0",
|
||||
"@stremio/stremio-video": "0.0.24",
|
||||
"a-color-picker": "1.2.1",
|
||||
|
|
@ -2699,9 +2699,9 @@
|
|||
"integrity": "sha512-Dt3PYmy1DZ473QNs99KYXVWQPHtpIl37VUY0+gCEvvuCqE1fRrZIJtZ9KbysUKonvO7WwdQDztgcW0iGoc1dEA=="
|
||||
},
|
||||
"node_modules/@stremio/stremio-core-web": {
|
||||
"version": "0.44.10",
|
||||
"resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.44.10.tgz",
|
||||
"integrity": "sha512-+AUJ3d5u5SH64lcuQIAtXPfeIaWzSNfdDL92HECXP29qat2TtCyM+ENLhTuMZzrbInD22SQrRhfIS3T8nFVQYg==",
|
||||
"version": "0.44.11",
|
||||
"resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.44.11.tgz",
|
||||
"integrity": "sha512-KkNEZenQ+94ylYEMl/AqvL1Md4p+xwqg/02FKuVxjFBEoKyXEDXCgOKOI7wbbXdZJe8tnvk+XFq39jzAiTinSw==",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "7.16.0"
|
||||
}
|
||||
|
|
@ -16716,9 +16716,9 @@
|
|||
"integrity": "sha512-Dt3PYmy1DZ473QNs99KYXVWQPHtpIl37VUY0+gCEvvuCqE1fRrZIJtZ9KbysUKonvO7WwdQDztgcW0iGoc1dEA=="
|
||||
},
|
||||
"@stremio/stremio-core-web": {
|
||||
"version": "0.44.10",
|
||||
"resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.44.10.tgz",
|
||||
"integrity": "sha512-+AUJ3d5u5SH64lcuQIAtXPfeIaWzSNfdDL92HECXP29qat2TtCyM+ENLhTuMZzrbInD22SQrRhfIS3T8nFVQYg==",
|
||||
"version": "0.44.11",
|
||||
"resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.44.11.tgz",
|
||||
"integrity": "sha512-KkNEZenQ+94ylYEMl/AqvL1Md4p+xwqg/02FKuVxjFBEoKyXEDXCgOKOI7wbbXdZJe8tnvk+XFq39jzAiTinSw==",
|
||||
"requires": {
|
||||
"@babel/runtime": "7.16.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
"@babel/runtime": "7.16.0",
|
||||
"@sentry/browser": "6.13.3",
|
||||
"@stremio/stremio-colors": "5.0.1",
|
||||
"@stremio/stremio-core-web": "0.44.10",
|
||||
"@stremio/stremio-core-web": "0.44.11",
|
||||
"@stremio/stremio-icons": "4.0.0",
|
||||
"@stremio/stremio-video": "0.0.24",
|
||||
"a-color-picker": "1.2.1",
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ const App = () => {
|
|||
};
|
||||
}, []);
|
||||
React.useEffect(() => {
|
||||
if (services.core.active) {
|
||||
const onWindowFocus = () => {
|
||||
services.core.transport.dispatch({
|
||||
action: 'Ctx',
|
||||
args: {
|
||||
|
|
@ -109,7 +109,12 @@ const App = () => {
|
|||
action: 'SyncLibraryWithAPI'
|
||||
}
|
||||
});
|
||||
};
|
||||
if (services.core.active) {
|
||||
onWindowFocus();
|
||||
window.addEventListener('focus', onWindowFocus);
|
||||
}
|
||||
return () => window.removeEventListener('focus', onWindowFocus);
|
||||
}, [initialized]);
|
||||
return (
|
||||
<React.StrictMode>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ const ServicesToaster = () => {
|
|||
break;
|
||||
}
|
||||
|
||||
if (args.error.type === 'Other' && args.error.code === 3 && args.source.event === 'AddonInstalled' && args.source.args.transport_url.startsWith('https://www.strem.io/trakt/addon')) {
|
||||
break;
|
||||
}
|
||||
|
||||
toast.show({
|
||||
type: 'error',
|
||||
title: args.source.event,
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@ const Settings = () => {
|
|||
streamingServerUrlInput.onChange(configureServerUrlInputRef.current.value);
|
||||
closeConfigureServerUrlModal();
|
||||
}, [streamingServerUrlInput]);
|
||||
const [traktAuthStarted, setTraktAuthStarted] = React.useState(false);
|
||||
const isTraktAuthenticated = React.useMemo(() => {
|
||||
return profile.auth !== null && profile.auth.user !== null && profile.auth.user.trakt !== null &&
|
||||
(Date.now() / 1000) < (profile.auth.user.trakt.created_at + profile.auth.user.trakt.expires_in);
|
||||
}, [profile.auth]);
|
||||
const configureServerUrlModalButtons = React.useMemo(() => {
|
||||
return [
|
||||
{
|
||||
|
|
@ -75,9 +80,19 @@ const Settings = () => {
|
|||
}
|
||||
});
|
||||
}, []);
|
||||
const authenticateTraktOnClick = React.useCallback(() => {
|
||||
// TODO
|
||||
}, []);
|
||||
const toggleTraktOnClick = React.useCallback(() => {
|
||||
if (!isTraktAuthenticated && profile.auth !== null && profile.auth.user !== null && typeof profile.auth.user._id === 'string') {
|
||||
window.open(`https://www.strem.io/trakt/auth/${profile.auth.user._id}`);
|
||||
setTraktAuthStarted(true);
|
||||
} else {
|
||||
core.transport.dispatch({
|
||||
action: 'Ctx',
|
||||
args: {
|
||||
action: 'LogoutTrakt'
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [isTraktAuthenticated, profile.auth]);
|
||||
const subscribeCalendarOnClick = React.useCallback(() => {
|
||||
const url = `webcal://www.strem.io/calendar/${profile.auth.user._id}.ics`;
|
||||
window.open(url);
|
||||
|
|
@ -135,6 +150,17 @@ const Settings = () => {
|
|||
const sectionsContainerOnScorll = React.useCallback(throttle(() => {
|
||||
updateSelectedSectionId();
|
||||
}, 50), []);
|
||||
React.useEffect(() => {
|
||||
if (isTraktAuthenticated && traktAuthStarted) {
|
||||
core.transport.dispatch({
|
||||
action: 'Ctx',
|
||||
args: {
|
||||
action: 'InstallTraktAddon'
|
||||
}
|
||||
});
|
||||
setTraktAuthStarted(false);
|
||||
}
|
||||
}, [isTraktAuthenticated, traktAuthStarted]);
|
||||
React.useEffect(() => {
|
||||
if (dataExport.exportUrl !== null && typeof dataExport.exportUrl === 'string') {
|
||||
window.open(dataExport.exportUrl);
|
||||
|
|
@ -228,9 +254,11 @@ const Settings = () => {
|
|||
<div className={styles['option-name-container']}>
|
||||
<div className={styles['label']}>Trakt Scrobbling</div>
|
||||
</div>
|
||||
<Button className={classnames(styles['option-input-container'], styles['button-container'])} title={'Authenticate'} disabled={true} tabIndex={-1} onClick={authenticateTraktOnClick}>
|
||||
<Button className={classnames(styles['option-input-container'], styles['button-container'])} title={'Authenticate'} disabled={profile.auth === null} tabIndex={-1} onClick={toggleTraktOnClick}>
|
||||
<Icon className={styles['icon']} icon={'ic_trakt'} />
|
||||
<div className={styles['label']}>Authenticate</div>
|
||||
<div className={styles['label']}>
|
||||
{ profile.auth.user !== null && profile.auth.user.trakt !== null ? 'Log out' : 'Authenticate' }
|
||||
</div>
|
||||
</Button>
|
||||
</div>
|
||||
<div className={styles['option-container']}>
|
||||
|
|
|
|||
Loading…
Reference in a new issue