Skip to content

Commit

Permalink
redirect to manage tab from context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat committed Mar 6, 2024
1 parent 4a168da commit 6a5958e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/library/ContextMenu/Wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ListWrapper = styled.ul`
list-style: none;
display: flex;
flex-direction: column;
padding: 0 0.35rem 0.35rem 0.35rem;
padding: 0.2rem 0.35rem 0.2rem 0.35rem;
margin: 0;
width: 100%;
Expand Down
23 changes: 19 additions & 4 deletions src/library/Page/provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import type { SectionContextInterface, SectionContextProps } from './types';
import * as local from './Local';
import { useEffectIgnoreInitial } from '@w3ux/hooks';
import { useTabs } from 'contexts/Tabs';
import { extractUrlValue, removeVarFromUrlHash } from '@w3ux/utils';
import { useLocation } from 'react-router-dom';
import { useMenu } from 'contexts/Menu';

export const SectionContext = createContext<SectionContextInterface>(
defaultSectionContext
Expand All @@ -15,6 +18,8 @@ export const SectionContext = createContext<SectionContextInterface>(
export const useSection = () => useContext(SectionContext);

export const SectionProvider = ({ pageId, children }: SectionContextProps) => {
const { open: menuOpen } = useMenu();
const { hash } = useLocation();
const { activeTabId } = useTabs();

// The active section of the page.
Expand All @@ -31,11 +36,21 @@ export const SectionProvider = ({ pageId, children }: SectionContextProps) => {
};

// Updates active section when active tab changes.
const redirectHash = extractUrlValue('redirect');

useEffectIgnoreInitial(() => {
setActiveSection(
local.getActiveSection(pageId, activeTabId) || defaultActiveSection
);
}, [pageId, activeTabId]);
if (redirectHash === 'manage-tab') {
if (!menuOpen) {
console.log(redirectHash, hash);
setActiveSection(1, false);
removeVarFromUrlHash('redirect');
}
} else {
setActiveSection(
local.getActiveSection(pageId, activeTabId) || defaultActiveSection
);
}
}, [pageId, activeTabId, menuOpen]);

return (
<SectionContext.Provider
Expand Down
29 changes: 0 additions & 29 deletions src/library/Tabs/Menu.tsx

This file was deleted.

18 changes: 15 additions & 3 deletions src/library/Tabs/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useTabs } from 'contexts/Tabs';
import { useMenu } from 'contexts/Menu';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faClose } from '@fortawesome/free-solid-svg-icons';
import { Menu } from './Menu';
import { TabMenu } from './TabMenu';
import type { TabProps } from './types';
import { useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
Expand All @@ -18,6 +18,7 @@ import {
} from 'contexts/Tabs/defaults';
import { useApi } from 'contexts/Api';
import { ConnectionIcon } from './ConectionIcon';
import { useNavigate } from 'react-router-dom';

export const Tab = ({ index, id, name, initial = false }: TabProps) => {
const {
Expand All @@ -33,8 +34,9 @@ export const Tab = ({ index, id, name, initial = false }: TabProps) => {
setActiveTabIndex,
addInstantiatedId,
} = useTabs();
const { openMenu } = useMenu();
const navigate = useNavigate();
const { getApiStatus } = useApi();
const { openMenu, closeMenu } = useMenu();

const {
listeners,
Expand Down Expand Up @@ -84,7 +86,17 @@ export const Tab = ({ index, id, name, initial = false }: TabProps) => {
// Handle context menu when tab is right clicked.
const handleTabContextMenu = (ev: MouseEvent): void => {
ev.preventDefault();
openMenu(ev, <Menu />);
openMenu(
ev,
<TabMenu
tabId={id}
onSettings={() => {
setActiveTabId(id);
navigate(`?redirect=manage-tab`);
closeMenu();
}}
/>
);
};

// Context menu ref.
Expand Down
28 changes: 28 additions & 0 deletions src/library/Tabs/TabMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { faBarsProgress } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { ListWrapper, SelectListWrapper } from 'library/ContextMenu/Wrappers';

export const TabMenu = ({
// tabId,
onSettings,
}: {
tabId: number;
onSettings: () => void;
}) => (
<SelectListWrapper>
<ListWrapper>
<li>
<button onClick={() => onSettings()}></button>
<div className="inner">
<div className="none"></div>
<div>
<h3>Manage Tab</h3>
</div>
<div>
<FontAwesomeIcon icon={faBarsProgress} transform="shrink-2" />
</div>
</div>
</li>
</ListWrapper>
</SelectListWrapper>
);

0 comments on commit 6a5958e

Please sign in to comment.