Skip to content

Commit a8e82fd

Browse files
committed
feat: img upload??
1 parent fc1ad37 commit a8e82fd

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

apps/frontend/src/components/ui/app/extensions/Imagesmodal.vue

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
v-if="extension.status == 'approved'"
5656
class="flex w-full flex-col items-center md:w-auto"
5757
:disabled="loading"
58-
@click="handleUpload"
58+
@click="uploadInput?.click()"
5959
>
6060
<div class="flex items-center gap-1.5">
6161
<Icon name="pixelarticons:upload" />
@@ -69,6 +69,14 @@
6969
/>
7070
</template>
7171
</ElementsModal>
72+
73+
<input
74+
ref="uploadInput"
75+
type="file"
76+
accept="image/*"
77+
class="hidden"
78+
@change="handleUpload"
79+
/>
7280
</template>
7381

7482
<script setup lang="ts">
@@ -82,6 +90,8 @@ const emit = defineEmits<{
8290
insert: [url: string]
8391
}>()
8492
93+
const uploadInput = useTemplateRef('uploadInput')
94+
8595
const isOpen = ref(true)
8696
const loading = ref(false)
8797
const images = ref<{ extension_images: ExtensionImages }>()
@@ -93,30 +103,42 @@ if (user.value?.admin) {
93103
}
94104
95105
const fetchImages = async () => {
96-
loading.value = true
97106
try {
98107
images.value = await $fetch(`${basePath.value}/images`, {
99108
method: 'GET',
100109
})
101110
} catch (error) {
102111
console.error('An error occurred fetching images: ' + error)
103-
} finally {
104-
loading.value = false
105112
}
106113
}
107114
108115
const handleOpen = async () => {
109116
isOpen.value = true
110-
await fetchImages()
117+
if (props.extension.status == 'approved') {
118+
loading.value = true
119+
await fetchImages()
120+
loading.value = false
121+
}
111122
}
112123
113-
const handleUpload = async () => {
124+
const handleUpload = async (event: Event) => {
125+
const file = (event.target as HTMLInputElement).files?.[0]
126+
if (!file) return
127+
114128
imageCount.value = (images.value?.extension_images.length || 0) + 1
115129
loading.value = true
116130
117-
// upload image
118-
119-
await fetchImages()
131+
try {
132+
await $fetch(`${basePath.value}/images`, {
133+
method: 'POST',
134+
body: file,
135+
})
136+
await fetchImages()
137+
} catch (error) {
138+
console.error(error)
139+
} finally {
140+
loading.value = false
141+
}
120142
}
121143
122144
defineExpose({

apps/frontend/src/pages/app/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<NuxtLink
1313
to="/app/account"
1414
class="hover:text-brand-50 focus:text-brand-50 space-y-2 bg-neutral-950 p-4 outline-0 transition-colors hover:bg-neutral-900 focus:bg-neutral-900"
15+
@mousedown.prevent
1516
>
1617
<div class="flex items-center gap-1.5">
1718
<Icon name="memory:account-box" :size="28" mode="svg" />
@@ -24,6 +25,7 @@
2425
<NuxtLink
2526
to="/app/extensions"
2627
class="hover:text-brand-50 focus:text-brand-50 space-y-2 bg-neutral-950 p-4 outline-0 transition-colors hover:bg-neutral-900 focus:bg-neutral-900"
28+
@mousedown.prevent
2729
>
2830
<div class="flex items-center gap-1.5">
2931
<Icon name="memory:cube" :size="28" mode="svg" />
@@ -36,6 +38,7 @@
3638
<NuxtLink
3739
to="/app/stats"
3840
class="hover:text-brand-50 focus:text-brand-50 space-y-2 bg-neutral-950 p-4 outline-0 transition-colors hover:bg-neutral-900 focus:bg-neutral-900"
41+
@mousedown.prevent
3942
>
4043
<div class="flex items-center gap-1.5">
4144
<Icon name="memory:chart-bar" :size="28" mode="svg" />

0 commit comments

Comments
 (0)