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

Update Electron help menu to reflect new in-app menu #3699

Merged
merged 4 commits into from
Oct 23, 2024
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
26 changes: 2 additions & 24 deletions packages/desktop-client/src/components/HelpMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { forwardRef, useRef } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import { Trans, useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { useLocation } from 'react-router-dom';

import { useToggle } from 'usehooks-ts';

import { openDocsForCurrentPage } from 'loot-core/client/actions';
import { pushModal } from 'loot-core/client/actions/modals';

import { SvgHelp } from '../icons/v2/Help';
import { openUrl } from '../util/router-tools';

import { Button } from './common/Button2';
import { Menu } from './common/Menu';
Expand Down Expand Up @@ -45,38 +44,17 @@ const HelpButton = forwardRef<HTMLButtonElement, HelpButtonProps>(

HelpButton.displayName = 'HelpButton';

const getPageDocs = (page: string) => {
switch (page) {
case '/budget':
return 'https://actualbudget.org/docs/getting-started/envelope-budgeting';
case '/reports':
return 'https://actualbudget.org/docs/reports/';
case '/schedules':
return 'https://actualbudget.org/docs/schedules';
case '/payees':
return 'https://actualbudget.org/docs/transactions/payees';
case '/rules':
return 'https://actualbudget.org/docs/budgeting/rules';
case '/settings':
return 'https://actualbudget.org/docs/settings';
default:
// All pages under /accounts, plus any missing pages
return 'https://actualbudget.org/docs';
}
};

export const HelpMenu = () => {
const { t } = useTranslation();
const [isMenuOpen, toggleMenuOpen, setMenuOpen] = useToggle();
const menuButtonRef = useRef(null);

const dispatch = useDispatch();
const page = useLocation().pathname;

const handleItemSelect = (item: HelpMenuItem) => {
switch (item) {
case 'docs':
openUrl(getPageDocs(page));
dispatch(openDocsForCurrentPage());
break;
case 'keyboard-shortcuts':
dispatch(pushModal('keyboard-shortcuts'));
Expand Down
7 changes: 5 additions & 2 deletions packages/desktop-client/src/components/Titlebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { css } from '@emotion/css';
import * as Platform from 'loot-core/src/client/platform';
import * as queries from 'loot-core/src/client/queries';
import { listen } from 'loot-core/src/platform/client/fetch';
import { isDevelopmentEnvironment } from 'loot-core/src/shared/environment';
import {
isDevelopmentEnvironment,
isElectron,
} from 'loot-core/src/shared/environment';

import { useActions } from '../hooks/useActions';
import { useGlobalPref } from '../hooks/useGlobalPref';
Expand Down Expand Up @@ -340,7 +343,7 @@ export function Titlebar({ style }: TitlebarProps) {
<PrivacyButton />
{serverURL ? <SyncButton /> : null}
<LoggedInUser />
<HelpMenu />
{!isElectron() && <HelpMenu />}
</SpaceBetween>
</View>
);
Expand Down
4 changes: 0 additions & 4 deletions packages/desktop-client/src/util/router-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ export function ExposeNavigate() {
}, [navigate]);
return null;
}

export function openUrl(url: string) {
window.open(url, '_blank', 'noopener,noreferrer');
}
27 changes: 10 additions & 17 deletions packages/desktop-electron/menu.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
MenuItemConstructorOptions,
Menu,
ipcMain,
app,
shell,
} from 'electron';
import { MenuItemConstructorOptions, Menu, ipcMain, app } from 'electron';

export function getMenu(
isDev: boolean,
Expand Down Expand Up @@ -173,7 +167,15 @@ export function getMenu(
role: 'help',
submenu: [
{
label: 'Keyboard Shortcuts Reference',
label: 'Documentation',
click(_menuItem, focusedWin) {
focusedWin?.webContents.executeJavaScript(
'window.__actionsForMenu && window.__actionsForMenu.openDocsForCurrentPage()',
);
},
},
{
label: 'Keyboard Shortcuts',
jfdoming marked this conversation as resolved.
Show resolved Hide resolved
accelerator: '?',
enabled: !!budgetId,
click: function (_menuItem, focusedWin) {
Expand All @@ -184,15 +186,6 @@ export function getMenu(
}
},
},
{
type: 'separator',
},
{
label: 'Learn More',
click() {
shell.openExternal('https://actualbudget.org/docs/');
},
},
],
},
];
Expand Down
26 changes: 26 additions & 0 deletions packages/loot-core/src/client/actions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,29 @@ export function reloadApp() {
global.Actual.reload();
};
}

const getPageDocs = (page: string) => {
switch (page) {
case '/budget':
return 'https://actualbudget.org/docs/getting-started/envelope-budgeting';
case '/reports':
return 'https://actualbudget.org/docs/reports/';
case '/schedules':
return 'https://actualbudget.org/docs/schedules';
case '/payees':
return 'https://actualbudget.org/docs/transactions/payees';
case '/rules':
return 'https://actualbudget.org/docs/budgeting/rules';
case '/settings':
return 'https://actualbudget.org/docs/settings';
default:
// All pages under /accounts, plus any missing pages
return 'https://actualbudget.org/docs';
}
};
jfdoming marked this conversation as resolved.
Show resolved Hide resolved

export function openDocsForCurrentPage() {
return () => {
global.Actual.openURLInBrowser(getPageDocs(window.location.pathname));
};
}
jfdoming marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions upcoming-release-notes/3699.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [jfdoming]
---

Update Electron help menu to reflect new in-app menu