mirror of
https://github.com/wassname/talk.git
synced 2026-07-27 11:28:12 +08:00
Reuse same store and action flows
This commit is contained in:
@@ -219,7 +219,7 @@ class Embed extends React.Component {
|
||||
: <p>{asset.settings.closedMessage}</p>
|
||||
}
|
||||
|
||||
{!loggedIn && <Button id='coralSignInButton' onClick={this.showSignInDialog} full>Sign in to comment</Button>}
|
||||
{!loggedIn && <Button id='coralSignInButton' onClick={this.props.showSignInDialog} full>Sign in to comment</Button>}
|
||||
|
||||
{loggedIn && user && <ChangeUsernameContainer loggedIn={loggedIn} offset={signInOffset} user={user} />}
|
||||
{loggedIn && <ModerationLink assetId={asset.id} isAdmin={isAdmin} />}
|
||||
|
||||
@@ -3,10 +3,12 @@ import {render} from 'react-dom';
|
||||
import {ApolloProvider} from 'react-apollo';
|
||||
|
||||
import {client} from 'coral-framework/services/client';
|
||||
import store from 'coral-framework/services/store';
|
||||
import localStore from 'coral-framework/services/store';
|
||||
|
||||
import AppRouter from './AppRouter';
|
||||
|
||||
const store = (window.opener && window.opener.coralStore) ? window.opener.coralStore : localStore;
|
||||
|
||||
render(
|
||||
<ApolloProvider client={client} store={store}>
|
||||
<AppRouter />
|
||||
|
||||
@@ -26,16 +26,19 @@ export const showSignInDialog = () => dispatch => {
|
||||
const signInPopUp = window.open(
|
||||
'/embed/stream/login',
|
||||
'Login',
|
||||
'menubar=0,resizable=0,width=500,height=500,top=200,left=500'
|
||||
'menubar=0,resizable=0,width=500,height=550,top=200,left=500'
|
||||
);
|
||||
|
||||
signInPopUp.onbeforeunload = fetchMe;
|
||||
// ({type: actions.SHOW_SIGNIN_DIALOG, offset})
|
||||
signInPopUp.onbeforeunload = () => {
|
||||
dispatch(checkLogin());
|
||||
fetchMe();
|
||||
};
|
||||
dispatch({type: actions.SHOW_SIGNIN_DIALOG});
|
||||
};
|
||||
export const hideSignInDialog = () => dispatch => {
|
||||
dispatch({type: actions.HIDE_SIGNIN_DIALOG});
|
||||
window.close();
|
||||
// ({type: actions.HIDE_SIGNIN_DIALOG});
|
||||
}
|
||||
};
|
||||
|
||||
export const createUsernameRequest = () => ({type: actions.CREATE_USERNAME_REQUEST});
|
||||
export const showCreateUsernameDialog = () => ({type: actions.SHOW_CREATEUSERNAME_DIALOG});
|
||||
@@ -62,10 +65,13 @@ export const createUsername = (userId, formData) => dispatch => {
|
||||
export const changeView = view => dispatch => {
|
||||
switch(view) {
|
||||
case 'SIGNUP':
|
||||
window.resizeTo(500, 700);
|
||||
window.resizeTo(500, 800);
|
||||
break;
|
||||
case 'FORGOT':
|
||||
window.resizeTo(500, 400);
|
||||
break;
|
||||
default:
|
||||
window.resizeTo(500, 500);
|
||||
window.resizeTo(500, 550);
|
||||
}
|
||||
dispatch({
|
||||
type: actions.CHANGE_VIEW,
|
||||
@@ -87,7 +93,7 @@ const signInFailure = error => ({type: actions.FETCH_SIGNIN_FAILURE, error});
|
||||
export const fetchSignIn = (formData) => (dispatch) => {
|
||||
dispatch(signInRequest());
|
||||
return coralApi('/auth/local', {method: 'POST', body: formData})
|
||||
.then(() => dispatch(closeSignInPopUp()))
|
||||
.then(() => dispatch(hideSignInDialog()))
|
||||
.catch(error => {
|
||||
if (error.metadata) {
|
||||
|
||||
@@ -101,22 +107,6 @@ export const fetchSignIn = (formData) => (dispatch) => {
|
||||
});
|
||||
};
|
||||
|
||||
// Sign In - Standalone PopUp
|
||||
|
||||
export const openSignInPopUp = cb => () => {
|
||||
const signInPopUp = window.open(
|
||||
'/embed/stream/login',
|
||||
'Login',
|
||||
'menubar=0,resizable=0,width=500,height=500,top=200,left=500'
|
||||
);
|
||||
|
||||
signInPopUp.onbeforeunload = cb;
|
||||
};
|
||||
|
||||
export const closeSignInPopUp = () => () => {
|
||||
window.close();
|
||||
};
|
||||
|
||||
// Sign In - Facebook
|
||||
|
||||
const signInFacebookRequest = () => ({type: actions.FETCH_SIGNIN_FACEBOOK_REQUEST});
|
||||
@@ -155,7 +145,7 @@ export const facebookCallback = (err, data) => dispatch => {
|
||||
dispatch(signInFacebookSuccess(user));
|
||||
dispatch(hideSignInDialog());
|
||||
dispatch(showCreateUsernameDialog());
|
||||
fetchMe();
|
||||
dispatch(hideSignInDialog());
|
||||
} catch (err) {
|
||||
dispatch(signInFacebookFailure(err));
|
||||
return;
|
||||
|
||||
@@ -28,8 +28,7 @@ export default function auth (state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case actions.SHOW_SIGNIN_DIALOG :
|
||||
return state
|
||||
.set('showSignInDialog', true)
|
||||
.set('signInOffset', action.offset);
|
||||
.set('showSignInDialog', true);
|
||||
case actions.HIDE_SIGNIN_DIALOG :
|
||||
return state.merge(Map({
|
||||
isLoading: false,
|
||||
|
||||
@@ -24,7 +24,7 @@ if (window.devToolsExtension) {
|
||||
middlewares.push(window.devToolsExtension());
|
||||
}
|
||||
|
||||
export default createStore(
|
||||
const store = createStore(
|
||||
combineReducers({
|
||||
...mainReducer,
|
||||
apollo: client.reducer()
|
||||
@@ -32,3 +32,6 @@ export default createStore(
|
||||
{},
|
||||
compose(...middlewares)
|
||||
);
|
||||
|
||||
export default store;
|
||||
window.coralStore = store;
|
||||
|
||||
Reference in New Issue
Block a user