Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hidden settings menu affects settings layout #7769

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApolloProvider } from '@/apollo/components/ApolloProvider';
import { CommandMenuEffect } from '@/app/effect-components/CommandMenuEffect';
import { GotoHotkeys } from '@/app/effect-components/GotoHotkeysEffect';
import { GotoHotkeysEffectsProvider } from '@/app/effect-components/GotoHotkeysEffectsProvider';
import { PageChangeEffect } from '@/app/effect-components/PageChangeEffect';
import { AuthProvider } from '@/auth/components/AuthProvider';
import { ChromeExtensionSidecarEffect } from '@/chrome-extension-sidecar/components/ChromeExtensionSidecarEffect';
Expand Down Expand Up @@ -45,7 +45,7 @@ export const AppRouterProviders = () => {
<StrictMode>
<PromiseRejectionEffect />
<CommandMenuEffect />
<GotoHotkeys />
<GotoHotkeysEffectsProvider />
<PageTitle title={pageTitle} />
<Outlet />
</StrictMode>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const GoToHotkeyItemEffect = (props: {
}) => {
const { hotkey, pathToNavigateTo } = props;

useGoToHotkeys(hotkey, pathToNavigateTo);
useGoToHotkeys({ key: hotkey, location: pathToNavigateTo });

return <></>;
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { GoToHotkeyItemEffect } from '@/app/effect-components/GoToHotkeyItemEffect';
import { useNonSystemActiveObjectMetadataItems } from '@/object-metadata/hooks/useNonSystemActiveObjectMetadataItems';
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { navigationDrawerExpandedMemorizedState } from '@/ui/navigation/states/navigationDrawerExpandedMemorizedState';
import { navigationMemorizedUrlState } from '@/ui/navigation/states/navigationMemorizedUrlState';
import { useGoToHotkeys } from '@/ui/utilities/hotkey/hooks/useGoToHotkeys';
import { useLocation } from 'react-router-dom';
import { useRecoilCallback } from 'recoil';

export const GotoHotkeysEffectsProvider = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually only renaming this file from GoToHokeysEffect

const { nonSystemActiveObjectMetadataItems } =
useNonSystemActiveObjectMetadataItems();

const location = useLocation();

useGoToHotkeys({
key: 's',
location: '/settings/profile',
preNavigateFunction: useRecoilCallback(
({ set }) =>
() => {
set(isNavigationDrawerExpandedState, true);
set(navigationDrawerExpandedMemorizedState, true);
set(navigationMemorizedUrlState, location.pathname + location.search);
},
[location.pathname, location.search],
),
});

return nonSystemActiveObjectMetadataItems.map((objectMetadataItem) => (
<GoToHotkeyItemEffect
key={`go-to-hokey-item-${objectMetadataItem.id}`}
hotkey={objectMetadataItem.namePlural[0]}
pathToNavigateTo={`/objects/${objectMetadataItem.namePlural}`}
/>
));
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect } from 'react';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useRecoilValue } from 'recoil';

import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { SettingsNavigationDrawerItems } from '@/settings/components/SettingsNavigationDrawerItems';
Expand All @@ -9,13 +8,11 @@ import {
NavigationDrawerProps,
} from '@/ui/navigation/navigation-drawer/components/NavigationDrawer';

import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';

import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';

import { AdvancedSettingsToggle } from '@/ui/navigation/link/components/AdvancedSettingsToggle';
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { MainNavigationDrawerItems } from './MainNavigationDrawerItems';

export type AppNavigationDrawerProps = {
Expand All @@ -25,11 +22,8 @@ export type AppNavigationDrawerProps = {
export const AppNavigationDrawer = ({
className,
}: AppNavigationDrawerProps) => {
const isMobile = useIsMobile();
const isSettingsDrawer = useIsSettingsDrawer();
const setIsNavigationDrawerExpanded = useSetRecoilState(
isNavigationDrawerExpandedState,
);

const currentWorkspace = useRecoilValue(currentWorkspaceState);

const drawerProps: NavigationDrawerProps = isSettingsDrawer
Expand All @@ -48,10 +42,6 @@ export const AppNavigationDrawer = ({
footer: <SupportDropdown />,
};

useEffect(() => {
setIsNavigationDrawerExpanded(!isMobile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another useEffect spotted :p

}, [isMobile, setIsNavigationDrawerExpanded]);

return (
<NavigationDrawer
className={className}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fireEvent, renderHook } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import { MemoryRouter, useLocation } from 'react-router-dom';
import { fireEvent, renderHook } from '@testing-library/react';
import { RecoilRoot } from 'recoil';

import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
Expand All @@ -23,7 +23,7 @@ const renderHookConfig = {
describe('useGoToHotkeys', () => {
it('should navigate on hotkey trigger', () => {
const { result } = renderHook(() => {
useGoToHotkeys('a', '/three');
useGoToHotkeys({ key: 'a', location: '/three' });

const setHotkeyScope = useSetHotkeyScope();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ import { AppHotkeyScope } from '../types/AppHotkeyScope';

import { useSequenceHotkeys } from './useSequenceScopedHotkeys';

export const useGoToHotkeys = (key: Keys, location: string) => {
type GoToHotkeysProps = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the API to take an object which is better from a dev XP as parameters are named when using the hook

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I fully agree, Object is way more easier to debug and use.

I always to that :)

key: Keys;
location: string;
preNavigateFunction?: () => void;
};

export const useGoToHotkeys = ({
key,
location,
preNavigateFunction,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing a a preNavigationFunction to update the problematic state

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain me how this part is working?

I mean we did avoid useEffect but how's it solving the problem?

}: GoToHotkeysProps) => {
const navigate = useNavigate();

useSequenceHotkeys(
'g',
key,
() => {
preNavigateFunction?.();
navigate(location);
},
AppHotkeyScope.Goto,
Expand Down
Loading