Skip to content

Commit

Permalink
Apply prettier after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
muodov committed Nov 4, 2024
1 parent 6ebad46 commit 055c9f7
Show file tree
Hide file tree
Showing 20 changed files with 193 additions and 219 deletions.
30 changes: 15 additions & 15 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ export default tseslint.config(
...tseslint.configs.recommended,
{
ignores: [
"**/build/",
"**/docs/",
"injected/lib",
"Sources/ContentScopeScripts/dist/",
"injected/integration-test/extension/contentScope.js",
"injected/integration-test/test-pages/duckplayer/scripts/dist",
"special-pages/pages/**/public",
"special-pages/playwright-report/",
"special-pages/test-results/",
"special-pages/types/",
"special-pages/messages/",
"playwright-report",
"test-results",
"injected/src/types",
".idea"
'**/build/',
'**/docs/',
'injected/lib',
'Sources/ContentScopeScripts/dist/',
'injected/integration-test/extension/contentScope.js',
'injected/integration-test/test-pages/duckplayer/scripts/dist',
'special-pages/pages/**/public',
'special-pages/playwright-report/',
'special-pages/test-results/',
'special-pages/types/',
'special-pages/messages/',
'playwright-report',
'test-results',
'injected/src/types',
'.idea',
],
},
{
Expand Down
4 changes: 2 additions & 2 deletions special-pages/messages/new-tab/examples/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const privacyStatsData = {
* @type {import("../../../types/new-tab").StatsConfig}
*/
const minimumConfig = {
expansion: "expanded",
animation: { kind: "none" }
expansion: 'expanded',
animation: { kind: 'none' },
}

/**
Expand Down
26 changes: 12 additions & 14 deletions special-pages/pages/new-tab/app/components/Components.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import { Fragment, h } from "preact";
import styles from "./Components.module.css";
import { mainExamples, otherExamples } from "./Examples.jsx";
import { updateNotificationExamples } from "../update-notification/UpdateNotification.examples.js";
const url = new URL(window.location.href);
import { Fragment, h } from 'preact'
import styles from './Components.module.css'
import { mainExamples, otherExamples } from './Examples.jsx'
import { updateNotificationExamples } from '../update-notification/UpdateNotification.examples.js'
const url = new URL(window.location.href)

const list = {
...mainExamples,
...otherExamples,
...updateNotificationExamples
...updateNotificationExamples,
}

const entries = Object.entries(list);
const entries = Object.entries(list)

export function Components() {
const ids = url.searchParams.getAll("id");
const isolated = url.searchParams.has("isolate");
const e2e = url.searchParams.has("e2e");
const entryIds = entries.map(([id]) => id);
const ids = url.searchParams.getAll('id')
const isolated = url.searchParams.has('isolate')
const e2e = url.searchParams.has('e2e')
const entryIds = entries.map(([id]) => id)

const validIds = ids.filter((id) => entryIds.includes(id))

const filtered = validIds.length
? validIds.map((id) => /** @type {const} */([id, list[id]]))
: entries
const filtered = validIds.length ? validIds.map((id) => /** @type {const} */ ([id, list[id]])) : entries

if (isolated) {
return <Isolated entries={filtered} e2e={e2e} />
Expand Down
8 changes: 2 additions & 6 deletions special-pages/pages/new-tab/app/components/Layout.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { h } from 'preact'

export function Centered ({ children }) {
return (
<div class="layout-centered">
{children}
</div>
)
export function Centered({ children }) {
return <div class="layout-centered">{children}</div>
}
6 changes: 3 additions & 3 deletions special-pages/pages/new-tab/app/customizer/Customizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export function useContextMenu() {
const items = getItems()
/** @type {VisibilityMenuItem[]} */
const simplified = items
.filter(x => x.id !== 'debug')
.map(item => {
.filter((x) => x.id !== 'debug')
.map((item) => {
return {
id: item.id,
title: item.title
title: item.title,
}
})
messaging.contextMenu({ visibilityMenuItems: simplified })
Expand Down
4 changes: 2 additions & 2 deletions special-pages/pages/new-tab/app/entry-points/favorites.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { h } from 'preact'
import { FavoritesCustomized } from '../favorites/Favorites.js'
import { Centered } from '../components/Layout.js'

export function factory () {
export function factory() {
return (
<Centered>
<FavoritesCustomized/>
<FavoritesCustomized />
</Centered>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { h } from 'preact'
import { PrivacyStatsCustomized } from '../privacy-stats/PrivacyStats.js'
import { Centered } from '../components/Layout.js'

export function factory () {
export function factory() {
return (
<Centered>
<PrivacyStatsCustomized />
Expand Down
4 changes: 2 additions & 2 deletions special-pages/pages/new-tab/app/entry-points/rmf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Centered } from '../components/Layout.js'
import { RMFConsumer } from '../remote-messaging-framework/RemoteMessagingFramework.js'
import { RMFProvider } from '../remote-messaging-framework/RMFProvider.js'

export function factory () {
export function factory() {
return (
<Centered>
<RMFProvider>
<RMFConsumer/>
<RMFConsumer />
</RMFProvider>
</Centered>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { h } from 'preact'
import { UpdateNotificationConsumer } from '../update-notification/UpdateNotification.js'
import { UpdateNotificationProvider } from '../update-notification/UpdateNotificationProvider.js'

export function factory () {
export function factory() {
return (
<UpdateNotificationProvider>
<UpdateNotificationConsumer />
Expand Down
4 changes: 3 additions & 1 deletion special-pages/pages/new-tab/app/favorites/Favorites.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export function FavoritesCustomized() {
return null
}
return (
<p>Favourites here... (id: <code>{id}</code>)</p>
<p>
Favourites here... (id: <code>{id}</code>)
</p>
)
}
20 changes: 12 additions & 8 deletions special-pages/pages/new-tab/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import enStrings from '../src/locales/en/newtab.json'
import { WidgetConfigProvider } from './widget-list/widget-config.provider.js'
import { Settings } from './settings.js'
import { Components } from './components/Components.jsx'
import { widgetEntryPoint } from "./widget-list/WidgetList.js";
import { widgetEntryPoint } from './widget-list/WidgetList.js'

/**
* @param {import("../src/js").NewTabPage} messaging
Expand Down Expand Up @@ -67,7 +67,6 @@ export async function init(messaging, baseEnvironment) {

document.body.dataset.platformName = settings.platform.name


if (environment.display === 'components') {
document.body.dataset.display = 'components'
return render(
Expand All @@ -84,15 +83,15 @@ export async function init(messaging, baseEnvironment) {

const entryPoints = await (async () => {
try {
const loaders = init.widgets.map(widget => {
return widgetEntryPoint(widget.id).then(mod => [widget.id, mod]);
const loaders = init.widgets.map((widget) => {
return widgetEntryPoint(widget.id).then((mod) => [widget.id, mod])
})
const entryPoints = await Promise.all(loaders)
return Object.fromEntries(entryPoints);
return Object.fromEntries(entryPoints)
} catch (e) {
const error = new Error('Error loading widget entry points:' + e.message);
const error = new Error('Error loading widget entry points:' + e.message)
didCatch(error)
console.error(error);
console.error(error)
return {}
}
})()
Expand All @@ -110,7 +109,12 @@ export async function init(messaging, baseEnvironment) {
<InitialSetupContext.Provider value={init}>
<SettingsProvider settings={settings}>
<TranslationProvider translationObject={strings} fallback={strings} textLength={environment.textLength}>
<WidgetConfigProvider api={widgetConfigAPI} widgetConfigs={init.widgetConfigs} widgets={init.widgets} entryPoints={entryPoints}>
<WidgetConfigProvider
api={widgetConfigAPI}
widgetConfigs={init.widgetConfigs}
widgets={init.widgets}
entryPoints={entryPoints}
>
<App />
</WidgetConfigProvider>
</TranslationProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Cross } from '../components/Icons.js'
export function RemoteMessagingFramework({ message, primaryAction, secondaryAction, dismiss }) {
const { id, messageType, titleText, descriptionText } = message
return (
<div id={id} class={cn(styles.root, (messageType !== 'small' && message.icon) && styles.icon)}>
<div id={id} class={cn(styles.root, messageType !== 'small' && message.icon && styles.icon)}>
{messageType !== 'small' && message.icon && (
<span class={styles.iconBlock}>
<img src={`./icons/${message.icon}.svg`} alt="" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ import { noop } from '../utils.js'
export const updateNotificationExamples = {
empty: {
factory: () => {
return <UpdateNotification
notes={[]}
version={'1.2.3'}
dismiss={noop('dismiss!')}
/>
}
return <UpdateNotification notes={[]} version={'1.2.3'} dismiss={noop('dismiss!')} />
},
},
populated: {
factory: () => {
return <UpdateNotification
notes={['Bug Fixed and Updates']}
version={'1.2.3'}
dismiss={noop('dismiss!')}
/>
}
}
return <UpdateNotification notes={['Bug Fixed and Updates']} version={'1.2.3'} dismiss={noop('dismiss!')} />
},
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function UpdateNotification({ notes, dismiss, version }) {
)
}

export function WithNotes ({ notes, version }) {
export function WithNotes({ notes, version }) {
const id = useId()
const ref = useRef(/** @type {HTMLDetailsElement|null} */ (null))
const { t } = useTypedTranslation()
Expand Down Expand Up @@ -79,13 +79,7 @@ export function UpdateNotificationConsumer() {

// `state.data.content` can be empty - meaning there's no message to display!
if (state.status === 'ready' && state.data.content) {
return (
<UpdateNotification
notes={state.data.content.notes}
version={state.data.content.version}
dismiss={dismiss}
/>
)
return <UpdateNotification notes={state.data.content.notes} version={state.data.content.version} dismiss={dismiss} />
}
return null
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class UpdateNotificationService {
*/
dismiss() {
this.ntp.messaging.notify('updateNotification_dismiss')
this.dataService.update(_old => {

this.dataService.update((_old) => {
return { content: null }
})
}
Expand Down
30 changes: 9 additions & 21 deletions special-pages/pages/new-tab/app/widget-list/WidgetList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@ import { Fragment, h } from 'preact'
import { WidgetConfigContext, WidgetVisibilityProvider } from './widget-config.provider.js'
import { useContext } from 'preact/hooks'
import { Stack } from '../../../onboarding/app/components/Stack.js'
import {
Customizer,
CustomizerMenuPositionedFixed
} from '../customizer/Customizer.js'
import { Customizer, CustomizerMenuPositionedFixed } from '../customizer/Customizer.js'

/**
* @param {string} id
* @return {{factory: () => import("preact").ComponentChild}}
*/
function placeholderWidget (id) {
function placeholderWidget(id) {
return {
factory: () => {
return <p>Entry point for {id} was not found. This is a bug.</p>
}
},
}
}

/**
* @param {string} id
* @return {Promise<{factory: () => import("preact").ComponentChild}>}
*/
export async function widgetEntryPoint (id) {
export async function widgetEntryPoint(id) {
try {

const mod = await import(`../entry-points/${id}.js`)
if (typeof mod.factory !== 'function') {
console.error(`module found for ${id}, but missing 'factory' export`)
Expand All @@ -36,30 +32,22 @@ export async function widgetEntryPoint (id) {
console.error(e)
return placeholderWidget(id)
}
};
}

export function WidgetList () {
export function WidgetList() {
const { widgets, widgetConfigItems, entryPoints } = useContext(WidgetConfigContext)

return (
<Stack gap={'var(--sp-8)'}>
{widgets.map((widget, index) => {
const matchingConfig = widgetConfigItems.find(item => item.id === widget.id)
const matchingConfig = widgetConfigItems.find((item) => item.id === widget.id)
const matchingEntryPoint = entryPoints[widget.id]
if (!matchingConfig) {
return (
<Fragment key={widget.id}>
{matchingEntryPoint.factory?.()}
</Fragment>
)
return <Fragment key={widget.id}>{matchingEntryPoint.factory?.()}</Fragment>
}
return (
<Fragment key={widget.id}>
<WidgetVisibilityProvider
visibility={matchingConfig.visibility}
id={matchingConfig.id}
index={index}
>
<WidgetVisibilityProvider visibility={matchingConfig.visibility} id={matchingConfig.id} index={index}>
{matchingEntryPoint.factory?.()}
</WidgetVisibilityProvider>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export const WidgetConfigContext = createContext({

/** @type {(id:string) => void} */

toggle: (_id) => {

toggle: (_id) => {},
})

Expand Down Expand Up @@ -56,14 +54,16 @@ export function WidgetConfigProvider(props) {
}

return (
<WidgetConfigContext.Provider value={{
// this field is static for the lifespan of the page
widgets: props.widgets,
entryPoints: props.entryPoints,
// this will be updated via subscriptions
widgetConfigItems: data || [],
toggle
}}>
<WidgetConfigContext.Provider
value={{
// this field is static for the lifespan of the page
widgets: props.widgets,
entryPoints: props.entryPoints,
// this will be updated via subscriptions
widgetConfigItems: data || [],
toggle,
}}
>
{props.children}
</WidgetConfigContext.Provider>
)
Expand Down
Loading

0 comments on commit 055c9f7

Please sign in to comment.