UNPKG

@jbrowse/core

Version:

JBrowse 2 core libraries used by plugins

19 lines (18 loc) 881 B
import { useLocalStorage } from "../../util/index.js"; import { isAppRootModel } from "../../util/types/index.js"; const NUM_SHOWN = 2; export default function useInternetAccounts(rootModel) { const [recentlyUsed, setRecentlyUsed] = useLocalStorage('fileSelector-recentlyUsedInternetAccounts', []); const accounts = isAppRootModel(rootModel) ? rootModel.internetAccounts.filter(f => f.type !== 'HTTPBasicInternetAccount') : []; const accountMap = Object.fromEntries(accounts.map(a => [a.internetAccountId, a])); const sortedIds = [...new Set(accounts.map(s => s.internetAccountId))].sort((a, b) => recentlyUsed.indexOf(a) - recentlyUsed.indexOf(b)); return { accountMap, shownAccountIds: sortedIds.slice(0, NUM_SHOWN), hiddenAccountIds: sortedIds.slice(NUM_SHOWN), recentlyUsed, setRecentlyUsed, }; }