Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
yongish committed Dec 28, 2019
1 parent 8d69cef commit fd41030
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const signup = (
}
};

export const cognitoFB = data => async dispatch => {
export const cognitoFB = (data, history) => async dispatch => {
const {first_name, last_name, email, accessToken: token, expiresIn} = data;
const expires_at = expiresIn * 1000 + new Date().getTime();
dispatch({type: COGNITO_FB_REQUEST});
Expand All @@ -191,13 +191,14 @@ export const cognitoFB = data => async dispatch => {
first_name,
last_name
});
history.push("/");
} catch (e) {
alert(e.message);
dispatch({type: COGNITO_FB_FAILURE});
}
};

export const cognitoGoogle = data => async dispatch => {
export const cognitoGoogle = (data, history) => async dispatch => {
const {
profileObj: {givenName, familyName, email},
tokenId: token,
Expand All @@ -215,6 +216,7 @@ export const cognitoGoogle = data => async dispatch => {
givenName,
familyName
});
history.push("/");
} catch (e) {
alert(e.message);
dispatch({type: COGNITO_GOOGLE_FAILURE});
Expand Down Expand Up @@ -341,6 +343,10 @@ export const deleteSuggestion = (term, suggestionContent) => dispatch => {
);
};

export const setReferral = referral => dispatch => {
dispatch({type: SET_REFERRAL, referral});
};

export const CLEAR_SUGGESTION: string = "CLEAR_SUGGESTION";
export const COGNITO_FB_REQUEST: string = "COGNITO_FB_REQUEST";
export const COGNITO_FB_SUCCESS: string = "COGNITO_FB_SUCCESS";
Expand Down Expand Up @@ -387,6 +393,7 @@ export const SET_NEW_USER: string = "SET_NEW_USER";
export const SET_ORIGINAL_SUGGESTION: string = "SET_ORIGINAL_SUGGESTION";
export const SET_PASSWORD: string = "SET_PASSWORD";
export const SET_SUGGESTION_CONTENT: string = "SET_SUGGESTION_CONTENT";
export const SET_REFERRAL: string = "SET_REFERRAL";
export const SET_TERM: string = "SET_TERM";
export const SIGNUP_REQUEST: string = "SIGNUP_REQUEST";
export const SIGNUP_SUCCESS: string = "SIGNUP_SUCCESS";
Expand Down
11 changes: 11 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export default function App(props) {
}
const termExists = term && term.length > 0;
const tab = useSelector(state => state.tab);
// const tab = term && term.length > 0 ? "term" : selectorTab;
// console.log(term);
return (
<div className="flexGrowOne flexDisplayRow">
<BlankLeft />
Expand All @@ -38,14 +40,23 @@ export default function App(props) {
<Related />
</div>
)}
<<<<<<< Updated upstream
{!termExists && tab === "about" && <About />}
{!termExists && tab === "home" && (
=======
{tab === "about" && <About />}
{(!term || term.length === 0) && (
>>>>>>> Stashed changes
<div className="flexGrowOne flexDisplayRow">
<Home />
<HomeRight />
</div>
)}
<<<<<<< Updated upstream
{!termExists && tab === "profile" && <Profile />}
=======
{(!term || term.length === 0) && <Profile />}
>>>>>>> Stashed changes
</div>
</div>
<BlankRight />
Expand Down
17 changes: 12 additions & 5 deletions src/components/Content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {useEffect, useState, useRef} from "react";
import {useSelector, useDispatch} from "react-redux";
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardActions from "@material-ui/core/CardActions";
import CardContent from "@material-ui/core/CardContent";
import Collapse from "@material-ui/core/Collapse";
import Dialog from "@material-ui/core/Dialog";
Expand Down Expand Up @@ -90,12 +89,12 @@ export default function Content(props) {

useEffect(() => {
dispatch(getSuggestions(props.term));
}, [dispatch, props.term]);
}, []);
useEffect(() => {
if (Object.keys(suggestionHeights).length === 0) {
setSuggestionHeights(suggestionsRef.current.map(x => x.clientHeight));
}
}, [suggestionHeights]);
}, []);
// useEffect(() => {
// setSuggestionHeights(suggestionsRef.current.clientHeight);
// }, []);
Expand Down Expand Up @@ -290,8 +289,16 @@ export default function Content(props) {
{suggestionVisible && !user.email && (
<div>
<p style={{marginLeft: 10}}>
To add a suggestion, <Link href="/login">log in</Link> or{" "}
<Link href="/signup">sign up</Link>.
To add a suggestion,{" "}
<Link
href="/login"
onClick={() => {
console.log("hi");
}}
>
log in
</Link>{" "}
or <Link href="/signup">sign up</Link>.
</p>
<Button
variant="contained"
Expand Down
31 changes: 25 additions & 6 deletions src/components/SignUp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, {useState} from "react";
import {useSelector, useDispatch} from "react-redux";
import {useHistory} from "react-router-dom";
import FacebookLogin from "react-facebook-login";
// import FacebookLogin from "react-facebook-login";
import FacebookLogin from "react-facebook-login/dist/facebook-login-render-props";

import GoogleLogin from "react-google-login";
import Button from "@material-ui/core/Button";
import CssBaseline from "@material-ui/core/CssBaseline";
Expand All @@ -23,7 +25,8 @@ import {
setEmail,
setFirstName,
setLastName,
setPassword
setPassword,
setReferral
} from "../actions";

const useStyles = makeStyles(theme => ({
Expand Down Expand Up @@ -127,15 +130,31 @@ export default function SignUp() {
<div className={classes.paper}>
<FacebookLogin
appId="1500181530138959"
fields="first_name,last_name,email,picture"
onClick={componentClicked}
callback={response => dispatch(cognitoFB(response))}
callback={response => dispatch(cognitoFB(response, history))}
onClick={() => console.log("hhhhhhhhhh")}
render={renderProps => (
<button
class="loginBtn loginBtn--facebook"
onClick={renderProps.onClick}
>
Continue with Facebook
</button>
)}
/>
<br />
<GoogleLogin
clientId="962985476906-k3ckglb9t5bo0boc2vrvsp9i3ksaat7f.apps.googleusercontent.com"
render={renderProps => (
<button
onClick={renderProps.onClick}
disabled={renderProps.disabled}
class="loginBtn loginBtn--google"
>
Continue with Google
</button>
)}
buttonText="Login"
onSuccess={response => dispatch(cognitoGoogle(response))}
onSuccess={response => dispatch(cognitoGoogle(response, history))}
onFailure={response => alert(response.details)}
cookiePolicy={"single_host_origin"}
/>
Expand Down
13 changes: 12 additions & 1 deletion src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
SET_ORIGINAL_SUGGESTION,
SET_PASSWORD,
SET_SUGGESTION_CONTENT,
SET_REFERRAL,
SET_TERM,
TOGGLE_EDIT,
TOGGLE_SUGGESTION_VISIBILITY
Expand Down Expand Up @@ -128,6 +129,15 @@ const newUser = (state = null, action: {type: string, newUser: string}) => {
}
};

const referral = (state = "", action: {type: string, referral: string}) => {
switch (action.type) {
case SET_REFERRAL:
return action.referral;
default:
return state;
}
};

const user = (state = {}, action: {type: string}) => {
switch (action.type) {
case LOGIN_SUCCESS:
Expand Down Expand Up @@ -325,7 +335,8 @@ const rootReducer = history =>
term,
latestTerms,
searchOptions,
user
user,
referral
});

export default rootReducer;
67 changes: 67 additions & 0 deletions src/styles/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,70 @@
.App-link {
color: #09d3ac;
}

body { padding: 2em; }


/* Shared */
.loginBtn {
box-sizing: border-box;
position: relative;
/* width: 13em; - apply for fixed size */
margin: 0.2em;
padding: 0 15px 0 46px;
border: none;
text-align: left;
line-height: 34px;
white-space: nowrap;
border-radius: 0.2em;
font-size: 16px;
color: #FFF;
}
.loginBtn:before {
content: "";
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
width: 34px;
height: 100%;
}
.loginBtn:focus {
outline: none;
}
.loginBtn:active {
box-shadow: inset 0 0 0 32px rgba(0,0,0,0.1);
}


/* Facebook */
.loginBtn--facebook {
background-color: #4C69BA;
background-image: linear-gradient(#4C69BA, #3B55A0);
/*font-family: "Helvetica neue", Helvetica Neue, Helvetica, Arial, sans-serif;*/
text-shadow: 0 -1px 0 #354C8C;
}
.loginBtn--facebook:before {
border-right: #364e92 1px solid;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/icon_facebook.png') 6px 6px no-repeat;
}
.loginBtn--facebook:hover,
.loginBtn--facebook:focus {
background-color: #5B7BD5;
background-image: linear-gradient(#5B7BD5, #4864B1);
}


/* Google */
.loginBtn--google {
/*font-family: "Roboto", Roboto, arial, sans-serif;*/
background: #DD4B39;
}
.loginBtn--google:before {
border-right: #BB3F30 1px solid;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/icon_google.png') 6px 6px no-repeat;
}
.loginBtn--google:hover,
.loginBtn--google:focus {
background: #E74B37;
}

0 comments on commit fd41030

Please sign in to comment.