diff --git a/components/brave_new_tab_ui/actions/new_tab_actions.ts b/components/brave_new_tab_ui/actions/new_tab_actions.ts index 609077c1bb2..55600bd0470 100644 --- a/components/brave_new_tab_ui/actions/new_tab_actions.ts +++ b/components/brave_new_tab_ui/actions/new_tab_actions.ts @@ -8,7 +8,6 @@ import { action } from 'typesafe-actions' // Constants import { types } from '../constants/new_tab_types' -import { Preferences } from '../api/preferences' import { Stats } from '../api/stats' import { PrivateTabData } from '../api/privateTabData' import { TorTabData } from '../api/torTabData' @@ -32,7 +31,7 @@ export const dismissBrandedWallpaperNotification = (isUserAction: boolean) => isUserAction }) -export const preferencesUpdated = (preferences: Preferences) => +export const preferencesUpdated = (preferences: NewTab.Preferences) => action(types.NEW_TAB_PREFERENCES_UPDATED, preferences) export const clockWidgetUpdated = (showClockWidget: boolean, diff --git a/components/brave_new_tab_ui/api/initialData.ts b/components/brave_new_tab_ui/api/initialData.ts index 5a40442d9be..5c4bd33ce99 100644 --- a/components/brave_new_tab_ui/api/initialData.ts +++ b/components/brave_new_tab_ui/api/initialData.ts @@ -10,7 +10,7 @@ import * as torTabDataAPI from './torTabData' import * as brandedWallpaper from './brandedWallpaper' export type InitialData = { - preferences: preferencesAPI.Preferences + preferences: NewTab.Preferences stats: statsAPI.Stats privateTabData: privateTabDataAPI.PrivateTabData torTabData: torTabDataAPI.TorTabData diff --git a/components/brave_new_tab_ui/api/preferences.ts b/components/brave_new_tab_ui/api/preferences.ts index 0ffc4c16921..2e3909f8327 100644 --- a/components/brave_new_tab_ui/api/preferences.ts +++ b/components/brave_new_tab_ui/api/preferences.ts @@ -10,22 +10,10 @@ // especially string keys. // -export type Preferences = { - showBackgroundImage: boolean - brandedWallpaperOptIn: boolean - showStats: boolean - showToday: boolean - showClock: boolean - clockFormat: string - showTopSites: boolean - showRewards: boolean - isBrandedWallpaperNotificationDismissed: boolean -} +type PreferencesUpdatedHandler = (prefData: NewTab.Preferences) => void -type PreferencesUpdatedHandler = (prefData: Preferences) => void - -export function getPreferences (): Promise { - return window.cr.sendWithPromise('getNewTabPagePreferences') +export function getPreferences (): Promise { + return window.cr.sendWithPromise('getNewTabPagePreferences') } function sendSavePref (key: string, value: any) { diff --git a/components/brave_new_tab_ui/apiEventsToStore.ts b/components/brave_new_tab_ui/apiEventsToStore.ts index 9b329d8c7a8..a814d85303c 100644 --- a/components/brave_new_tab_ui/apiEventsToStore.ts +++ b/components/brave_new_tab_ui/apiEventsToStore.ts @@ -11,7 +11,7 @@ import * as privateTabDataAPI from './api/privateTabData' import * as torTabDataAPI from './api/torTabData' import { getInitialData, getRewardsInitialData, getRewardsPreInitialData } from './api/initialData' -async function updatePreferences (prefData: preferencesAPI.Preferences) { +async function updatePreferences (prefData: NewTab.Preferences) { getActions().preferencesUpdated(prefData) } @@ -27,7 +27,7 @@ async function updateTorTabData (data: torTabDataAPI.TorTabData) { getActions().torTabDataUpdated(data) } -function onRewardsToggled (prefData: preferencesAPI.Preferences): void { +function onRewardsToggled (prefData: NewTab.Preferences): void { if (prefData.showRewards) { rewardsInitData() } diff --git a/components/brave_new_tab_ui/reducers/new_tab_reducer.ts b/components/brave_new_tab_ui/reducers/new_tab_reducer.ts index 3f021a8f45f..8f1c4b42860 100644 --- a/components/brave_new_tab_ui/reducers/new_tab_reducer.ts +++ b/components/brave_new_tab_ui/reducers/new_tab_reducer.ts @@ -124,7 +124,7 @@ export const newTabReducer: Reducer = (state: NewTab.S break case types.NEW_TAB_PREFERENCES_UPDATED: - const preferences = payload as preferencesAPI.Preferences + const preferences = payload as NewTab.Preferences const newState = { ...state, ...preferences diff --git a/components/definitions/newTab.d.ts b/components/definitions/newTab.d.ts index ce52b2bf189..a6d496265c8 100644 --- a/components/definitions/newTab.d.ts +++ b/components/definitions/newTab.d.ts @@ -91,7 +91,19 @@ declare namespace NewTab { cryptoDotComState: CryptoDotComWidgetState } - export interface EphemeralState { + export type Preferences = { + showBackgroundImage: boolean + brandedWallpaperOptIn: boolean + showStats: boolean + showToday: boolean + showClock: boolean + clockFormat: string + showTopSites: boolean + showRewards: boolean + isBrandedWallpaperNotificationDismissed: boolean + } + + export type EphemeralState = Preferences & { initialDataLoaded: boolean textDirection: string featureFlagBraveNTPSponsoredImagesWallpaper: boolean @@ -105,20 +117,12 @@ declare namespace NewTab { gridLayoutSize?: 'small' showGridSiteRemovedNotification?: boolean showBackgroundImage: boolean - showStats: boolean - showToday: boolean - showClock: boolean - clockFormat: string - showTopSites: boolean customLinksEnabled: boolean - showRewards: boolean showTogether: boolean showBinance: boolean showGemini: boolean showBitcoinDotCom: boolean showCryptoDotCom: boolean, - brandedWallpaperOptIn: boolean - isBrandedWallpaperNotificationDismissed: boolean stats: Stats, brandedWallpaperData?: BrandedWallpaper }