Skip to content

Commit f5261d3

Browse files
add trakt history import button
1 parent 4c86c48 commit f5261d3

File tree

3 files changed

+229
-4
lines changed

3 files changed

+229
-4
lines changed

package-lock.json

Lines changed: 185 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"react-i18next": "^12.1.1",
4040
"react-is": "18.2.0",
4141
"spatial-navigation-polyfill": "github:Stremio/spatial-navigation#64871b1422466f5f45d24ebc8bbd315b2ebab6a6",
42+
"stremio-history-sync": "github:stremio/stremio-history-sync",
4243
"stremio-translations": "github:Stremio/stremio-translations#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd",
4344
"url": "0.11.0",
4445
"use-long-press": "^3.1.5"

src/routes/Settings/Settings.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { default: Icon } = require('@stremio/stremio-icons/react');
88
const { useRouteFocused } = require('stremio-router');
99
const { useServices } = require('stremio/services');
1010
const { Button, Checkbox, MainNavBars, Multiselect, ColorInput, TextInput, ModalDialog, useProfile, useStreamingServer, useBinaryState, withCoreSuspender, useToast } = require('stremio/common');
11+
const historySync = require('stremio-history-sync');
1112
const useProfileSettingsInputs = require('./useProfileSettingsInputs');
1213
const useStreamingServerSettingsInputs = require('./useStreamingServerSettingsInputs');
1314
const useDataExport = require('./useDataExport');
@@ -100,6 +101,38 @@ const Settings = () => {
100101
}
101102
});
102103
}
104+
}, [isTraktAuthenticated, profile]);
105+
const traktImportOnClick = React.useCallback(() => {
106+
if ((localStorage.getItem('lastTraktImport') || 0) > Date.now() - (24 * 60 * 60 * 1000)) {
107+
toast.show({
108+
type: 'error',
109+
title: 'You already used this action recently, try again later',
110+
timeout: 25000
111+
});
112+
return
113+
}
114+
localStorage.setItem('lastTraktImport', Date.now())
115+
toast.show({
116+
type: 'success',
117+
title: 'Importing Trakt watched list...',
118+
timeout: 25000
119+
});
120+
historySync.traktSync(profile.auth.key)
121+
.then((res) =>
122+
toast.show({
123+
type: 'success',
124+
title: `Success: ${res.length} items imported from trakt watched list. (${res.movies} movies & ${res.series} series)`,
125+
timeout: 25000
126+
}))
127+
.catch(e => {
128+
console.error(e)
129+
localStorage.setItem('lastTraktImport', 0)
130+
toast.show({
131+
type: 'error',
132+
title: 'Trakt Import failed, please try again later',
133+
timeout: 25000
134+
});
135+
});
103136
}, [isTraktAuthenticated, profile.auth]);
104137
const subscribeCalendarOnClick = React.useCallback(() => {
105138
const url = `webcal://www.strem.io/calendar/${profile.auth.user._id}.ics`;
@@ -324,7 +357,16 @@ const Settings = () => {
324357
<div className={styles['label']}>
325358
{ profile.auth !== null && profile.auth.user !== null && profile.auth.user.trakt !== null ? t('LOG_OUT') : t('SETTINGS_TRAKT_AUTHENTICATE') }
326359
</div>
327-
</Button>
360+
</Button>
361+
{
362+
isTraktAuthenticated ?
363+
<Button className={classnames(styles['option-input-container'], styles['button-container'])} title={'Trakt Library Import'} disabled={profile.auth === null} tabIndex={-1} onClick={traktImportOnClick}>
364+
<div className={styles['label']}>
365+
{ t('TRAKT_IMPORT_WATCHED') }
366+
</div>
367+
</Button>
368+
: null
369+
}
328370
</div>
329371
</div>
330372
<div className={styles['section-container']}>

0 commit comments

Comments
 (0)