@@ -129,6 +129,7 @@ import { openDocument } from '../utils/viewer.js'
129129import { getStatusLabel } from ' ../utils/fileStatus.js'
130130import { FILE_STATUS , SIGN_REQUEST_STATUS } from ' ../constants.js'
131131import logger from ' ../logger.js'
132+ import { useFilesStore } from ' ../store/files.js'
132133import { useSignStore } from ' ../store/sign.js'
133134import { useSidebarStore } from ' ../store/sidebar.js'
134135import type {
@@ -289,6 +290,7 @@ function isLoadedValidationFileDocument(document: ValidationFileRecord | null):
289290
290291const signStore = useSignStore ()
291292const sidebarStore = useSidebarStore ()
293+ const filesStore = useFilesStore ()
292294const instance = getCurrentInstance ()
293295const EXPIRATION_WARNING_DAYS = 30
294296
@@ -697,6 +699,57 @@ function setValidationError(message: string, timeout = 5000) {
697699 }
698700}
699701
702+ function getTrackedFileId(file : ValidationFileRecord | ValidatedChildFileRecord ): number | null {
703+ const fileId = toNumber (file .id )
704+ if (fileId !== null && Object .hasOwn (filesStore .files , fileId )) {
705+ return fileId
706+ }
707+
708+ if (typeof file .uuid === ' string' && file .uuid .length > 0 ) {
709+ const trackedByUuid = toNumber (filesStore .getFileIdByUuid (file .uuid ))
710+ if (trackedByUuid !== null ) {
711+ return trackedByUuid
712+ }
713+ }
714+
715+ const nodeId = toNumber (file .nodeId )
716+ if (nodeId !== null ) {
717+ const trackedByNodeId = toNumber (filesStore .getFileIdByNodeId (nodeId ))
718+ if (trackedByNodeId !== null ) {
719+ return trackedByNodeId
720+ }
721+ }
722+
723+ return null
724+ }
725+
726+ function syncValidatedDocumentToFilesStore(validationDocument : ValidationFileRecord ) {
727+ const pendingFiles: Array <ValidationFileRecord | ValidatedChildFileRecord > = [validationDocument ]
728+
729+ while (pendingFiles .length > 0 ) {
730+ const currentFile = pendingFiles .shift ()
731+ if (! currentFile ) {
732+ continue
733+ }
734+
735+ const trackedFileId = getTrackedFileId (currentFile )
736+ if (trackedFileId !== null ) {
737+ const storeFilePayload = {
738+ ... currentFile ,
739+ id: trackedFileId ,
740+ } as Parameters <typeof filesStore .addFile >[0 ]
741+ void filesStore .addFile (storeFilePayload , { detailsLoaded: true })
742+ }
743+
744+ const nestedFiles = ' files' in currentFile && Array .isArray (currentFile .files )
745+ ? currentFile .files
746+ : []
747+ if (nestedFiles .length > 0 ) {
748+ pendingFiles .push (... nestedFiles .filter ((file ): file is ValidatedChildFileRecord => isRecord (file )))
749+ }
750+ }
751+ }
752+
700753function openUuidDialog() {
701754 validationErrorMessage .value = null
702755 getUUID .value = true
@@ -738,6 +791,9 @@ function handleValidationSuccess(data: unknown) {
738791 && document .value .files .length > 0
739792 && document .value .files .every (file => isSignedStatus (file .status ))
740793 const signerCompleted = isCurrentSignerSigned ()
794+ if (isSignedDoc || allFilesSigned || signerCompleted ) {
795+ syncValidatedDocumentToFilesStore (normalizedDocument )
796+ }
741797 if ((isSignedDoc || allFilesSigned || signerCompleted ) && (isAfterSigned .value || shouldFireAsyncConfetti .value )) {
742798 const capabilities = getCapabilities () as { libresign? : { config? : Record <string , unknown > } } | undefined
743799 if (capabilities ?.libresign ?.config ?.[' show-confetti' ] === true ) {
0 commit comments