🐛 fix hook not detecting user authenticated

This commit is contained in:
ghalestrilo 2020-08-13 18:57:42 -03:00
parent a0b302fdcd
commit 074334e14a
3 changed files with 8 additions and 7 deletions

View file

@ -34,8 +34,7 @@ class App extends React.Component {
render() {
return (
<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}
</div>
);

View file

@ -73,6 +73,9 @@ const getNatOptions = (username = undefined) =>
const isUserOwner = ({ project, user }) =>
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 />
const handleGlobalKeydown = (props, cmController) => (e) => {
const {
@ -113,7 +116,7 @@ const handleGlobalKeydown = (props, cmController) => (e) => {
// 83 === s
e.preventDefault();
e.stopPropagation();
if (isUserOwner(props) || (user.authenticated && !project.owner)) saveProject(cmController.getContent());
if (canSaveProject(props)) saveProject(cmController.getContent());
else if (user.authenticated) cloneProject();
else showErrorModal('forceAuthentication');
@ -205,8 +208,7 @@ const MobileIDEView = (props) => {
autosaveProject, preferences, ide, selectedFile
});
// useEventListener('keydown', () => alert('haha'));
useEventListener('keydown', handleGlobalKeydown(props, cmController));
useEventListener('keydown', handleGlobalKeydown(props, cmController), false, [props]);
return (

View file

@ -53,7 +53,7 @@ export const useEffectWithComparison = (fn, 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);
return () => document.removeEventListener(event, callback, useCapture);
}, []);
}, list);