mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-20 10:42:12 +00:00
Intro adapted to changes in core
This commit is contained in:
parent
08dd4bdbb7
commit
b514be6b48
1 changed files with 22 additions and 28 deletions
|
|
@ -3,7 +3,7 @@ const PropTypes = require('prop-types');
|
|||
const classnames = require('classnames');
|
||||
const Icon = require('stremio-icons/dom');
|
||||
const { useRouteFocused } = require('stremio-router');
|
||||
const { Button } = require('stremio/common');
|
||||
const { Button, useCoreEvent } = require('stremio/common');
|
||||
const { useServices } = require('stremio/services');
|
||||
const CredentialsTextInput = require('./CredentialsTextInput');
|
||||
const ConsentCheckbox = require('./ConsentCheckbox');
|
||||
|
|
@ -71,29 +71,21 @@ const Intro = ({ queryParams }) => {
|
|||
error: ''
|
||||
}
|
||||
);
|
||||
React.useEffect(() => {
|
||||
const onEvent = ({ event, args }) => {
|
||||
switch (event) {
|
||||
case 'CtxActionErr': {
|
||||
const [, error] = args;
|
||||
dispatch({ type: 'error', error: error.args.message });
|
||||
break;
|
||||
}
|
||||
case 'CtxChanged': {
|
||||
const state = core.getState();
|
||||
if (state.ctx.content.auth !== null) {
|
||||
window.location.replace('#/');
|
||||
}
|
||||
}
|
||||
useCoreEvent(React.useCallback(({ event, args }) => {
|
||||
switch (event) {
|
||||
case 'UserAuthenticated': {
|
||||
window.location.replace('#/');
|
||||
break;
|
||||
}
|
||||
case 'Error': {
|
||||
if (args.source.event === 'UserAuthenticated') {
|
||||
// TODO use error.code to match translated message;
|
||||
dispatch({ type: 'error', error: args.error.message });
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
if (routeFocused) {
|
||||
core.on('Event', onEvent);
|
||||
}
|
||||
return () => {
|
||||
core.off('Event', onEvent);
|
||||
};
|
||||
}, [routeFocused]);
|
||||
}, []));
|
||||
const loginWithFacebook = React.useCallback(() => {
|
||||
FB.login((response) => {
|
||||
if (response.status === 'connected') {
|
||||
|
|
@ -131,10 +123,11 @@ const Intro = ({ queryParams }) => {
|
|||
return;
|
||||
}
|
||||
core.dispatch({
|
||||
action: 'UserOp',
|
||||
action: 'Ctx',
|
||||
args: {
|
||||
userOp: 'Login',
|
||||
action: 'Authenticate',
|
||||
args: {
|
||||
type: 'Login',
|
||||
email: state.email,
|
||||
password: state.password
|
||||
}
|
||||
|
|
@ -147,9 +140,9 @@ const Intro = ({ queryParams }) => {
|
|||
return;
|
||||
}
|
||||
core.dispatch({
|
||||
action: 'UserOp',
|
||||
action: 'Ctx',
|
||||
args: {
|
||||
userOp: 'Logout'
|
||||
action: 'Logout'
|
||||
}
|
||||
});
|
||||
window.location.replace('#/');
|
||||
|
|
@ -176,10 +169,11 @@ const Intro = ({ queryParams }) => {
|
|||
return;
|
||||
}
|
||||
core.dispatch({
|
||||
action: 'UserOp',
|
||||
action: 'Ctx',
|
||||
args: {
|
||||
userOp: 'Register',
|
||||
action: 'Authenticate',
|
||||
args: {
|
||||
type: 'Register',
|
||||
email: state.email,
|
||||
password: state.password,
|
||||
gdpr_consent: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue