Skip to content

Commit 294a279

Browse files
authored
ntp: fixing components iew (#1335)
* ntp: fixing components iew * more fixes
1 parent b2fd6ff commit 294a279

File tree

6 files changed

+60
-37
lines changed

6 files changed

+60
-37
lines changed

special-pages/pages/new-tab/app/components/Components.jsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Fragment, h } from 'preact';
22
import styles from './Components.module.css';
33
import { mainExamples, otherExamples } from './Examples.jsx';
4+
import { useThemes } from '../customizer/themes.js';
5+
import { useSignal } from '@preact/signals';
6+
import { BackgroundConsumer } from './BackgroundProvider.js';
47
const url = new URL(window.location.href);
58

69
const list = {
@@ -15,19 +18,31 @@ export function Components() {
1518
const isolated = url.searchParams.has('isolate');
1619
const e2e = url.searchParams.has('e2e');
1720
const entryIds = entries.map(([id]) => id);
18-
1921
const validIds = ids.filter((id) => entryIds.includes(id));
20-
2122
const filtered = validIds.length ? validIds.map((id) => /** @type {const} */ ([id, list[id]])) : entries;
2223

23-
if (isolated) {
24-
return <Isolated entries={filtered} e2e={e2e} />;
25-
}
24+
/** @type {import('../../types/new-tab').CustomizerData} */
25+
const data = {
26+
background: { kind: 'default' },
27+
userImages: [],
28+
theme: 'system',
29+
userColor: null,
30+
};
31+
const dataSignal = useSignal(data);
32+
const { main, browser } = useThemes(dataSignal);
2633

2734
return (
28-
<div>
29-
<DebugBar id={ids[0]} ids={ids} entries={entries} />
30-
<Stage entries={/** @type {any} */ (filtered)} />
35+
<div class={styles.main} data-main-scroller data-theme={main}>
36+
<BackgroundConsumer browser={browser} />
37+
<div data-content-tube class={styles.contentTube}>
38+
{isolated && <Isolated entries={filtered} e2e={e2e} />}
39+
{!isolated && (
40+
<Fragment>
41+
<DebugBar id={ids[0]} ids={ids} entries={entries} />
42+
<Stage entries={/** @type {any} */ (filtered)} />
43+
</Fragment>
44+
)}
45+
</div>
3146
</div>
3247
);
3348
}

special-pages/pages/new-tab/app/components/Components.module.css

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
body[data-display="components"] {
44
padding-left: 0;
55
padding-right: 0;
6+
7+
a {
8+
color: var(--ntp-text-normal);
9+
}
10+
}
11+
12+
.main {
13+
height: 100vh;
14+
overflow: auto;
15+
color: var(--ntp-text-normal);
16+
}
17+
18+
19+
.contentTube {
20+
position: relative;
21+
z-index: 1;
622
}
723

824
.componentList {
@@ -15,8 +31,6 @@ body[data-display="components"] {
1531
display: grid;
1632
grid-template-columns: auto;
1733
grid-row-gap: 2rem;
18-
19-
2034
}
2135

2236
.itemInfo {

special-pages/pages/new-tab/app/favorites/components/Favorites.examples.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
import { h } from 'preact';
2-
import { noop } from '../../utils.js';
32
import { favorites } from '../mocks/favorites.data.js';
43
import { MockFavoritesProvider } from '../mocks/MockFavoritesProvider.js';
5-
import { FavoritesMemo } from './Favorites.js';
64
import { FavoritesConsumer } from './FavoritesCustomized.js';
75

86
/** @type {Record<string, {factory: () => import("preact").ComponentChild}>} */
97

108
export const favoritesExamples = {
11-
'favorites.no-dnd': {
12-
factory: () => (
13-
<FavoritesMemo
14-
favorites={favorites.many.favorites}
15-
expansion={'expanded'}
16-
toggle={noop('toggle')}
17-
add={noop('add')}
18-
openFavorite={noop('openFavorite')}
19-
openContextMenu={noop('openContextMenu')}
20-
/>
21-
),
22-
},
239
'favorites.dnd': {
2410
factory: () => (
2511
<MockFavoritesProvider data={favorites.many}>

special-pages/pages/new-tab/app/favorites/components/Favorites.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ function Inner({ rows, safeAreaRef, rowHeight, add }) {
180180
const gridOffset = useRef(0);
181181

182182
useLayoutEffect(() => {
183-
const mainScroller = document.querySelector('[data-main-scroller]');
184-
const contentTube = document.querySelector('[data-content-tube]');
183+
const mainScroller = document.querySelector('[data-main-scroller]') || document.documentElement;
184+
const contentTube = document.querySelector('[data-content-tube]') || document.body;
185185
if (!mainScroller) return console.warn('cannot find scrolling element');
186186
if (!contentTube) return console.warn('cannot find content tube');
187187

special-pages/pages/new-tab/app/favorites/components/FavoritesProvider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const FavoritesContext = createContext({
4848
},
4949
/** @type {(cb: (data: FavoritesConfig) => void) => void} */
5050
onConfigChanged: (cb) => {
51-
throw new Error('must implement add');
51+
/** noop */
5252
},
5353
});
5454

special-pages/pages/new-tab/app/favorites/mocks/MockFavoritesProvider.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { h } from 'preact';
22
import { FavoritesContext, FavoritesDispatchContext } from '../components/FavoritesProvider.js';
3-
import { useCallback, useReducer } from 'preact/hooks';
3+
import { useCallback, useReducer, useState } from 'preact/hooks';
44
import { useEnv } from '../../../../../shared/components/EnvironmentProvider.js';
55
import { favorites } from './favorites.data.js';
66
import { reducer } from '../../service.hooks.js';
@@ -33,16 +33,20 @@ export function MockFavoritesProvider({ data = favorites.many, config = DEFAULT_
3333
config,
3434
});
3535

36+
const [et] = useState(() => new EventTarget());
37+
3638
/** @type {[State, import('preact/hooks').Dispatch<Events>]} */
3739
const [state, dispatch] = useReducer(reducer, initial);
3840

3941
const toggle = useCallback(() => {
4042
if (state.status !== 'ready') return;
41-
if (state.config.expansion === 'expanded') {
42-
dispatch({ kind: 'config', config: { ...state.config, expansion: 'collapsed' } });
43-
} else {
44-
dispatch({ kind: 'config', config: { ...state.config, expansion: 'expanded' } });
45-
}
43+
const next =
44+
state.config.expansion === 'expanded'
45+
? /** @type {const} */ ({ ...state.config, expansion: 'collapsed' })
46+
: /** @type {const} */ ({ ...state.config, expansion: 'expanded' });
47+
48+
dispatch({ kind: 'config', config: next });
49+
et.dispatchEvent(new CustomEvent('state-update', { detail: next }));
4650
}, [state.status, state.config?.expansion, isReducedMotion]);
4751

4852
/** @type {import('../components/FavoritesProvider.js').ReorderFn<Favorite>} */
@@ -65,10 +69,14 @@ export function MockFavoritesProvider({ data = favorites.many, config = DEFAULT_
6569
console.log('noop add', ...args);
6670
};
6771

68-
const onConfigChanged = () => {
69-
/* no-op */
70-
return () => {};
71-
};
72+
const onConfigChanged = useCallback(
73+
(cb) => {
74+
et.addEventListener('state-update', (/** @type {CustomEvent<any>} */ e) => {
75+
cb(e.detail);
76+
});
77+
},
78+
[et],
79+
);
7280

7381
return (
7482
<FavoritesContext.Provider value={{ state, toggle, favoritesDidReOrder, openContextMenu, openFavorite, add, onConfigChanged }}>

0 commit comments

Comments
 (0)