🐛 fix hook not detecting user authenticated
This commit is contained in:
parent
a0b302fdcd
commit
074334e14a
3 changed files with 8 additions and 7 deletions
|
@ -34,8 +34,7 @@ class App extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="app">
|
<div className="app">
|
||||||
{false &&
|
{this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
|
||||||
this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
|
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -73,6 +73,9 @@ const getNatOptions = (username = undefined) =>
|
||||||
const isUserOwner = ({ project, user }) =>
|
const isUserOwner = ({ project, user }) =>
|
||||||
project && project.owner && project.owner.id === user.id;
|
project && project.owner && project.owner.id === user.id;
|
||||||
|
|
||||||
|
const canSaveProject = (project, user) =>
|
||||||
|
isUserOwner({ project, user }) || (user.authenticated && !project.owner);
|
||||||
|
|
||||||
// TODO: This could go into <Editor />
|
// TODO: This could go into <Editor />
|
||||||
const handleGlobalKeydown = (props, cmController) => (e) => {
|
const handleGlobalKeydown = (props, cmController) => (e) => {
|
||||||
const {
|
const {
|
||||||
|
@ -113,7 +116,7 @@ const handleGlobalKeydown = (props, cmController) => (e) => {
|
||||||
// 83 === s
|
// 83 === s
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (isUserOwner(props) || (user.authenticated && !project.owner)) saveProject(cmController.getContent());
|
if (canSaveProject(props)) saveProject(cmController.getContent());
|
||||||
else if (user.authenticated) cloneProject();
|
else if (user.authenticated) cloneProject();
|
||||||
else showErrorModal('forceAuthentication');
|
else showErrorModal('forceAuthentication');
|
||||||
|
|
||||||
|
@ -205,8 +208,7 @@ const MobileIDEView = (props) => {
|
||||||
autosaveProject, preferences, ide, selectedFile
|
autosaveProject, preferences, ide, selectedFile
|
||||||
});
|
});
|
||||||
|
|
||||||
// useEventListener('keydown', () => alert('haha'));
|
useEventListener('keydown', handleGlobalKeydown(props, cmController), false, [props]);
|
||||||
useEventListener('keydown', handleGlobalKeydown(props, cmController));
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -53,7 +53,7 @@ export const useEffectWithComparison = (fn, props) => {
|
||||||
}, Object.values(props));
|
}, Object.values(props));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useEventListener = (event, callback, useCapture = false) => useEffect(() => {
|
export const useEventListener = (event, callback, useCapture = false, list = []) => useEffect(() => {
|
||||||
document.addEventListener(event, callback, useCapture);
|
document.addEventListener(event, callback, useCapture);
|
||||||
return () => document.removeEventListener(event, callback, useCapture);
|
return () => document.removeEventListener(event, callback, useCapture);
|
||||||
}, []);
|
}, list);
|
||||||
|
|
Loading…
Reference in a new issue