api-client/components/http/ResponseMeta.vue

102 lines
2.7 KiB
Vue
Raw Normal View History

<template>
2021-07-17 17:40:28 +00:00
<div class="bg-primary flex p-4 top-0 z-10 sticky items-center">
<div
2021-07-16 15:04:35 +00:00
v-if="response == null"
class="
2021-07-17 17:40:28 +00:00
flex flex-col flex-1
2021-07-16 15:04:35 +00:00
text-secondaryLight
2021-07-17 17:40:28 +00:00
items-center
2021-07-16 15:04:35 +00:00
justify-center
"
>
2021-08-01 17:33:54 +00:00
<ButtonSecondary
:label="$t('app.documentation')"
2021-08-01 17:33:54 +00:00
to="https://docs.hoppscotch.io"
2021-08-28 00:17:33 +00:00
svg="external-link"
2021-08-01 17:33:54 +00:00
blank
outline
reverse
2021-08-01 17:33:54 +00:00
/>
2021-07-16 15:04:35 +00:00
</div>
<div v-else class="flex flex-col flex-1">
<div v-if="response.type === 'loading'">
<i class="animate-spin material-icons"> refresh </i>
</div>
<div
v-if="response.type === 'network_fail'"
class="
flex flex-col flex-1
text-secondaryLight
p-4
items-center
justify-center
"
>
<i class="opacity-75 pb-2 material-icons">cloud_off</i>
<span class="text-center pb-2">
{{ $t("error.network_fail") }}
</span>
<span class="text-center pb-4">
{{ $t("helpers.network_fail") }}
</span>
<ButtonSecondary
outline
:label="$t('action.learn_more')"
to="https://docs.hoppscotch.io"
blank
2021-08-28 00:17:33 +00:00
svg="external-link"
reverse
/>
</div>
2021-07-16 15:04:35 +00:00
<div
v-if="response.type === 'success' || 'fail'"
2021-07-16 15:04:35 +00:00
:class="statusCategory.className"
class="font-semibold space-x-4"
2021-07-16 15:04:35 +00:00
>
<span v-if="response.statusCode">
2021-08-16 17:45:06 +00:00
<span class="text-secondary"> {{ $t("response.status") }}: </span>
{{ response.statusCode || $t("state.waiting_send_request") }}
</span>
<span v-if="response.meta && response.meta.responseDuration">
2021-08-16 17:45:06 +00:00
<span class="text-secondary"> {{ $t("response.time") }}: </span>
{{ `${response.meta.responseDuration} ms` }}
</span>
<span v-if="response.meta && response.meta.responseSize">
2021-08-16 17:45:06 +00:00
<span class="text-secondary"> {{ $t("response.size") }}: </span>
{{ `${response.meta.responseSize} B` }}
</span>
</div>
2021-07-13 07:18:57 +00:00
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from "@nuxtjs/composition-api"
import findStatusGroup from "~/helpers/findStatusGroup"
import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
const props = defineProps<{
response: HoppRESTResponse
}>()
const statusCategory = computed(() => {
if (
props.response.type === "loading" ||
props.response.type === "network_fail"
)
return ""
return findStatusGroup(props.response.statusCode)
2021-08-24 03:44:46 +00:00
})
</script>
<style lang="scss" scoped>
.shortcut-key {
@apply bg-dividerLight;
@apply rounded;
@apply ml-2;
@apply py-1;
@apply px-2;
@apply inline-flex;
}
</style>