Skip to content

The open-source app everyone uses to manage agents at work

854 B
Raw Blame
import {
  readRecentSelectionIds,
  trackRecentSelectionId,
} from "./recent-selections";

const STORAGE_KEY = "paperclip:recent-projects";

export function getRecentProjectIds(): string[] {
  return readRecentSelectionIds(STORAGE_KEY);
}

/** Undefined means no history; an empty string remembers an explicit No project. */
export function getLastProjectId(companyId: string): string | undefined {
  try {
    return localStorage.getItem(`${STORAGE_KEY}:${companyId}`) ?? undefined;
  } catch {
    return undefined;
  }
}

export function trackRecentProject(projectId: string, companyId?: string): void {
  trackRecentSelectionId(STORAGE_KEY, projectId);
  if (companyId) {
    try {
      localStorage.setItem(`${STORAGE_KEY}:${companyId}`, projectId);
    } catch {
      // Selection remains usable when browser storage is unavailable.
    }
  }
}