-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
84 lines (78 loc) · 1.52 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
<main class="container">
<nav>
<ul>
<li><nuxt-link to="/">Home</nuxt-link></li>
</ul>
</nav>
Hi Fusion 2025!
<form @submit.prevent="handleSubmission">
<input v-model="prompt" type="text" placeholder="How do you want things to change?" />
<button :aria-busy="loading">Submit request</button>
</form>
<MalleableComponent />
</main>
</template>
<script setup lang="ts">
import '@picocss/pico'
const prompt = ref('')
const malleables = reactive({
query: `query List {
cards {
name
abilities {
effect
name
type
}
evolveFrom
category
rarity
energyType
attacks {
cost
damage
effect
}
description
}
}`,
template: `<ul>
<li v-for="card in data?.data.cards || []">
{{ card.name }}
</li>
</ul>`
})
const loading = ref(false)
async function handleSubmission() {
loading.value = true
try {
const res = await $fetch('/api/completion', {
method: 'POST',
body: {
malleables,
prompt: prompt.value
}
})
console.log(res)
Object.assign(malleables, res)
} catch (e) {
console.error(e)
}
loading.value = false
}
const MalleableComponent = defineComponent({
async setup () {
const { data } = await useFetch('https://api.tcgdex.net/v2/graphql', {
method: 'POST',
body: {
query: malleables.query
}
})
return () => h({
data: () => ({ data }),
template: malleables.template
})
}
})
</script>