Refactoring Lenses Using Vue Composables (#1995)
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user