publishCurrentDraft property

MutationSignal<DocumentVersion, String> publishCurrentDraft
latefinal

Atomically publishes the document's current draft as a new version.

Delegates to the single backend endpoint DataSource.publishCurrentVersion which snapshots the current CRDT HLC, creates a published version row, and upserts the public content row — all in one transaction.

Implementation

late final publishCurrentDraft =
    mutationSignal<DocumentVersion, String>((documentId) async {
      final version = await dataSource.publishCurrentVersion(documentId);

      documentsContainer(
        currentDocumentType.value?.name ?? '',
      ).awaitableReload();
      versionsContainer(documentId).awaitableReload();
      selectedVersionId.value = version.id;
      if (version.id != null) {
        documentDataContainer(version.id!).awaitableReload();
      }
      // Reload the selected document so crdtHlc is fresh for hasUnpublishedChanges.
      selectedDocumentContainer(documentId).awaitableReload();

      return version;
    }, debugLabel: 'publishCurrentDraft');