Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

1.0 KB
Raw Blame
import { useLayoutEffect, useMemo } from 'react';
import {
  advanceViewedPriorityHold,
  type MainListPriorityContext,
  type ViewedPriorityHoldState,
} from '../lib/mainListModel';

/** Only a committed route may release the previously viewed task's priority. */
export function useViewedPriorityHold(
  state: ViewedPriorityHoldState,
  viewedSessionId: string | undefined,
  ctx: MainListPriorityContext,
  options?: { project?: boolean },
): ViewedPriorityHoldState {
  const project = options?.project !== false;
  const projected = useMemo(() => {
    if (!project) return state;
    return advanceViewedPriorityHold(
      {
        prevViewedId: state.prevViewedId,
        heldPriorityRanks: new Map(state.heldPriorityRanks),
        recentlyViewedAtMs: new Map(state.recentlyViewedAtMs),
      },
      viewedSessionId,
      ctx,
      Date.now(),
    );
  }, [state, viewedSessionId, ctx, project]);
  useLayoutEffect(() => {
    if (!project) return;
    Object.assign(state, projected);
  }, [state, projected, project]);
  return projected;
}