|
| 1 | +<script lang="ts" setup> |
| 2 | +import { computed, onMounted, ref } from "vue"; |
| 3 | +import { HttpDumpPage } from "~/src/screens/http-dump"; |
| 4 | +import { useFetch, useRoute, useRouter, useHead, useNuxtApp } from "#app"; // eslint-disable-line @conarti/feature-sliced/layers-slices |
| 5 | +import { PageHeader } from "~/src/widgets/ui"; |
| 6 | +import { useHttpDump } from "~/src/entities/http-dump"; |
| 7 | +import type { HttpDump } from "~/src/entities/http-dump/types"; |
| 8 | +import { useEvents } from "~/src/shared/lib/use-events"; |
| 9 | +import type { EventId, ServerEvent } from "~/src/shared/types"; |
| 10 | +
|
| 11 | +const { normalizeHttpDumpEvent } = useHttpDump(); |
| 12 | +
|
| 13 | +const { params } = useRoute(); |
| 14 | +const router = useRouter(); |
| 15 | +const eventId = params.id as EventId; |
| 16 | +
|
| 17 | +useHead({ |
| 18 | + title: `Http dumps > ${eventId} | Buggregator`, |
| 19 | +}); |
| 20 | +
|
| 21 | +const { events } = useEvents(); |
| 22 | +const { $authToken } = useNuxtApp(); |
| 23 | +
|
| 24 | +const isLoading = ref(false); |
| 25 | +const serverEvent = ref<Event | null>(null); |
| 26 | +
|
| 27 | +const event = computed(() => |
| 28 | + serverEvent.value |
| 29 | + ? normalizeHttpDumpEvent( |
| 30 | + serverEvent.value as unknown as ServerEvent<HttpDump> |
| 31 | + ) |
| 32 | + : null |
| 33 | +); |
| 34 | +
|
| 35 | +const onDelete = () => { |
| 36 | + events.removeById(eventId); |
| 37 | +
|
| 38 | + router.push("/"); |
| 39 | +}; |
| 40 | +
|
| 41 | +const getEvent = async () => { |
| 42 | + await useFetch(events.getUrl(eventId), { |
| 43 | + headers: { "X-Auth-Token": $authToken.token || "" }, |
| 44 | + onRequest() { |
| 45 | + isLoading.value = true; |
| 46 | + }, |
| 47 | + onResponse({ response: { _data } }) { |
| 48 | + serverEvent.value = _data; |
| 49 | + isLoading.value = false; |
| 50 | + }, |
| 51 | + onResponseError() { |
| 52 | + router.push("/404"); |
| 53 | + }, |
| 54 | + onRequestError() { |
| 55 | + router.push("/404"); |
| 56 | + }, |
| 57 | + }); |
| 58 | +}; |
| 59 | +
|
| 60 | +onMounted(getEvent); |
| 61 | +</script> |
| 62 | + |
1 | 63 | <template> |
2 | 64 | <main class="http-dumps-event"> |
3 | 65 | <PageHeader |
|
7 | 69 | > |
8 | 70 | <NuxtLink to="/">Home</NuxtLink> / |
9 | 71 | <NuxtLink to="/http-dumps">Http dumps</NuxtLink> / |
10 | | - <NuxtLink :disabled="true">{{ event.id }}</NuxtLink> |
| 72 | + <NuxtLink :disabled="true">{{ eventId }}</NuxtLink> |
11 | 73 | </PageHeader> |
12 | 74 |
|
13 | | - <div v-if="pending && !event" class="http-dumps-event__loading"> |
| 75 | + <div v-if="isLoading && !event" class="http-dumps-event__loading"> |
14 | 76 | <div></div> |
15 | 77 | <div></div> |
16 | 78 | <div></div> |
|
22 | 84 | </main> |
23 | 85 | </template> |
24 | 86 |
|
25 | | -<script lang="ts"> |
26 | | -import { defineComponent } from "vue"; |
27 | | -import { useFetch, useRoute, useRouter, useNuxtApp } from "#app"; // eslint-disable-line @conarti/feature-sliced/layers-slices |
28 | | -import { PageHeader } from "~/src/widgets/ui"; |
29 | | -import { useHttpDump } from "~/src/entities/http-dump"; |
30 | | -import type { HttpDump } from "~/src/entities/http-dump/types"; |
31 | | -import { useEvents } from "~/src/shared/lib/use-events"; |
32 | | -import type { EventId, ServerEvent } from "~/src/shared/types"; |
33 | | -import { HttpDumpPage } from "~/src/screens/http-dump"; |
34 | | -
|
35 | | -const { normalizeHttpDumpEvent } = useHttpDump(); |
36 | | -
|
37 | | -export default defineComponent({ |
38 | | - components: { HttpDumpPage, PageHeader }, |
39 | | -
|
40 | | - async setup() { |
41 | | - const route = useRoute(); |
42 | | - const router = useRouter(); |
43 | | - const nuxtApp = useNuxtApp(); |
44 | | - const eventId = route.params.id as EventId; |
45 | | -
|
46 | | - const { events } = useEvents(); |
47 | | -
|
48 | | - const { data: event, pending } = await useFetch(events.getUrl(eventId), { |
49 | | - headers: {"X-Auth-Token": nuxtApp.$authToken.token}, |
50 | | - onResponse({ response }) { |
51 | | - return response.data; |
52 | | - }, |
53 | | - onResponseError() { |
54 | | - router.push("/404"); |
55 | | - }, |
56 | | - onRequestError() { |
57 | | - router.push("/404"); |
58 | | - }, |
59 | | - }); |
60 | | -
|
61 | | - return { |
62 | | - serverEvent: event, |
63 | | - pending, |
64 | | - eventId, |
65 | | - clearEvent: () => events.removeById(eventId), |
66 | | - }; |
67 | | - }, |
68 | | - head() { |
69 | | - return { |
70 | | - title: `Http dumps > ${this.eventId} | Buggregator`, |
71 | | - }; |
72 | | - }, |
73 | | - computed: { |
74 | | - event() { |
75 | | - return this.serverEvent |
76 | | - ? normalizeHttpDumpEvent( |
77 | | - this.serverEvent as unknown as ServerEvent<HttpDump> |
78 | | - ) |
79 | | - : null; |
80 | | - }, |
81 | | - }, |
82 | | - methods: { |
83 | | - onDelete() { |
84 | | - this.clearEvent(); |
85 | | -
|
86 | | - this.$router.push("/"); |
87 | | - }, |
88 | | - }, |
89 | | -}); |
90 | | -</script> |
91 | | - |
92 | 87 | <style lang="scss" scoped> |
93 | | -@import "assets/mixins"; |
| 88 | +@import "src/assets/mixins"; |
94 | 89 | .http-dumps-event { |
95 | 90 | @include layout; |
96 | 91 | } |
|
0 commit comments