Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.0 KB
Raw Blame
import { type HomeStore } from '@/store/home/store';

import { type RecentEntityRef, toRecentEntityRef } from './initialState';
import type { DocsHomeTab } from './projection';

/** Items of one recents query; `undefined` until it is hydrated or fetched. */
const query = (queryKey: string) => (s: HomeStore) => s.recentListMap[queryKey];

/**
 * Whether a recents query has been answered by the server in this session. A
 * hydrated snapshot may be stale or empty, so "no rows" only means empty once
 * this is true.
 */
const isQueryConfirmed = (queryKey: string) => (s: HomeStore) =>
  s.recentListReplica.entries[queryKey]?.source === 'server';

const item = (queryKey: string, ref: RecentEntityRef) => (s: HomeStore) =>
  s.recentListMap[queryKey]?.find((recent) => toRecentEntityRef(recent) === ref);

/** One Docs home tab; `undefined` until hydrated or fetched. */
const docsHome = (tab: DocsHomeTab) => (s: HomeStore) => s.docsHomeMap[tab];

export const homeRecentSelectors = {
  docsHome,
  isQueryConfirmed,
  item,
  query,
};