Skip to content

Commit

Permalink
Replacing "Add Card" tab with "Edit Cards" sub-tab [NTP]
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanml committed Nov 13, 2020
1 parent 11a437e commit 8169346
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 128 deletions.
1 change: 0 additions & 1 deletion browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(kNewTabPageShowRewards, true);
registry->RegisterBooleanPref(kNewTabPageShowBinance, true);
registry->RegisterBooleanPref(kNewTabPageShowTogether, false);
registry->RegisterBooleanPref(kNewTabPageShowAddCard, true);
registry->RegisterBooleanPref(kNewTabPageShowGemini, true);
registry->RegisterIntegerPref(
kNewTabPageShowsOptions,
Expand Down
2 changes: 0 additions & 2 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kNewTabPageShowTogether] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kNewTabPageShowAddCard] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kNewTabPageShowGemini] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kNewTabPageShowsOptions] =
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "rewardsWidgetBrandedNotificationTitle", IDS_REWARDS_WIDGET_BRANDED_NOTIFICATION_TITLE }, // NOLINT
{ "rewardsWidgetBrandedNotificationDescription", IDS_REWARDS_WIDGET_BRANDED_NOTIFICATION_DESCRIPTION }, // NOLINT
{ "rewardsWidgetBrandedNotificationHideAction", IDS_REWARDS_WIDGET_BRANDED_NOTIFICATION_HIDE_ACTION }, // NOLINT
{ "addCardWidgetTitle", IDS_ADD_CARD_WIDGET_TITLE },
{ "editCardsTitle", IDS_EDIT_CARDS_TITLE },
{ "tosAndPp", IDS_REWARDS_WIDGET_TOS_AND_PP}, // NOLINT
{ "rewardsWidgetStartUsing", IDS_REWARDS_WIDGET_START_USING}, // NOLINT
// Together Widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ base::DictionaryValue GetPreferencesDictionary(PrefService* prefs) {
pref_data.SetBoolean(
"showTogether",
prefs->GetBoolean(kNewTabPageShowTogether));
pref_data.SetBoolean(
"showAddCard",
prefs->GetBoolean(kNewTabPageShowAddCard));
pref_data.SetBoolean(
"showGemini",
prefs->GetBoolean(kNewTabPageShowGemini));
Expand Down Expand Up @@ -339,9 +336,6 @@ void BraveNewTabMessageHandler::OnJavascriptAllowed() {
pref_change_registrar_.Add(kNewTabPageShowTogether,
base::Bind(&BraveNewTabMessageHandler::OnPreferencesChanged,
base::Unretained(this)));
pref_change_registrar_.Add(kNewTabPageShowAddCard,
base::Bind(&BraveNewTabMessageHandler::OnPreferencesChanged,
base::Unretained(this)));
pref_change_registrar_.Add(kNewTabPageShowGemini,
base::Bind(&BraveNewTabMessageHandler::OnPreferencesChanged,
base::Unretained(this)));
Expand Down Expand Up @@ -465,8 +459,6 @@ void BraveNewTabMessageHandler::HandleSaveNewTabPagePref(
settingsKey = kNewTabPageShowBinance;
} else if (settingsKeyInput == "showTogether") {
settingsKey = kNewTabPageShowTogether;
} else if (settingsKeyInput == "showAddCard") {
settingsKey = kNewTabPageShowAddCard;
} else if (settingsKeyInput == "showGemini") {
settingsKey = kNewTabPageShowGemini;
#if BUILDFLAG(MOONPAY_ENABLED)
Expand Down
1 change: 0 additions & 1 deletion common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const char kNewTabPageShowRewards[] = "brave.new_tab_page.show_rewards";
const char kNewTabPageShowBinance[] = "brave.new_tab_page.show_binance";
const char kNewTabPageShowGemini[] = "brave.new_tab_page.show_gemini";
const char kNewTabPageShowTogether[] = "brave.new_tab_page.show_together";
const char kNewTabPageShowAddCard[] = "brave.new_tab_page.show_addcard";
const char kNewTabPageShowsOptions[] = "brave.new_tab_page.shows_options";
const char kBraveTodaySources[] = "brave.today.sources";
const char kBraveEnabledMediaRouter[] = "brave.enable_media_router";
Expand Down
1 change: 0 additions & 1 deletion common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ extern const char kNewTabPageShowRewards[];
extern const char kNewTabPageShowBinance[];
extern const char kNewTabPageShowGemini[];
extern const char kNewTabPageShowTogether[];
extern const char kNewTabPageShowAddCard[];
extern const char kNewTabPageShowsOptions[];
extern const char kBraveTodaySources[];
extern const char kBraveEnabledMediaRouter[];
Expand Down
5 changes: 0 additions & 5 deletions components/brave_new_tab_ui/api/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export type Preferences = {
clockFormat: string
showTopSites: boolean
showRewards: boolean
showAddCard: boolean
isBrandedWallpaperNotificationDismissed: boolean
}

Expand Down Expand Up @@ -65,10 +64,6 @@ export function saveShowBinance (value: boolean): void {
sendSavePref('showBinance', value)
}

export function saveShowAddCard (value: boolean): void {
sendSavePref('showAddCard', value)
}

export function saveBrandedWallpaperOptIn (value: boolean): void {
sendSavePref('brandedWallpaperOptIn', value)
}
Expand Down
45 changes: 0 additions & 45 deletions components/brave_new_tab_ui/components/default/addCard/index.tsx

This file was deleted.

29 changes: 0 additions & 29 deletions components/brave_new_tab_ui/components/default/addCard/style.ts

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions components/brave_new_tab_ui/components/default/editCards/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import * as React from 'react'
import { getLocale } from '../../../../common/locale'

// Components
import {
StyledWrapper,
StyledTitle,
StyledEditIcon
} from './style'
import EditIcon from './assets/edit-icon.svg'

interface Props {
onEditCards: () => void
}

export default class EditCards extends React.PureComponent<Props, {}> {

render () {
return (
<StyledWrapper onClick={this.props.onEditCards}>
<StyledTitle>
<StyledEditIcon src={EditIcon} />
<span>
{getLocale('editCardsTitle')}
</span>
</StyledTitle>
</StyledWrapper>
)
}
}
44 changes: 44 additions & 0 deletions components/brave_new_tab_ui/components/default/editCards/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License. v. 2.0. If a copy of the MPL was not distributed with this file.
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import styled from 'brave-ui/theme'
import palette from 'brave-ui/theme/colors'

export const StyledWrapper = styled<{}, 'button'>('button')`
width: 100%;
border: none;
display: block;
margin-top: 5px;
appearance: none;
border-radius: 8px;
cursor: pointer;
backdrop-filter: blur(23px);
padding: 12px 20px;
background: linear-gradient(90deg, rgba(33, 37, 41, 0.6) 0%, rgba(33, 37, 41, 0.24) 100%);
outline: none;
&:hover {
background: rgba(33, 37, 41, 0.5);
}
&:focus-visible {
box-shadow: 0 0 0 1px ${p => p.theme.color.brandBrave};
}
`

export const StyledTitle = styled<{}, 'div'>('div')`
display: flex;
align-items: center;
width: fit-content;
font-size: 13px;
font-weight: 600;
color: ${palette.white};
margin: 0 auto;
font-family: ${p => p.theme.fontFamily.heading};
`

export const StyledEditIcon = styled<{}, 'img'>('img')`
width: 14px;
margin-right: 10px;
`
4 changes: 2 additions & 2 deletions components/brave_new_tab_ui/components/default/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { ClockWidget } from './clock'
import { RewardsWidget } from './rewards'
import { BinanceWidget } from './binance'
import { TogetherWidget } from './together'
import { AddCardWidget } from './addCard'
import { GeminiWidget } from './gemini'
import { BitcoinDotComWidget } from './bitcoinDotCom'
import { CryptoDotComWidget } from './cryptoDotCom'
import EditCards from './editCards'
import createWidget from './widget'

export * from './page'
Expand All @@ -34,7 +34,7 @@ export {
RewardsWidget,
BinanceWidget,
TogetherWidget,
AddCardWidget,
EditCards,
GeminiWidget,
BitcoinDotComWidget,
CryptoDotComWidget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type PageProps = {
showBinance: boolean
showTogether: boolean
showTopSites: boolean
showAddCard: boolean
showBrandedWallpaper: boolean
} & HasImageProps

Expand Down
1 change: 0 additions & 1 deletion components/brave_new_tab_ui/containers/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class DefaultPage extends React.Component<Props, {}> {
saveShowRewards={PreferencesAPI.saveShowRewards}
saveShowTogether={PreferencesAPI.saveShowTogether}
saveShowBinance={PreferencesAPI.saveShowBinance}
saveShowAddCard={PreferencesAPI.saveShowAddCard}
saveShowGemini={PreferencesAPI.saveShowGemini}
saveShowBitcoinDotCom={PreferencesAPI.saveShowBitcoinDotCom}
saveShowCryptoDotCom={PreferencesAPI.saveShowCryptoDotCom}
Expand Down
33 changes: 8 additions & 25 deletions components/brave_new_tab_ui/containers/newTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
RewardsWidget as Rewards,
TogetherWidget as Together,
BinanceWidget as Binance,
AddCardWidget as AddCard,
GeminiWidget as Gemini,
BitcoinDotComWidget as BitcoinDotCom,
CryptoDotComWidget as CryptoDotCom
CryptoDotComWidget as CryptoDotCom,
EditCards
} from '../../components/default'
import * as Page from '../../components/default/page'
import BrandedWallpaperLogo from '../../components/default/brandedWallpaper/logo'
Expand Down Expand Up @@ -57,7 +57,6 @@ interface Props {
saveShowRewards: (value: boolean) => void
saveShowTogether: (value: boolean) => void
saveShowBinance: (value: boolean) => void
saveShowAddCard: (value: boolean) => void
saveShowGemini: (value: boolean) => void
saveShowBitcoinDotCom: (value: boolean) => void
saveShowCryptoDotCom: (value: boolean) => void
Expand Down Expand Up @@ -257,10 +256,6 @@ class NewTabPage extends React.Component<Props, State> {
}
}

disableAddCard = () => {
this.props.saveShowAddCard(false)
}

toggleShowGemini = () => {
const { showGemini } = this.props.newTabData

Expand Down Expand Up @@ -411,7 +406,7 @@ class NewTabPage extends React.Component<Props, State> {
brandedWallpaperLogoClicked(this.props.newTabData.brandedWallpaperData)
}

openSettingsAddCard = () => {
openSettingsEditCards = () => {
this.openSettings(SettingsTabType.Cards)
}

Expand Down Expand Up @@ -710,7 +705,7 @@ class NewTabPage extends React.Component<Props, State> {
const isForeground = i === widgetList.length - 1
return (
<div key={`widget-${widget}`}>
{lookup[widget].render(isForeground, (i + 1))}
{lookup[widget].render(isForeground, i)}
</div>
)
})}
Expand Down Expand Up @@ -753,30 +748,19 @@ class NewTabPage extends React.Component<Props, State> {

renderCryptoContent () {
const { newTabData } = this.props
const { widgetStackOrder, textDirection, showAddCard } = newTabData
const { widgetStackOrder } = newTabData
const allWidgetsHidden = this.allWidgetsHidden()
const shouldShowAddCard = allWidgetsHidden ? showAddCard : true

if (!widgetStackOrder.length) {
return null
}

return (
<Page.GridItemWidgetStack>
{shouldShowAddCard &&
<AddCard
isCrypto={true}
paddingType={'none'}
menuPosition={'left'}
widgetTitle={getLocale('addCardWidgetTitle')}
textDirection={textDirection}
hideMenu={!allWidgetsHidden}
hideWidget={this.disableAddCard}
onAddCard={this.openSettingsAddCard}
stackPosition={0}
/>
}
{this.getCryptoContent()}
{!allWidgetsHidden &&
<EditCards onEditCards={this.openSettingsEditCards} />
}
</Page.GridItemWidgetStack>
)
}
Expand Down Expand Up @@ -1036,7 +1020,6 @@ class NewTabPage extends React.Component<Props, State> {
showTogether={newTabData.showTogether && newTabData.togetherSupported}
showBinance={newTabData.showBinance}
showTopSites={showTopSites}
showAddCard={newTabData.showAddCard}
showBrandedWallpaper={isShowingBrandedWallpaper}
>
{newTabData.showStats &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import geminiBanner from './assets/gemini.png'
import bitcoinDotComBanner from './assets/bitcoin-dot-com.png'
import cryptoDotComBanner from './assets/crypto-dot-com.png'
import HideIcon from './assets/hide-icon'
import AddIcon from '../../../components/default/addCard/assets/add-icon'
import { Toggle } from '../../../components/toggle'
import AddIcon from './assets/add-icon'

import { getLocale } from '../../../../common/locale'

Expand Down
Loading

0 comments on commit 8169346

Please sign in to comment.