Skip to content

Commit

Permalink
Fix pathing
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Fusco <[email protected]>
  • Loading branch information
josephfusco committed Mar 27, 2024
1 parent c6c7527 commit aea52f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
18 changes: 11 additions & 7 deletions src/components/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { GraphiQL } from 'graphiql';
import { useDispatch, useSelect } from '@wordpress/data';

import { actions } from '../store/index';
import PrettifyButton from './toolbarButtons/PrettifyButton';
import CopyQueryButton from './toolbarButtons/CopyQueryButton';
import MergeFragmentsButton from './toolbarButtons/MergeFragmentsButton';
import ShareDocumentButton from './toolbarButtons/ShareDocumentButton';
import ToggleAuthButton from './toolbarButtons/ToggleAuthButton';
import { PrettifyButton } from './toolbarButtons/PrettifyButton';
import { CopyQueryButton } from './toolbarButtons/CopyQueryButton';
import { MergeFragmentsButton } from './toolbarButtons/MergeFragmentsButton';
import { ShareDocumentButton } from './toolbarButtons/ShareDocumentButton';
import { ToggleAuthButton } from './toolbarButtons/ToggleAuthButton';

import 'graphiql/graphiql.min.css';

Expand All @@ -17,6 +17,7 @@ export function Editor() {
const shouldRenderStandalone = useSelect(select => select('wpgraphql-ide').shouldRenderStandalone());
const isAuthenticated = useSelect(select => select('wpgraphql-ide').isAuthenticated());

console.log({isAuthenticated, shouldRenderStandalone});
const fetcher = useCallback(async (graphQLParams) => {
const { graphqlEndpoint } = window.WPGRAPHQL_IDE_DATA;
const headers = { 'Content-Type': 'application/json' };
Expand All @@ -31,10 +32,13 @@ export function Editor() {
return response.json();
}, [isAuthenticated]);

// Correctly handle toggling authentication
const handleToggleAuthentication = () => {
dispatch(actions.toggleAuthentication());
};

const handleDrawerClose = () => {
dispatch(actions.setDrawerOpen(false));
};

return (
<>
Expand All @@ -53,7 +57,7 @@ export function Editor() {
{ ! shouldRenderStandalone && (
<button
className="button EditorDrawerCloseButton"
onClick={ () => setDrawerOpen( false ) }
onClick={handleDrawerClose}
>
X{ ' ' }
<span className="screen-reader-text">
Expand Down
26 changes: 9 additions & 17 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ const reducer = ( state = initialState, action ) => {
},
};
case 'TOGGLE_AUTHENTICATION':
const isAuthenticated = !state.isAuthenticated;
setAuthenticationStateInLocalStorage(isAuthenticated);
return {
...state,
isAuthenticated,
isAuthenticated: !state.isAuthenticated,
};
default:
return state;
Expand Down Expand Up @@ -83,20 +81,14 @@ const actions = {
config,
};
},
toggleAuthentication: () => ({
type: 'TOGGLE_AUTHENTICATION',
}),
};
toggleAuthentication: () => (dispatch, getState) => {
// Dispatch action to toggle authentication state
dispatch({ type: 'TOGGLE_AUTHENTICATION' });

const localStorageMiddleware = store => next => action => {
if (action.type === 'TOGGLE_AUTHENTICATION') {
const nextState = !store.getState().isAuthenticated;

setAuthenticationStateInLocalStorage(nextState);
next(action);
} else {
next(action);
}
// Now, directly handle the side effect using the updated state
const newState = getState();
setAuthenticationStateInLocalStorage(newState.isAuthenticated);
},
};

const selectors = {
Expand All @@ -112,4 +104,4 @@ export const store = createReduxStore( 'wpgraphql-ide', {
reducer,
selectors,
actions,
}, [ localStorageMiddleware ]);
});

0 comments on commit aea52f2

Please sign in to comment.