Browse Source

fix(admin): restore ctrl+v photo upload in orders section

unknown 1 day ago
parent
commit
8d5ec3d8d4
2 changed files with 44 additions and 11 deletions
  1. 44 1
      src/components/admin/OrdersSection.vue
  2. 0 10
      src/pages/Admin.vue

+ 44 - 1
src/components/admin/OrdersSection.vue

@@ -63,9 +63,10 @@
 </template>
 
 <script setup lang="ts">
-import { ref, computed } from "vue";
+import { ref, computed, onMounted, onUnmounted } from "vue";
 import { useI18n } from "vue-i18n";
 import { Search, Filter, RefreshCw, Plus, Package } from "lucide-vue-next";
+import { toast } from "vue-sonner";
 import Button from "@/components/ui/button.vue";
 import OrderCard from "./OrderCard.vue";
 
@@ -131,4 +132,46 @@ const resetFilters = () => {
   dateFrom.value = '';
   dateTo.value = '';
 };
+
+onMounted(() => {
+  window.addEventListener('paste', handlePaste);
+});
+
+onUnmounted(() => {
+  window.removeEventListener('paste', handlePaste);
+});
+
+async function handlePaste(event: ClipboardEvent) {
+  const active = document.activeElement;
+  if (active && (active.tagName === 'INPUT' || active.tagName === 'TEXTAREA')) return;
+  
+  if (!focusedOrderId.value) {
+    // We don't want to show a toast here because the user might just be pasting outside of an order
+    return;
+  }
+  
+  if (!event.clipboardData || !event.clipboardData.items) {
+    toast.error("No clipboard data available");
+    return;
+  }
+  
+  let foundImage = false;
+  for (let i = 0; i < event.clipboardData.items.length; i++) {
+    const item = event.clipboardData.items[i];
+    if (item.type.startsWith('image/')) {
+      foundImage = true;
+      const file = item.getAsFile();
+      if (file) {
+        event.preventDefault();
+        toast.info("Uploading pasted image...");
+        emit('upload-photo', focusedOrderId.value, file);
+        break; // Stop after finding the first image
+      }
+    }
+  }
+  
+  if (!foundImage) {
+    toast.error("No image found in clipboard. Make sure you copied an image, not text or a file path.");
+  }
+}
 </script>

+ 0 - 10
src/pages/Admin.vue

@@ -710,15 +710,5 @@ onMounted(async () => {
   fetchData();
   // Ensure materials are loaded for order edit selectors
   adminGetMaterials().then(res => materials.value = res).catch(() => {});
-  window.addEventListener('paste', handlePaste);
 });
-
-onUnmounted(() => {
-  window.removeEventListener('paste', handlePaste);
-});
-
-async function handlePaste(event: ClipboardEvent) {
-  const active = document.activeElement;
-  if (active && (active.tagName === 'INPUT' || active.tagName === 'TEXTAREA')) return;
-}
 </script>