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

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

Merged
merged 1 commit into from
Mar 3, 2021

Conversation

francoischalifour
Copy link
Member

@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.

None yet

1 participant