diff --git a/plugins/turnstone-recent-searches/index.jsx b/plugins/turnstone-recent-searches/index.jsx deleted file mode 100644 index 06b0de6..0000000 --- a/plugins/turnstone-recent-searches/index.jsx +++ /dev/null @@ -1,72 +0,0 @@ -import { useCallback } from 'react' - -const RecentSearchesPlugin = (props) => { - const { - Component, - componentProps, - pluginIndex, - render, - ratio = 1, - id, - name = 'Recent Searches', - storageKey = 'recentSearches', - limit = 10 - } = props - - const { - defaultListbox = [], - onSelect - } = componentProps - - const recentSearches = useCallback(() => { - return JSON.parse(localStorage.getItem(storageKey)) || [] - }, [storageKey]) - - const addToRecentSearches = useCallback(itemToAdd => { - const searches = [ - itemToAdd, - ...recentSearches().filter( - item => item._displayField !== itemToAdd._displayField - ) - ] - localStorage.setItem(storageKey, JSON.stringify(searches.slice(0, limit))) - }, [storageKey, limit, recentSearches, ]) - - const buildDefaultListBox = () => { - return [ - { - id, - name, - displayField: '_displayField', - data: () => Promise.resolve(recentSearches()), - ratio - }, - ...defaultListbox - ] - } - - const handleSelect = useCallback((selectedResult, displayField) => { - if(selectedResult) { - if(typeof selectedResult === 'string') { - selectedResult = {_displayField: selectedResult} - } - else { - selectedResult._displayField = selectedResult[displayField] - } - addToRecentSearches(selectedResult) - } - - if(typeof onSelect === 'function') onSelect(selectedResult, displayField) - }, [addToRecentSearches, onSelect]) - - const newComponentProps = { - ...componentProps, - defaultListbox: buildDefaultListBox(), - defaultListboxIsImmutable: false, - onSelect: handleSelect - } - - return render(Component, newComponentProps, pluginIndex + 1) -} - -export default RecentSearchesPlugin \ No newline at end of file