Skip to content

Commit

Permalink
add title
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Jan 23, 2025
1 parent bdb8cc5 commit 3425be3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion special-pages/pages/new-tab/app/activity/ActivityProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export function ActivityProvider(props) {
if (typeof value !== 'string') return console.warn('expected clicked button to have a value');

if (action === ACTION_ADD_FAVORITE) {
service.current.addFavorite(button.value);
const title = button.dataset.title;
service.current.addFavorite(button.value, title || '');
} else if (action === ACTION_REMOVE_FAVORITE) {
service.current.removeFavorite(button.value);
} else if (action === ACTION_BURN) {
Expand Down
5 changes: 3 additions & 2 deletions special-pages/pages/new-tab/app/activity/activity.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ export class ActivityService {
}
/**
* @param {string} url
* @param {string} title
*/
addFavorite(url) {
addFavorite(url, title) {
this.dataService.update((old) => {
return {
...old,
Expand All @@ -90,7 +91,7 @@ export class ActivityService {
}),
};
});
this.ntp.messaging.notify('activity_addFavorite', { url });
this.ntp.messaging.notify('activity_addFavorite', { url, title });
}
/**
* @param {string} url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function ActivityBody({ data, canBurn }) {
class={cn(styles.icon, styles.controlIcon)}
title={favoriteTitle}
data-action={item.favorite ? ACTION_REMOVE_FAVORITE : ACTION_ADD_FAVORITE}
data-title={item.title}
value={item.url}
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class ActivityPage {
method: 'activity_addFavorite',
params: {
url: 'https://example.com',
title: 'example.com',
},
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["url"],
"required": ["url", "title"],
"properties": {
"url": {
"description": "The History Entry url to be added to favorites",
"type": "string"
},
"title": {
"description": "The History Entry title",
"type": "string"
}
}
}
4 changes: 4 additions & 0 deletions special-pages/pages/new-tab/types/new-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ export interface ActivityAddFavoriteNotify {
* The History Entry url to be added to favorites
*/
url: string;
/**
* The History Entry title
*/
title: string;
}
/**
* Generated from @see "../messages/activity_burn.notify.json"
Expand Down

0 comments on commit 3425be3

Please sign in to comment.