-
-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor GraphQL queries and mutations (#360)
- Loading branch information
Showing
42 changed files
with
820 additions
and
625 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* React Starter Kit for Firebase | ||
* https://github.com/kriasoft/react-firebase-starter | ||
* Copyright (c) 2015-present Kriasoft | MIT License | ||
*/ | ||
|
||
import clsx from 'clsx'; | ||
import React from 'react'; | ||
import MuiTextField from '@material-ui/core/TextField'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
root: { | ||
marginBottom: theme.spacing(1), | ||
}, | ||
maxLength: { | ||
float: 'right', | ||
}, | ||
})); | ||
|
||
function TextField(props) { | ||
const { | ||
className, | ||
name, | ||
state: [state, setState], | ||
maxLength, | ||
required, | ||
...other | ||
} = props; | ||
|
||
const s = useStyles(); | ||
const errors = (state.errors || {})[name] || []; | ||
const error = errors.length ? errors.join(' \n') : null; | ||
const hasError = | ||
Boolean(error) || (maxLength && (state[name] || '').length > maxLength); | ||
|
||
let helperText = error || (required ? '* Required' : ' '); | ||
|
||
if (maxLength) { | ||
helperText = ( | ||
<React.Fragment> | ||
{helperText} | ||
<span className={s.maxLength}> | ||
{(state[name] || '').length}/{maxLength} | ||
</span> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
function handleChange(event) { | ||
const { name, value } = event.target; | ||
setState(x => ({ ...x, [name]: value })); | ||
} | ||
|
||
return ( | ||
<MuiTextField | ||
className={clsx(s.root, className)} | ||
name={name} | ||
error={hasError} | ||
value={state[name]} | ||
onChange={handleChange} | ||
helperText={helperText} | ||
{...other} | ||
/> | ||
); | ||
} | ||
|
||
export default TextField; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* React Starter Kit for Firebase | ||
* https://github.com/kriasoft/react-firebase-starter | ||
* Copyright (c) 2015-present Kriasoft | MIT License | ||
*/ | ||
|
||
export * from './useAuth'; | ||
export * from './useConfig'; | ||
export * from './useFirebase'; | ||
export * from './useHistory'; | ||
export * from './useRelay'; | ||
export * from './useReset'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* React Starter Kit for Firebase | ||
* https://github.com/kriasoft/react-firebase-starter | ||
* Copyright (c) 2015-present Kriasoft | MIT License | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { useHistory } from './useHistory'; | ||
import { useReset } from './useReset'; | ||
import { openWindow } from '../utils'; | ||
|
||
export function useAuth() { | ||
const history = useHistory(); | ||
const reset = useReset(); | ||
|
||
return React.useMemo( | ||
() => ({ | ||
signIn(options = {}) { | ||
return openWindow(options.url || '/login', { | ||
onPostMessage({ data }) { | ||
if (typeof data === 'string' && data === 'login:success') { | ||
reset(); | ||
history.replace(history.location); | ||
return Promise.resolve(); | ||
} | ||
}, | ||
}); | ||
}, | ||
|
||
async signOut() { | ||
await fetch('/login/clear', { | ||
method: 'POST', | ||
credentials: 'include', | ||
}); | ||
reset(); | ||
history.push('/'); | ||
}, | ||
}), | ||
[], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* React Starter Kit for Firebase | ||
* https://github.com/kriasoft/react-firebase-starter | ||
* Copyright (c) 2015-present Kriasoft | MIT License | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
export const ConfigContext = React.createContext({}); | ||
|
||
export function useConfig() { | ||
return React.useContext(ConfigContext); | ||
} |
Oops, something went wrong.