All files / src/components/navigation/mcad McadAddObjectBtn.vue

100% Statements 12/12
75% Branches 3/4
100% Functions 5/5
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42  32x                       32x     1x 1x 1x     1x 1x       1x       1x       2x 1x 1x          
<template>
  <McadDropZone
    height="40px"
    @onClick="onClickItems"
    @onDropItems="onDropItems"
  />
</template>
 
<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { traverseDirectoryTreeWrapper } from '@/functions/fileReader';
import { useViewerStore } from '@/stores/viewer.store';
 
const { options } = storeToRefs(useViewerStore());
 
async function onDropItems(event: DragEvent) {
  const files: Array<File> = [];
  Eif (event.dataTransfer?.items) {
    await traverseDirectoryTreeWrapper(
      event.dataTransfer?.items,
      (file: File) => {
        files.push(file);
        return Promise.resolve();
      },
    );
  }
  await onComplete(files);
}
 
async function onClickItems(items: Array<File>) {
  await onComplete(items);
}
 
async function onComplete(items: Array<File>) {
  if (options.value.onMCADUpload) {
    await options.value.onMCADUpload(
      items.filter((x) => x.name.toLowerCase().includes('.stl')),
    );
  }
}
</script>