@@ -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
@@ -692,6 +694,57 @@ function setValidationError(message: string, timeout = 5000) {
692694 }
693695}
694696
697+ function getTrackedFileId(file : ValidationFileRecord | ValidatedChildFileRecord ): number | null {
698+ const fileId = toNumber (file .id )
699+ if (fileId !== null && Object .hasOwn (filesStore .files , fileId )) {
700+ return fileId
701+ }
702+
703+ if (typeof file .uuid === ' string' && file .uuid .length > 0 ) {
704+ const trackedByUuid = toNumber (filesStore .getFileIdByUuid (file .uuid ))
705+ if (trackedByUuid !== null ) {
706+ return trackedByUuid
707+ }
708+ }
709+
710+ const nodeId = toNumber (file .nodeId )
711+ if (nodeId !== null ) {
712+ const trackedByNodeId = toNumber (filesStore .getFileIdByNodeId (nodeId ))
713+ if (trackedByNodeId !== null ) {
714+ return trackedByNodeId
715+ }
716+ }
717+
718+ return null
719+ }
720+
721+ function syncValidatedDocumentToFilesStore(validationDocument : ValidationFileRecord ) {
722+ const pendingFiles: Array <ValidationFileRecord | ValidatedChildFileRecord > = [validationDocument ]
723+
724+ while (pendingFiles .length > 0 ) {
725+ const currentFile = pendingFiles .shift ()
726+ if (! currentFile ) {
727+ continue
728+ }
729+
730+ const trackedFileId = getTrackedFileId (currentFile )
731+ if (trackedFileId !== null ) {
732+ const storeFilePayload = {
733+ ... currentFile ,
734+ id: trackedFileId ,
735+ } as Parameters <typeof filesStore .addFile >[0 ]
736+ void filesStore .addFile (storeFilePayload , { detailsLoaded: true })
737+ }
738+
739+ const nestedFiles = ' files' in currentFile && Array .isArray (currentFile .files )
740+ ? currentFile .files
741+ : []
742+ if (nestedFiles .length > 0 ) {
743+ pendingFiles .push (... nestedFiles .filter ((file ): file is ValidatedChildFileRecord => isRecord (file )))
744+ }
745+ }
746+ }
747+
695748function openUuidDialog() {
696749 validationErrorMessage .value = null
697750 getUUID .value = true
@@ -733,6 +786,9 @@ function handleValidationSuccess(data: unknown) {
733786 && document .value .files .length > 0
734787 && document .value .files .every (file => isSignedStatus (file .status ))
735788 const signerCompleted = isCurrentSignerSigned ()
789+ if (isSignedDoc || allFilesSigned || signerCompleted ) {
790+ syncValidatedDocumentToFilesStore (normalizedDocument )
791+ }
736792 if ((isSignedDoc || allFilesSigned || signerCompleted ) && (isAfterSigned .value || shouldFireAsyncConfetti .value )) {
737793 const capabilities = getCapabilities () as { libresign? : { config? : Record <string , unknown > } } | undefined
738794 if (capabilities ?.libresign ?.config ?.[' show-confetti' ] === true ) {
0 commit comments