File tree Expand file tree Collapse file tree 2 files changed +34
-9
lines changed
components/ui/app/extensions Expand file tree Collapse file tree 2 files changed +34
-9
lines changed Original file line number Diff line number Diff line change 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" />
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+
8595const isOpen = ref (true )
8696const loading = ref (false )
8797const images = ref <{ extension_images: ExtensionImages }>()
@@ -93,30 +103,42 @@ if (user.value?.admin) {
93103}
94104
95105const 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
108115const 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
122144defineExpose ({
Original file line number Diff line number Diff line change 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" />
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" />
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" />
You can’t perform that action at this time.
0 commit comments