Skip to content

Commit

Permalink
Uplift of #5490 (squashed) to beta
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-browser-releases committed May 11, 2020
1 parent 394e28a commit 53ceabf
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 377 deletions.
28 changes: 0 additions & 28 deletions components/brave_new_tab_ui/actions/grid_sites_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
import { types } from '../constants/grid_sites_types'
import { action } from 'typesafe-actions'
import { InitialData } from '../api/initialData'
import { Dispatch } from 'redux'

// API
import {
fetchAllBookmarkTreeNodes,
updateBookmarkTreeNode
} from '../api/bookmarks'

export const setFirstRenderGridSitesData = (initialData: InitialData) => {
return action(types.GRID_SITES_SET_FIRST_RENDER_DATA, initialData)
Expand All @@ -39,27 +32,6 @@ export const undoRemoveAllGridSites = () => {
return action(types.GRID_SITES_UNDO_REMOVE_ALL_SITES)
}

export const updateGridSitesBookmarkInfo = (
sites: chrome.topSites.MostVisitedURL[]
) => {
return async (dispatch: Dispatch) => {
const bookmarkInfo = await fetchAllBookmarkTreeNodes(sites)
dispatch(action(types.GRID_SITES_UPDATE_SITE_BOOKMARK_INFO, {
bookmarkInfo
}))
}
}

export const toggleGridSiteBookmarkInfo = (site: NewTab.Site) => {
return async (dispatch: Dispatch) => {
const bookmarkInfo = await updateBookmarkTreeNode(site)
dispatch(action(types.GRID_SITES_TOGGLE_SITE_BOOKMARK_INFO, {
url: site.url,
bookmarkInfo
}))
}
}

export const addGridSites = (site: NewTab.Site) => {
return action(types.GRID_SITES_ADD_SITES, { site })
}
Expand Down
47 changes: 0 additions & 47 deletions components/brave_new_tab_ui/api/bookmarks.ts

This file was deleted.

1 change: 0 additions & 1 deletion components/brave_new_tab_ui/apiEventsToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function wireApiEventsToStore () {
binanceInitData()
getActions().setInitialData(initialData)
getActions().setFirstRenderGridSitesData(initialData)
getActions().updateGridSitesBookmarkInfo(initialData.topSites)
// Listen for API changes and dispatch to store
statsAPI.addChangeListener(updateStats)
preferencesAPI.addChangeListener(updatePreferences)
Expand Down
4 changes: 0 additions & 4 deletions components/brave_new_tab_ui/constants/grid_sites_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export const enum types {
GRID_SITES_UNDO_REMOVE_SITE = '@@topSites/GRID_SITES_UNDO_REMOVE_SITE',
GRID_SITES_UNDO_REMOVE_ALL_SITES =
'@@topSites/GRID_SITES_UNDO_REMOVE_ALL_SITES',
GRID_SITES_UPDATE_SITE_BOOKMARK_INFO =
'@@topSites/GRID_SITES_UPDATE_SITE_BOOKMARK_INFO',
GRID_SITES_TOGGLE_SITE_BOOKMARK_INFO =
'@@topSites/GRID_SITES_TOGGLE_SITE_BOOKMARK_INFO',
GRID_SITES_ADD_SITES = '@@topSites/GRID_SITES_ADD_SITES',
GRID_SITES_SHOW_SITE_REMOVED_NOTIFICATION =
'@@topSites/GRID_SITES_SHOW_SITE_REMOVED_NOTIFICATION'
Expand Down
16 changes: 1 addition & 15 deletions components/brave_new_tab_ui/containers/newTab/gridTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ import {

// Helpers
import {
isGridSitePinned,
isGridSiteBookmarked
isGridSitePinned
} from '../../helpers/newTabUtils'

// Icons
import {
PinIcon,
PinOIcon,
BookmarkIcon,
BookmarkOIcon,
CloseStrokeIcon
} from 'brave-ui/components/icons'

Expand All @@ -49,10 +46,6 @@ class TopSite extends React.PureComponent<Props, {}> {
this.props.actions.showGridSiteRemovedNotification(true)
}

onToggleBookmark (site: NewTab.Site) {
this.props.actions.toggleGridSiteBookmarkInfo(site)
}

render () {
const { siteData } = this.props

Expand All @@ -69,13 +62,6 @@ class TopSite extends React.PureComponent<Props, {}> {
<TileAction onClick={this.onTogglePinnedTopSite.bind(this, siteData)}>
{isGridSitePinned(siteData) ? <PinIcon /> : <PinOIcon />}
</TileAction>
<TileAction onClick={this.onToggleBookmark.bind(this, siteData)}>
{
isGridSiteBookmarked(siteData.bookmarkInfo)
? <BookmarkIcon />
: <BookmarkOIcon />
}
</TileAction>
{
// Disallow removing a pinned site
isGridSitePinned(siteData)
Expand Down
12 changes: 2 additions & 10 deletions components/brave_new_tab_ui/helpers/newTabUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ export const isGridSitePinned = (
return gridSite.pinnedIndex !== undefined
}

export const isGridSiteBookmarked = (
bookmarkInfo: chrome.bookmarks.BookmarkTreeNode | undefined
): boolean => {
return bookmarkInfo !== undefined
}

export const isExistingGridSite = (
sitesData: NewTab.Site[],
topOrGridSite: chrome.topSites.MostVisitedURL | NewTab.Site
Expand All @@ -61,8 +55,7 @@ export const generateGridSitePropertiesFromDefaultSuperReferralTopSite = (
id: generateGridSiteId(),
letter: getCharForSite(defaultSuperReferralTopSite),
favicon: defaultSuperReferralTopSite.favicon,
pinnedIndex: defaultSuperReferralTopSite.pinnedIndex,
bookmarkInfo: undefined
pinnedIndex: defaultSuperReferralTopSite.pinnedIndex
}
}

Expand All @@ -79,8 +72,7 @@ export const generateGridSiteProperties = (
favicon: generateGridSiteFavicon(topSite.url),
// In the legacy version of topSites the pinnedIndex
// was the site index itself.
pinnedIndex: fromLegacyData ? index : undefined,
bookmarkInfo: undefined
pinnedIndex: fromLegacyData ? index : undefined
}
}

Expand Down
16 changes: 0 additions & 16 deletions components/brave_new_tab_ui/reducers/grid_sites_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,6 @@ export const gridSitesReducer: Reducer<NewTab.GridSitesState | undefined> = (
break
}

case types.GRID_SITES_UPDATE_SITE_BOOKMARK_INFO: {
state = gridSitesState
.gridSitesReducerUpdateSiteBookmarkInfo(state, payload.bookmarkInfo)
break
}

case types.GRID_SITES_TOGGLE_SITE_BOOKMARK_INFO: {
state = gridSitesState
.gridSitesReducerToggleSiteBookmarkInfo(
state,
payload.url,
payload.bookmarkInfo
)
break
}

case types.GRID_SITES_ADD_SITES: {
state = gridSitesState.gridSitesReducerAddSiteOrSites(state, payload.site)
break
Expand Down
49 changes: 0 additions & 49 deletions components/brave_new_tab_ui/state/gridSitesState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
isExistingGridSite,
getGridSitesWhitelist,
isGridSitePinned,
isGridSiteBookmarked,
filterFromExcludedSites,
filterDuplicatedSitesbyIndexOrUrl
} from '../helpers/newTabUtils'
Expand Down Expand Up @@ -173,54 +172,6 @@ export function gridSitesReducerUndoRemoveAllSites (
return state
}

export const gridSitesReducerUpdateSiteBookmarkInfo = (
state: NewTab.GridSitesState,
bookmarkInfo: chrome.bookmarks.BookmarkTreeNode
): NewTab.GridSitesState => {
const updatedGridSites: NewTab.Site[] = []
for (const [index, gridSite] of state.gridSites.entries()) {
const updatedBookmarkTreeNode = bookmarkInfo[index]
if (
updatedBookmarkTreeNode !== undefined &&
gridSite.url === updatedBookmarkTreeNode.url
) {
updatedGridSites.push({
...gridSite,
bookmarkInfo: updatedBookmarkTreeNode
})
} else {
updatedGridSites.push(gridSite)
}
}
state = gridSitesReducerDataUpdated(state, updatedGridSites)
return state
}

export const gridSitesReducerToggleSiteBookmarkInfo = (
state: NewTab.GridSitesState,
url: string,
bookmarkInfo: chrome.bookmarks.BookmarkTreeNode
): NewTab.GridSitesState => {
const updatedGridSites: NewTab.Site[] = []
for (const gridSite of state.gridSites) {
if (url === gridSite.url) {
updatedGridSites.push({
...gridSite,
bookmarkInfo: isGridSiteBookmarked(bookmarkInfo)
? undefined
// Add a transitory state for bookmarks.
// This will be overriden by a new mount and is used
// as a secondary render until data is ready,
: { title: gridSite.title, id: 'TEMPORARY' }
})
} else {
updatedGridSites.push(gridSite)
}
}
state = gridSitesReducerDataUpdated(state, updatedGridSites)
return state
}

export function gridSitesReducerAddSiteOrSites (
state: NewTab.GridSitesState,
addedSites: NewTab.Site[] | NewTab.Site
Expand Down
1 change: 0 additions & 1 deletion components/definitions/newTab.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ declare namespace NewTab {
favicon: string
letter: string
pinnedIndex: number | undefined
bookmarkInfo: chrome.bookmarks.BookmarkTreeNode | undefined
}

// This is preserved for migration reasons.
Expand Down
Loading

0 comments on commit 53ceabf

Please sign in to comment.