Skip to content

history: favicon support #1490

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

Merged
merged 2 commits into from
Feb 15, 2025
Merged
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
6 changes: 5 additions & 1 deletion special-pages/pages/history/app/components/Empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ export function Empty() {
const { t } = useTypedTranslation();
return (
<div class={cn(styles.emptyState, styles.emptyStateOffset)}>
<img src="icons/clock.svg" width={128} height={96} alt="" class={styles.emptyStateImage} />
<div class={styles.icons}>
<img src="icons/backdrop.svg" width={128} height={96} alt="" />
<img src="icons/clock.svg" width={60} height={60} alt="" class={styles.forground} />
</div>
<h2 class={styles.emptyTitle}>{t('empty_title')}</h2>
<p class={styles.emptyText}>{t('empty_text')}</p>
</div>
);
}
69 changes: 47 additions & 22 deletions special-pages/pages/history/app/components/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Fragment, h } from 'preact';
import styles from './Item.module.css';
import { Dots } from '../icons/dots.js';
import { useTypedTranslation } from '../types.js';
import { BTN_ACTION_ENTRIES_MENU, BTN_ACTION_TITLE_MENU } from '../constants.js';
import { BTN_ACTION_ENTRIES_MENU, BTN_ACTION_TITLE_MENU, DDG_DEFAULT_ICON_SIZE } from '../constants.js';
import { FaviconWithState } from '../../../../shared/components/FaviconWithState.js';

export const Item = memo(
/**
Expand All @@ -17,47 +18,71 @@ export const Item = memo(
* @param {string} props.url - The text to be displayed for the item.
* @param {string} props.domain - The text to be displayed for the domain
* @param {number} props.kind - The kind or type of the item that determines its visual style.
* @param {string} props.dateRelativeDay - The relative day information to display (shown when kind is equal to TITLE_KIND).
* @param {string} props.dateTimeOfDay - the time of day, like 11.00am.
* @param {string} props.dateRelativeDay - the time of day, like 11.00am.
* @param {string|null} props.etldPlusOne
* @param {number} props.index - original index
* @param {boolean} props.selected - whether this item is selected
* @param {string|null|undefined} props.faviconSrc
* @param {number} props.faviconMax
*/
function Item({ id, url, domain, title, kind, dateRelativeDay, dateTimeOfDay, index, selected }) {
const { t } = useTypedTranslation();
function Item(props) {
const { title, kind, etldPlusOne, faviconSrc, faviconMax, dateTimeOfDay, dateRelativeDay, index, selected } = props;
const hasFooterGap = kind === END_KIND || kind === BOTH_KIND;
const hasTitle = kind === TITLE_KIND || kind === BOTH_KIND;
return (
<Fragment>
{hasTitle && (
<div class={cn(styles.title, styles.hover)} data-section-title>
{dateRelativeDay}
<button
class={cn(styles.dots, styles.titleDots)}
data-action={BTN_ACTION_TITLE_MENU}
value={dateRelativeDay}
aria-label={t('menu_sectionTitle', { relativeTime: dateRelativeDay })}
tabindex={0}
>
<Dots />
</button>
</div>
)}
{hasTitle && <Heading dateRelativeDay={dateRelativeDay} />}
<div
class={cn(styles.row, styles.hover, hasFooterGap && styles.last)}
data-history-entry={id}
data-history-entry={props.id}
data-index={index}
aria-selected={selected}
>
<a href={url} data-url={url} class={styles.entryLink}>
<div class={styles.favicon}>
<FaviconWithState
fallback={'./company-icons/other.svg'}
fallbackDark={'./company-icons/other-dark.svg'}
faviconMax={faviconMax}
faviconSrc={faviconSrc}
etldPlusOne={etldPlusOne}
displayKind={'history-favicon'}
theme={'light'}
defaultSize={DDG_DEFAULT_ICON_SIZE}
/>
</div>
<a href={props.url} data-url={props.url} class={styles.entryLink}>
{title}
</a>
<span class={styles.domain}>{domain}</span>
<span class={styles.domain}>{props.domain}</span>
<span class={styles.time}>{dateTimeOfDay}</span>
<button class={styles.dots} data-action={BTN_ACTION_ENTRIES_MENU} data-index={index} value={id} tabindex={0}>
<button class={styles.dots} data-action={BTN_ACTION_ENTRIES_MENU} data-index={index} value={props.id} tabindex={0}>
<Dots />
</button>
</div>
</Fragment>
);
},
);

/**
* @param {object} props
* @param {string} props.dateRelativeDay
*/
function Heading({ dateRelativeDay }) {
const { t } = useTypedTranslation();
return (
<div className={cn(styles.title, styles.hover)} data-section-title>
{dateRelativeDay}
<button
className={cn(styles.dots, styles.titleDots)}
data-action={BTN_ACTION_TITLE_MENU}
value={dateRelativeDay}
aria-label={t('menu_sectionTitle', { relativeTime: dateRelativeDay })}
tabIndex={0}
>
<Dots />
</button>
</div>
);
}
4 changes: 4 additions & 0 deletions special-pages/pages/history/app/components/Item.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
border-bottom-right-radius: var(--row-radius);
}

.favicon {
flex-shrink: 0;
min-width: 0;
}

.entryLink {
white-space: nowrap;
Expand Down
9 changes: 7 additions & 2 deletions special-pages/pages/history/app/components/Results.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h } from 'preact';
import { OVERSCAN_AMOUNT } from '../constants.js';
import { DDG_DEFAULT_ICON_SIZE, OVERSCAN_AMOUNT } from '../constants.js';
import { Item } from './Item.js';
import styles from './VirtualizedList.module.css';
import { VisibleItems } from './VirtualizedList.js';
Expand All @@ -24,6 +24,8 @@ export function Results({ results, selected }) {
overscan={OVERSCAN_AMOUNT}
renderItem={({ item, cssClassName, style, index }) => {
const isSelected = selected.value.has(index);
const faviconMax = item.favicon?.maxAvailableSize ?? DDG_DEFAULT_ICON_SIZE;
const favoriteSrc = item.favicon?.src;
return (
<li key={item.id} data-id={item.id} class={cssClassName} style={style} data-is-selected={isSelected}>
<Item
Expand All @@ -32,10 +34,13 @@ export function Results({ results, selected }) {
url={item.url}
domain={item.domain}
title={item.title}
dateRelativeDay={item.dateRelativeDay}
dateTimeOfDay={item.dateTimeOfDay}
dateRelativeDay={item.dateRelativeDay}
index={index}
selected={isSelected}
etldPlusOne={item.etldPlusOne ?? null}
faviconSrc={favoriteSrc}
faviconMax={faviconMax}
/>
</li>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,36 @@
width: 100%;
height: 100%;
text-align: center;
color: var(--history-text-normal)
color: var(--history-text-normal);
display: grid;
grid-template-rows: max-content max-content;
justify-items: center;
}

.emptyStateOffset {
padding-top: var(--sp-32);
padding-top: 30vh;
}

.emptyStateImage {
.icons {
width: 128px;
height: 96px;
display: inline-block;
position: relative;
}

.forground {
position: absolute;
top: 50%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
}

.emptyTitle {
font-size: var(--title-3-em-font-size);
font-weight: var(--title-3-em-font-weight);
line-height: var(--title-3-em-line-height);
}
margin-top: 16px;
}
.emptyText {
margin-top: 8px;
color: var(--history-text-muted)
}
1 change: 1 addition & 0 deletions special-pages/pages/history/app/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const DDG_DEFAULT_ICON_SIZE = 32;
export const OVERSCAN_AMOUNT = 5;
export const BTN_ACTION_TITLE_MENU = 'title_menu';
export const BTN_ACTION_ENTRIES_MENU = 'entries_menu';
Expand Down
4 changes: 4 additions & 0 deletions special-pages/pages/history/app/mocks/history.mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const historyMocks = {
title: 'Electric Callboy - Hypa Hypa (OFFICIAL VIDEO) - YouTube',
url: 'https://www.youtube.com/watch?v=75Mw8r5gW8E',
domain: 'www.youtube.com',
etldPlusOne: 'youtube.com',
},
{
id: 'history-id-02',
Expand All @@ -27,6 +28,7 @@ export const historyMocks = {
title: 'Sonos continues to clean house with departure of chief commercial officer - The Verge',
url: 'https://www.theverge.com/2025/1/15/24344430/sonos-cco-deirdre-findlay-leaving',
domain: 'www.theverge.com',
etldPlusOne: 'theverge.com',
},
{
id: 'history-id-03',
Expand All @@ -36,6 +38,7 @@ export const historyMocks = {
title: 'PreactJS/preact: Fast 3kB React alternative with the same API. Components & Virtual DOM. - GitHub',
url: 'https://github.com/preactjs/preact',
domain: 'github.com',
etldPlusOne: 'github.com',
},
],
},
Expand Down Expand Up @@ -87,6 +90,7 @@ export function generateSampleData({ count, offset }) {
domain: domains[domainIndex],
title: `(index:${id}) ` + titles[domainIndex],
url: urls[domainIndex],
etldPlusOne: domains[domainIndex],
});

// Adjust time for each entry so they're not identical
Expand Down
4 changes: 4 additions & 0 deletions special-pages/pages/history/app/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"title": "Nothing to see here!",
"note": "Text shown where there are no remaining history items"
},
"empty_text": {
"title": "Page visits will appear once you start browsing.",
"note": "Placeholder text when there's no results to show"
},
"delete_all": {
"title": "Delete All",
"note": "Text for a button that deletes all items or entries."
Expand Down
21 changes: 21 additions & 0 deletions special-pages/pages/history/messages/types/favicon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Favicon",
"oneOf": [
{
"type": "null"
},
{
"type": "object",
"required": ["src"],
"properties": {
"src": {
"type": "string"
},
"maxAvailableSize": {
"type": "number"
}
}
}
]
}
3 changes: 3 additions & 0 deletions special-pages/pages/history/messages/types/history-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"type": "string",
"format": "uri",
"description": "A complete URL including query parameters."
},
"favicon": {
"$ref": "./favicon.json"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions special-pages/pages/history/public/company-icons/other.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions special-pages/pages/history/public/icons/backdrop.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading