Skip to content

Commit 8dde7a2

Browse files
committed
global handlers
1 parent 3ddb6c3 commit 8dde7a2

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

special-pages/pages/history/app/components/App.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import { useRef } from 'preact/hooks';
77
import { Sidebar } from './Sidebar.js';
88
import { useGlobalState } from '../global-state/GlobalStateProvider.js';
99
import { useSelected } from '../global-state/SelectionProvider.js';
10+
import { useGlobalHandlers } from '../global-state/HistoryServiceProvider.js';
1011

1112
export function App() {
1213
const { isDarkMode } = useEnv();
1314
const containerRef = useRef(/** @type {HTMLElement|null} */ (null));
1415
const { ranges, term, results } = useGlobalState();
1516
const selected = useSelected();
1617

18+
useGlobalHandlers();
19+
1720
return (
1821
<div class={styles.layout} data-theme={isDarkMode ? 'dark' : 'light'}>
1922
<header class={styles.header}>

special-pages/pages/history/app/global-state/HistoryServiceProvider.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,34 @@ import { paramsToQuery, toRange } from '../history.service.js';
44
import { EVENT_RANGE_CHANGE, EVENT_SEARCH_COMMIT, KNOWN_ACTIONS, OVERSCAN_AMOUNT } from '../constants.js';
55
import { usePlatformName } from '../types.js';
66
import { eventToTarget } from '../../../../shared/handlers.js';
7+
import { useContext } from 'preact/hooks';
78

89
// Create the context
9-
const HistoryServiceContext = createContext({});
10+
const HistoryServiceContext = createContext({
11+
service: /** @type {import("../history.service.js").HistoryService} */ ({}),
12+
});
1013

1114
/**
1215
* Provides a context for the history service, allowing dependent components to access it.
1316
* Everything that interacts with the service should be registered here
1417
*
1518
* @param {Object} props
1619
* @param {import("../history.service.js").HistoryService} props.service
17-
* @param {import("../history.service.js").ServiceData} props.initial
1820
* @param {import("preact").ComponentChild} props.children
1921
*/
20-
export function HistoryServiceProvider({ service, initial, children }) {
21-
const platformName = usePlatformName();
22+
export function HistoryServiceProvider({ service, children }) {
23+
return <HistoryServiceContext.Provider value={{ service }}>{children}</HistoryServiceContext.Provider>;
24+
}
2225

26+
export function useGlobalHandlers() {
27+
const { service } = useContext(HistoryServiceContext);
28+
const platformName = usePlatformName();
2329
useSearchCommit(service);
2430
useRangeChange(service);
2531
useLinkClickHandler(service, platformName);
2632
useButtonClickHandler(service);
2733
useAuxClickHandler(service, platformName);
2834
useContextMenu(service);
29-
30-
return <HistoryServiceContext.Provider value={{ service, initial }}>{children}</HistoryServiceContext.Provider>;
3135
}
3236

3337
/**

special-pages/pages/history/app/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export async function init(root, messaging, baseEnvironment) {
7676
<MessagingContext.Provider value={messaging}>
7777
<SettingsContext.Provider value={settings}>
7878
<QueryProvider query={query.query}>
79-
<HistoryServiceProvider service={service} initial={initial}>
79+
<HistoryServiceProvider service={service}>
8080
<GlobalStateProvider service={service} initial={initial}>
8181
<SelectionProvider>
8282
<App />

0 commit comments

Comments
 (0)