Skip to content

Commit

Permalink
refresh document on extractions complete (#3401)
Browse files Browse the repository at this point in the history
Co-authored-by: Cole Blanchard <[email protected]>
Co-authored-by: Yohann Paris <[email protected]>
  • Loading branch information
3 people authored Apr 24, 2024
1 parent 48347b8 commit f7cef87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
viewOptions[1]?.value === DocumentView.PDF
"
>
PDF Extractions may still be processing please refresh in some time...
PDF Extractions are processing please come back in some time...
</p>
<tera-pdf-embed
v-else-if="view === DocumentView.PDF && pdfLink"
Expand All @@ -154,15 +154,15 @@
</template>
<script setup lang="ts">
import { computed, onUpdated, ref, watch } from 'vue';
import { computed, onMounted, onUnmounted, onUpdated, ref, watch } from 'vue';
import { isEmpty } from 'lodash';
import Accordion from 'primevue/accordion';
import AccordionTab from 'primevue/accordiontab';
import { FeatureConfig } from '@/types/common';
import TeraPdfEmbed from '@/components/widgets/tera-pdf-embed.vue';
import TeraAsset from '@/components/asset/tera-asset.vue';
import type { DocumentAsset } from '@/types/Types';
import { AssetType, ExtractionAssetType } from '@/types/Types';
import type { ClientEvent, DocumentAsset, ExtractionStatusUpdate } from '@/types/Types';
import { AssetType, ClientEventType, ExtractionAssetType } from '@/types/Types';
import {
downloadDocumentAsset,
getDocumentAsset,
Expand All @@ -176,6 +176,8 @@ import { useProjects } from '@/composables/project';
import { logger } from '@/utils/logger';
import Button from 'primevue/button';
import ContextMenu from 'primevue/contextmenu';
import { subscribe, unsubscribe } from '@/services/ClientEventService';
import { getStatus } from '@/services/notificationEventHandlers';
import TeraTextEditor from './tera-text-editor.vue';
enum DocumentView {
Expand Down Expand Up @@ -308,6 +310,25 @@ onUpdated(() => {
emit('asset-loaded');
}
});
onMounted(async () => {
await subscribe(ClientEventType.ExtractionPdf, subscribeToExtraction);
});
async function subscribeToExtraction(event: ClientEvent<ExtractionStatusUpdate>) {
console.log(event.data.message);
if (!event.data || event.data.documentId !== props.assetId) return;
const status = getStatus(event.data);
// FIXME: adding the 'dispatching' check since there seems to be an issue with the status of the extractions.
if (status === 'Completed' || event.data.message.includes('Dispatching')) {
document.value = await getDocumentAsset(props.assetId);
}
}
onUnmounted(async () => {
await unsubscribe(ClientEventType.ExtractionPdf, subscribeToExtraction);
});
</script>
<style scoped>
.extracted-item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Ref } from 'vue';
import { NotificationItem } from '@/types/common';
import { getDocumentAsset } from './document-assets';

const getStatus = (data: { error: string; t: number }) => {
export const getStatus = (data: { error: string; t: number }) => {
if (data.error) return 'Failed';
if (data.t >= 1.0) return 'Completed';
return 'Running';
Expand Down

0 comments on commit f7cef87

Please sign in to comment.