Skip to content

Commit 3f231d4

Browse files
refactor: simplify pdf editor add completion flow
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 0ef1ee2 commit 3f231d4

1 file changed

Lines changed: 8 additions & 21 deletions

File tree

src/components/PdfEditor/PdfEditor.vue

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ defineOptions({
132132
name: 'PdfEditor',
133133
})
134134
135-
// PDFElements expects the worker path to be available before its own mount.
136135
ensurePdfWorker()
137136
138137
const props = withDefaults(defineProps<{
@@ -151,14 +150,13 @@ const emit = defineEmits<{
151150
(event: 'pdf-editor:end-init', payload: EndInitPayload): void
152151
(event: 'pdf-editor:on-delete-signer', payload: VisibleElementRecord): void
153152
(event: 'pdf-editor:object-click', payload: Record<string, unknown>): void
154-
(event: 'pdf-editor:signer-added'): void
153+
(event: 'pdf-editor:adding-ended'): void
155154
}>()
156155
157156
const pdfElements = ref<PdfElementsInstance | null>(null)
158157
const pendingAddedObjectCount = ref<number | null>(null)
159158
160159
let pendingAddCheckTimer: ReturnType<typeof setTimeout> | null = null
161-
let pendingAddCheckRetries = 0
162160
163161
const ignoreClickOutsideSelectors = computed(() => ['.action-item__popper', '.action-item'])
164162
@@ -275,10 +273,14 @@ function clearPendingAddCheck() {
275273
clearTimeout(pendingAddCheckTimer)
276274
pendingAddCheckTimer = null
277275
}
278-
pendingAddCheckRetries = 0
279276
pendingAddedObjectCount.value = null
280277
}
281278
279+
function finishPendingAddCheck() {
280+
clearPendingAddCheck()
281+
emit('pdf-editor:adding-ended')
282+
}
283+
282284
function checkSignerAdded() {
283285
const objectsBefore = pendingAddedObjectCount.value
284286
if (objectsBefore === null) {
@@ -290,27 +292,14 @@ function checkSignerAdded() {
290292
const objectsAfter = getTotalObjectsCount()
291293
292294
if (objectsAfter > objectsBefore) {
293-
clearPendingAddCheck()
294-
emit('pdf-editor:signer-added')
295+
finishPendingAddCheck()
295296
return
296297
}
297298
298-
// Fallback: once add mode ends, unblock the UI even if the object count
299-
// comparison was not conclusive due timing/reactivity.
300299
if (!isAddingMode) {
301-
clearPendingAddCheck()
302-
emit('pdf-editor:signer-added')
303-
return
304-
}
305-
306-
// Poll while the external component still processes placement.
307-
if (pendingAddCheckRetries < 300) {
308-
pendingAddCheckRetries++
309-
pendingAddCheckTimer = setTimeout(checkSignerAdded, 100)
300+
finishPendingAddCheck()
310301
return
311302
}
312-
313-
clearPendingAddCheck()
314303
}
315304
316305
function scheduleSignerAddedCheck() {
@@ -342,11 +331,9 @@ function startAddingSigner(signer: SignerSummaryRecord | SignerDetailRecord | nu
342331
signer: signerPayload,
343332
})
344333
pendingAddedObjectCount.value = getTotalObjectsCount()
345-
pendingAddCheckRetries = 0
346334
if (pendingAddCheckTimer !== null) {
347335
clearTimeout(pendingAddCheckTimer)
348336
}
349-
pendingAddCheckTimer = setTimeout(checkSignerAdded, 100)
350337
351338
return true
352339
}

0 commit comments

Comments
 (0)