Skip to content

feat(recent-searches): export storage and search APIs#473

Merged
francoischalifour merged 1 commit intonextfrom
feat/rs-storage-search-apis
Mar 3, 2021
Merged

feat(recent-searches): export storage and search APIs#473
francoischalifour merged 1 commit intonextfrom
feat/rs-storage-search-apis

Conversation

@francoischalifour
Copy link
Copy Markdown
Contributor

@francoischalifour francoischalifour commented Mar 2, 2021

This creates a programmatic API to add and remove items from the Recent Searches instance, and exports the search and highlight APIs.

This will likely be the foundation of the upcoming Recently Viewed Items plugin.

Changes

Recent Item structure

The Recent Item structure changed to be decoupled from the Algolia Query Suggestions hit.

// Before
const item = { objectID: '1', query: 'First item' };

// After
const item = { id: '1', label: 'First item' };

(This change will likely "break" current Autocomplete Recent Searches implementation by displaying an empty title, but it's time before we release widely. If so, run localStorage.clear())

API

Manipulate items with the Data API

const recentSearchesPlugin = createLocalStorageRecentSearchesPlugin({
  key: 'search',
});

recentSearchesPlugin.data.addItem({ id: '1', label: 'First item' });
recentSearchesPlugin.data.addItem({ id: '2', label: 'Second item' });
recentSearchesPlugin.data.removeItem('2');
recentSearchesPlugin.data.getAll();
recentSearchesPlugin.data.getAll('first');

addHighlightedAttribute({ item, query })

This function is now exported.

const highlightedItem = addHighlightedAttribute({ item, query });

search({ items, query, limit })

This function is now exported.

const items = search({ query, items, limit })

Recently Viewed Items plugin

I created a user-land Recently Viewed Items plugin based on these new APIs.

This plugin is in a sandbox that displays the items on the empty screen for now. When supporting the official plugin, we'll think about a better integrated UX when searching for recently viewed items.

Screenshot 2021-03-02 at 10 43 56

@francoischalifour francoischalifour changed the title feat(rs): export storage and search APIs feat(recent-searches): export storage and search APIs Mar 3, 2021
@francoischalifour francoischalifour merged commit 09be485 into next Mar 3, 2021
@francoischalifour francoischalifour deleted the feat/rs-storage-search-apis branch March 3, 2021 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant