Refactoring Lenses Using Vue Composables (#1995)

This commit is contained in:
Rishabh Agarwal
2022-01-17 21:00:48 +05:30
committed by GitHub
parent ddff126aaa
commit 647c347eb1
10 changed files with 187 additions and 208 deletions

View File

@@ -0,0 +1,25 @@
import { computed, ComputedRef } from "@nuxtjs/composition-api"
import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
export default function useResponseBody(response: HoppRESTResponse): {
responseBodyText: ComputedRef<string>
} {
const responseBodyText = computed(() => {
if (
response.type === "loading" ||
response.type === "network_fail" ||
response.type === "script_fail" ||
response.type === "fail"
)
return ""
if (typeof response.body === "string") return response.body
else {
const res = new TextDecoder("utf-8").decode(response.body)
// HACK: Temporary trailing null character issue from the extension fix
return res.replace(/\0+$/, "")
}
})
return {
responseBodyText,
}
}