Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

1.4 KB
Raw Blame
import type { ProjectSummary } from '@workbench/projects/library';

import { getWorkbenchPreferences, patchWorkbenchPreferences } from '@workbench/settings/store';

import { prunePinnedProjectIds, toggleProjectPin } from './projectLibraryView';

/** Centralize account pin writes and read the live snapshot so rapid toggles do not overwrite each other. */

export const toggleProjectPinPreference = (projectId: string): void => {
  const current = getWorkbenchPreferences().launchpadPinnedProjectIds;

  void patchWorkbenchPreferences({ launchpadPinnedProjectIds: toggleProjectPin(current, projectId) });
};

export const dropProjectPin = (projectId: string): void => {
  const current = getWorkbenchPreferences().launchpadPinnedProjectIds;

  if (!current.includes(projectId)) {
    return;
  }

  void patchWorkbenchPreferences({
    launchpadPinnedProjectIds: current.filter((id) => id !== projectId),
  });
};

/** Drop pins whose project no longer exists — deleted from another device or another tab. */
export const prunePinnedProjects = (summaries: readonly ProjectSummary[]): void => {
  const current = getWorkbenchPreferences().launchpadPinnedProjectIds;

  if (current.length === 0) {
    return;
  }

  const pruned = prunePinnedProjectIds(current, summaries);

  if (pruned.length !== current.length) {
    void patchWorkbenchPreferences({ launchpadPinnedProjectIds: pruned });
  }
};