Page MenuHomeWickedGov Phorge

RecentItemsProvider.js
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

RecentItemsProvider.js

const { CommandPaletteItem, CommandPaletteProvider, CommandPaletteActionResult } = require( '../types.js' );
const createRecentItems = require( '../services/recentItems.js' );
const { getNavigationAction } = require( '../utils/providerActions.js' );
const recentItemsService = createRecentItems();
/** @type {CommandPaletteProvider} */
module.exports = {
id: 'recent',
isAsync: false, // We load from localStorage, so no need to debounce
debounceMs: 0,
keepStaleResultsOnQueryChange: false,
/**
* Determines if this provider should handle the current query.
*
* @param {string} query The search query.
* @return {boolean}
*/
canProvide( query ) {
// Provides results only when the query is empty
return !query;
},
/**
* Gets the recent items.
* Items are expected to conform to the CommandPaletteItem structure
* as they were saved in that format or a compatible subset (like fulltext-search).
*
* @return {Array<CommandPaletteItem>} An array of recent items.
*/
getResults() {
const items = recentItemsService.getRecentItems();
// Ensure source is added by the provider
return Array.isArray( items ) ? items.map( ( item ) => ( { ...item, source: this.id } ) ) : [];
},
/**
* Handles the selection of a recent item.
* Default action is to navigate to the item's URL.
*
* @param {CommandPaletteItem} item The selected item.
* @return {Promise<CommandPaletteActionResult>} Action result for the UI.
*/
async onResultSelect( item ) {
return getNavigationAction( item );
}
};

File Metadata

Mime Type
text/plain
Expires
Wed, Aug 19, 03:12 (2 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a6/1a/56e7f2f8f6d5e2be76e458154380
Default Alt Text
RecentItemsProvider.js (1 KB)

Event Timeline