浏览代码

refactor: migrate more components to setup script + fix a race condition with power search

liyasthomas 4 年之前
父节点
当前提交
3080af1ea5

+ 23 - 22
packages/hoppscotch-app/components/lenses/HeadersRenderer.vue

@@ -69,28 +69,29 @@
   </div>
   </div>
 </template>
 </template>
 
 
-<script>
-import { defineComponent } from "@nuxtjs/composition-api"
+<script setup lang="ts">
+import { ref, useContext } from "@nuxtjs/composition-api"
+import { HoppRESTHeader } from "~/helpers/types/HoppRESTRequest"
 import { copyToClipboard } from "~/helpers/utils/clipboard"
 import { copyToClipboard } from "~/helpers/utils/clipboard"
 
 
-export default defineComponent({
-  props: {
-    headers: { type: Array, default: () => [] },
-  },
-  data() {
-    return {
-      copyIcon: "copy",
-    }
-  },
-  methods: {
-    copyHeaders() {
-      copyToClipboard(JSON.stringify(this.headers))
-      this.copyIcon = "check"
-      this.$toast.success(this.$t("state.copied_to_clipboard"), {
-        icon: "content_paste",
-      })
-      setTimeout(() => (this.copyIcon = "copy"), 1000)
-    },
-  },
-})
+const {
+  $toast,
+  app: { i18n },
+} = useContext()
+const t = i18n.t.bind(i18n)
+
+const props = defineProps<{
+  headers: Array<HoppRESTHeader>
+}>()
+
+const copyIcon = ref("copy")
+
+const copyHeaders = () => {
+  copyToClipboard(JSON.stringify(props.headers))
+  copyIcon.value = "check"
+  $toast.success(t("state.copied_to_clipboard").toString(), {
+    icon: "content_paste",
+  })
+  setTimeout(() => (copyIcon.value = "copy"), 1000)
+}
 </script>
 </script>

+ 12 - 17
packages/hoppscotch-app/components/teams/Modal.vue

@@ -1,26 +1,21 @@
 <template>
 <template>
-  <SmartModal
-    v-if="show"
-    :title="$t('team.select_a_team')"
-    @close="$emit('hide-modal')"
-  >
+  <SmartModal v-if="show" :title="$t('team.select_a_team')" @close="hideModal">
     <template #body>
     <template #body>
       <Teams :modal="true" />
       <Teams :modal="true" />
     </template>
     </template>
   </SmartModal>
   </SmartModal>
 </template>
 </template>
 
 
-<script>
-import { defineComponent } from "@nuxtjs/composition-api"
+<script setup lang="ts">
+defineProps<{
+  show: Boolean
+}>()
 
 
-export default defineComponent({
-  props: {
-    show: Boolean,
-  },
-  methods: {
-    hideModal() {
-      this.$emit("hide-modal")
-    },
-  },
-})
+const emit = defineEmits<{
+  (e: "hide-modal"): void
+}>()
+
+const hideModal = () => {
+  emit("hide-modal")
+}
 </script>
 </script>

+ 4 - 3
packages/hoppscotch-app/helpers/powerSearchNavigation.ts

@@ -15,17 +15,18 @@ export function useArrowKeysNavigation(searchItems: any, options: any = {}) {
     const itemsLength = searchItems.value.length
     const itemsLength = searchItems.value.length
     const lastItemIndex = itemsLength - 1
     const lastItemIndex = itemsLength - 1
     const itemIndexValue = itemIndex.value
     const itemIndexValue = itemIndex.value
-    const action = searchItems.value[itemIndexValue].action
+    const action = searchItems.value[itemIndexValue]?.action
 
 
     if (action && event.key === "Enter" && options.onEnter) {
     if (action && event.key === "Enter" && options.onEnter) {
       options.onEnter(action)
       options.onEnter(action)
       return
       return
     }
     }
 
 
-    if (event.key === "ArrowDown") {
+    if (itemsLength && event.key === "ArrowDown") {
       itemIndex.value = itemIndexValue < lastItemIndex ? itemIndexValue + 1 : 0
       itemIndex.value = itemIndexValue < lastItemIndex ? itemIndexValue + 1 : 0
     } else if (itemIndexValue === 0) itemIndex.value = lastItemIndex
     } else if (itemIndexValue === 0) itemIndex.value = lastItemIndex
-    else if (event.key === "ArrowUp") itemIndex.value = itemIndexValue - 1
+    else if (itemsLength && event.key === "ArrowUp")
+      itemIndex.value = itemIndexValue - 1
   }
   }
 
 
   const preventPropagation = options && options.stopPropagation
   const preventPropagation = options && options.stopPropagation