Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ntp: favorites drag and drop #1150

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion special-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"preact": "^10.24.3",
"classnames": "^2.5.1",
"@formkit/auto-animate": "^0.8.2",
"@rive-app/canvas-single": "^2.23.3"
"@rive-app/canvas-single": "^2.23.3",
"@atlaskit/pragmatic-drag-and-drop": "^1.3.1",
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.3"
}
}
11 changes: 0 additions & 11 deletions special-pages/pages/new-tab/app/components/Chevron.js

This file was deleted.

54 changes: 54 additions & 0 deletions special-pages/pages/new-tab/app/components/Examples.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { PrivacyStatsMockProvider } from '../privacy-stats/mocks/PrivacyStatsMoc
import { Body, Heading, PrivacyStatsConsumer } from '../privacy-stats/PrivacyStats.js'
import { RemoteMessagingFramework } from '../remote-messaging-framework/RemoteMessagingFramework.js'
import { stats } from '../privacy-stats/mocks/stats.js'
import { MockFavoritesProvider } from "../favorites/mocks/MockFavoritesProvider.js";
import { favorites } from "../favorites/mocks/favorites.data.js";
import { FavoritesConsumer } from "../favorites/Favorites.js";
import { noop } from '../utils.js'
import { VisibilityMenu } from '../customizer/VisibilityMenu.js'
import { CustomizerButton } from '../customizer/Customizer.js'
Expand Down Expand Up @@ -83,6 +86,57 @@ export const mainExamples = {
dismiss={() => {}}
/>
)
},
'favorites.many': {
factory: () => (
<MockFavoritesProvider data={favorites.many}><FavoritesConsumer /></MockFavoritesProvider>
)
},
'favorites.few.7': {
factory: () => (
<MockFavoritesProvider data={{favorites: favorites.many.favorites.slice(0, 7)}}><FavoritesConsumer /></MockFavoritesProvider>
)
},
'favorites.few.7.no-animation': {
factory: () => (
<MockFavoritesProvider
data={{favorites: favorites.many.favorites.slice(0, 7)}}
config={{expansion: "expanded", animation: { kind: "none" }}}
><FavoritesConsumer /></MockFavoritesProvider>
)
},
'favorites.few.6': {
factory: () => (
<MockFavoritesProvider data={{favorites: favorites.many.favorites.slice(0, 6)}}><FavoritesConsumer /></MockFavoritesProvider>
)
},
'favorites.few.12': {
factory: () => (
<MockFavoritesProvider data={{favorites: favorites.many.favorites.slice(0, 12)}}><FavoritesConsumer /></MockFavoritesProvider>
)
},
'favorites.multi': {
factory: () => (
<div>
<MockFavoritesProvider data={favorites.many}><FavoritesConsumer /></MockFavoritesProvider>
<br/>
<MockFavoritesProvider data={favorites.two}><FavoritesConsumer /></MockFavoritesProvider>
<br/>
<MockFavoritesProvider data={favorites.single}><FavoritesConsumer /></MockFavoritesProvider>
<br/>
<MockFavoritesProvider data={favorites.none}><FavoritesConsumer /></MockFavoritesProvider>
</div>
)
},
'favorites.single': {
factory: () => (
<MockFavoritesProvider data={favorites.single}><FavoritesConsumer /></MockFavoritesProvider>
)
},
'favorites.none': {
factory: () => (
<MockFavoritesProvider data={favorites.none}><FavoritesConsumer /></MockFavoritesProvider>
)
}
}

Expand Down
1 change: 1 addition & 0 deletions special-pages/pages/new-tab/app/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*
* @module NewTab Services
*/
export * from './favorites/favorites.service.js'
33 changes: 33 additions & 0 deletions special-pages/pages/new-tab/app/favorites/Color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Constant array of colors for empty favicon backgrounds
const EMPTY_FAVICON_TEXT_BACKGROUND_COLOR_BRUSHES = [
'#94B3AF', '#727998', '#645468', '#4D5F7F',
'#855DB6', '#5E5ADB', '#678FFF', '#6BB4EF',
'#4A9BAE', '#66C4C6', '#55D388', '#99DB7A',
'#ECCC7B', '#E7A538', '#DD6B4C', '#D65D62'
]

// DJB hashing algorithm to get a consistent color index from URL host
function getDJBHash (str) {
let hash = 5381
for (let i = 0; i < str.length; i++) {
hash = (hash << 5) + hash + str.charCodeAt(i)
}
return hash
}

// Extracts the host part of the URL
function getHost (url) {
try {
const urlObj = new URL(url)
return urlObj.hostname.replace(/^www\./, '')
} catch (e) {
return '?'
}
}

// Main function: Converts a URL to a color from the predefined array
export function urlToColor (url) {
const host = getHost(url)
const index = Math.abs(getDJBHash(host) % EMPTY_FAVICON_TEXT_BACKGROUND_COLOR_BRUSHES.length)
return EMPTY_FAVICON_TEXT_BACKGROUND_COLOR_BRUSHES[index]
}
Loading
Loading