Skip to content

Commit

Permalink
feat: jump to facebook to get identity if there is no identity in the db
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Jul 24, 2019
1 parent 5141b78 commit 4ef8934
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
14 changes: 13 additions & 1 deletion src/components/Welcomes/0.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { geti18nString } from '../../utils/i18n'
import { makeStyles, Paper, Button, Typography, Box, Theme, useTheme } from '@material-ui/core'
import { styled } from '@material-ui/styles'
import WelcomeContainer from './WelcomeContainer'
import { IdentifierRefContext } from '../../extension/options-page/Welcome'
import { useValueRef } from '../../utils/hooks/useValueRef'

const VerticalCenter = styled('div')({
display: 'flex',
Expand Down Expand Up @@ -64,6 +66,7 @@ const useStyles = makeStyles(theme => ({
export default function Welcome({ create, restore, close }: Props) {
const theme = useTheme()
const classes = useStyles()
const idContext = useValueRef(React.useContext(IdentifierRefContext))
return (
<WelcomeContainer>
<nav className={classes.nav}>
Expand All @@ -85,7 +88,16 @@ export default function Welcome({ create, restore, close }: Props) {
<Typography variant="h6">{geti18nString('welcome_0_connect_facebook')}</Typography>
</Box>
<VerticalCenter>
<Button className={classes.commonButton} onClick={create} variant="contained" color="primary">
<Button
disabled={idContext.isUnknown}
className={classes.commonButton}
onClick={() => {
if (idContext.isUnknown) {
location.href = 'https://facebook.com/'
} else create()
}}
variant="contained"
color="primary">
{geti18nString('welcome_0_connect_facebook')}
</Button>
</VerticalCenter>
Expand Down
9 changes: 6 additions & 3 deletions src/extension/background-script/PeopleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ export async function queryPeople(network: string): Promise<Person[]> {
/**
* Query my identity.
*/
export async function queryMyIdentity(network: string): Promise<Person[]>
export async function queryMyIdentity(network?: string): Promise<Person[]>
export async function queryMyIdentity(identifier: PersonIdentifier): Promise<Person[]>
export async function queryMyIdentity(identifier: PersonIdentifier | string): Promise<Person[]> {
if (typeof identifier === 'string') {
export async function queryMyIdentity(identifier?: PersonIdentifier | string): Promise<Person[]> {
if (identifier === undefined) {
const all = await getMyIdentitiesDB()
return Promise.all(all.map(personRecordToPerson))
} else if (typeof identifier === 'string') {
const all = await getMyIdentitiesDB()
const atSite = all.filter(x => x.identifier.network === identifier)
return Promise.all(atSite.map(personRecordToPerson))
Expand Down
24 changes: 16 additions & 8 deletions src/extension/options-page/Welcome/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,16 @@ const ResponsiveDialog = withMobileDialog()(Dialog)
const ProvePostRef = new ValueRef('')
const IdentifierRef = new ValueRef(PersonIdentifier.unknown)
const getMyProveBio = async () => {
if (IdentifierRef.value.isUnknown) {
const all = await Services.People.queryMyIdentity()
if (all[0]) IdentifierRef.value = all[0].identifier
}
const post = await Services.Crypto.getMyProveBio(IdentifierRef.value)
if (post) ProvePostRef.value = post
}
MessageCenter.on('generateKeyPair', getMyProveBio)
IdentifierRef.addListener(getMyProveBio)
getMyProveBio()

const useStyles = makeStyles(theme => ({
full: {
Expand All @@ -144,6 +149,7 @@ const useStyles = makeStyles(theme => ({
alignItems: 'center',
},
}))
export const IdentifierRefContext = React.createContext(IdentifierRef)
export default withRouter(function _WelcomePortal(props: RouteComponentProps<{ identifier: string }>) {
const [step, setStep] = useState(WelcomeState.Start)
const provePost = useValueRef(ProvePostRef)
Expand All @@ -161,14 +167,16 @@ export default withRouter(function _WelcomePortal(props: RouteComponentProps<{ i

return (
<ResponsiveDialog classes={{ paperWidthSm: classes.full }} open>
<Welcome
provePost={provePost}
currentStep={step}
sideEffects={WelcomeActions}
onStepChange={setStep}
onFinish={WelcomeActions.onFinish}
identity={identifier}
/>
<IdentifierRefContext.Provider value={IdentifierRef}>
<Welcome
provePost={provePost}
currentStep={step}
sideEffects={WelcomeActions}
onStepChange={setStep}
onFinish={WelcomeActions.onFinish}
identity={identifier}
/>
</IdentifierRefContext.Provider>
</ResponsiveDialog>
)
})
Expand Down

0 comments on commit 4ef8934

Please sign in to comment.