Skip to content

Commit

Permalink
update image preview to blank when scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
rwv committed Nov 15, 2023
1 parent 4a5af5a commit 7a0657c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
13 changes: 11 additions & 2 deletions src/components/page-preview/ImagePreview.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
<template>
<n-image :src="imageURL" v-if="imageURL" style="display: block" />
<div v-else class="image-placeholder">
<div v-else class="image-placeholder" :style="skeletonStyle">
<n-skeleton width="100%" height="100%" />
</div>
</template>

<script lang="ts" setup>
import { NImage, NSkeleton } from "naive-ui";
import { toRef } from "vue";
import { toRef, computed } from "vue";
import { useObjectUrl } from "@vueuse/core";
const props = defineProps<{
image?: Blob;
width?: number;
height?: number;
}>();
const image = toRef(props, "image");
const imageURL = useObjectUrl(image);
const skeletonStyle = computed(() => {
if (!props.width || !props.height) return {};
return {
"aspect-ratio": `${props.width} / ${props.height}`,
};
});
</script>

<style scoped>
Expand Down
42 changes: 29 additions & 13 deletions src/components/page-preview/PreviewCompare.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
<ImagePreview :image="image?.blob" />
</template>
<template #scan>
<ImagePreview :image="scanImage?.blob" />
<ImagePreview
:image="scanning ? undefined : scanImage?.blob"
:height="image?.height"
:width="image?.width"
/>
</template>
</SideBySidePreview>
<PreviewPagination
Expand All @@ -25,13 +29,16 @@ import PreviewPagination from "./PreviewPagination.vue";
import { NSpace } from "naive-ui";
const page = ref(1);
const scanning = ref(false);
interface PDFRenderer {
renderPage(
page: number,
scale: number
): Promise<{
blob: Blob;
width: number;
height: number;
}>;
getNumPages(): Promise<number>;
}
Expand Down Expand Up @@ -61,26 +68,35 @@ const image = computedAsync(async () => {
width: undefined,
};
const { blob } = await props.pdfRenderer.renderPage(page.value, props.scale);
const { blob, width, height } = await props.pdfRenderer.renderPage(
page.value,
props.scale
);
return {
blob,
width,
height,
};
});
let controller = new AbortController();
const scanImage = computedAsync(async () => {
controller.abort();
controller = new AbortController();
if (!props.scanRenderer || !image.value.blob) return;
const scanImage = computedAsync(
async () => {
controller.abort();
controller = new AbortController();
if (!props.scanRenderer || !image.value.blob) return;
const { blob } = await props.scanRenderer.renderPage(image.value.blob, {
signal: controller.signal,
});
return {
blob,
};
});
const { blob } = await props.scanRenderer.renderPage(image.value.blob, {
signal: controller.signal,
});
return {
blob,
};
},
undefined,
scanning
);
const numPages = computedAsync(async () => {
page.value = 1;
Expand Down

0 comments on commit 7a0657c

Please sign in to comment.