| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <div class="text-center"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     <v-menu | 
					
						
							|  |  |  |       v-model="menu" | 
					
						
							|  |  |  |       offset-y | 
					
						
							|  |  |  |       top | 
					
						
							|  |  |  |       nudge-top="6" | 
					
						
							|  |  |  |       :close-on-content-click="false" | 
					
						
							|  |  |  |     > | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  |       <template #activator="{ props: activatorProps }"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         <v-btn | 
					
						
							|  |  |  |           color="accent" | 
					
						
							|  |  |  |           dark | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  |           v-bind="activatorProps" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         > | 
					
						
							|  |  |  |           <v-icon start> | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |             {{ $globals.icons.fileImage }} | 
					
						
							|  |  |  |           </v-icon> | 
					
						
							|  |  |  |           {{ $t("general.image") }} | 
					
						
							|  |  |  |         </v-btn> | 
					
						
							|  |  |  |       </template> | 
					
						
							|  |  |  |       <v-card width="400"> | 
					
						
							|  |  |  |         <v-card-title class="headline flex mb-0"> | 
					
						
							|  |  |  |           <div> | 
					
						
							|  |  |  |             {{ $t("recipe.recipe-image") }} | 
					
						
							|  |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |           <AppButtonUpload | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |             class="ml-auto" | 
					
						
							|  |  |  |             url="none" | 
					
						
							|  |  |  |             file-name="image" | 
					
						
							|  |  |  |             :text-btn="false" | 
					
						
							|  |  |  |             :post="false" | 
					
						
							| 
									
										
										
										
											2021-08-01 19:24:47 -08:00
										 |  |  |             @uploaded="uploadImage" | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |           /> | 
					
						
							|  |  |  |         </v-card-title> | 
					
						
							|  |  |  |         <v-card-text class="mt-n5"> | 
					
						
							|  |  |  |           <div> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             <v-text-field | 
					
						
							|  |  |  |               v-model="url" | 
					
						
							|  |  |  |               :label="$t('general.url')" | 
					
						
							|  |  |  |               class="pt-5" | 
					
						
							|  |  |  |               clearable | 
					
						
							|  |  |  |               :messages="messages" | 
					
						
							|  |  |  |             > | 
					
						
							| 
									
										
										
										
											2025-06-27 15:39:47 +02:00
										 |  |  |               <template #append> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                 <v-btn | 
					
						
							|  |  |  |                   class="ml-2" | 
					
						
							|  |  |  |                   color="primary" | 
					
						
							|  |  |  |                   :loading="loading" | 
					
						
							|  |  |  |                   :disabled="!slug" | 
					
						
							|  |  |  |                   @click="getImageFromURL" | 
					
						
							|  |  |  |                 > | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |                   {{ $t("general.get") }} | 
					
						
							|  |  |  |                 </v-btn> | 
					
						
							|  |  |  |               </template> | 
					
						
							|  |  |  |             </v-text-field> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </v-card-text> | 
					
						
							|  |  |  |       </v-card> | 
					
						
							|  |  |  |     </v-menu> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | <script setup lang="ts"> | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  | import { useUserApi } from "~/composables/api"; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-01 19:24:47 -08:00
										 |  |  | const REFRESH_EVENT = "refresh"; | 
					
						
							|  |  |  | const UPLOAD_EVENT = "upload"; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | const props = defineProps<{ slug: string }>(); | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | const emit = defineEmits<{ | 
					
						
							|  |  |  |   refresh: []; | 
					
						
							|  |  |  |   upload: [fileObject: File]; | 
					
						
							|  |  |  | }>(); | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | const url = ref(""); | 
					
						
							|  |  |  | const loading = ref(false); | 
					
						
							|  |  |  | const menu = ref(false); | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | function uploadImage(fileObject: File) { | 
					
						
							|  |  |  |   emit(UPLOAD_EVENT, fileObject); | 
					
						
							|  |  |  |   menu.value = false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-30 20:37:02 +02:00
										 |  |  | const api = useUserApi(); | 
					
						
							|  |  |  | async function getImageFromURL() { | 
					
						
							|  |  |  |   loading.value = true; | 
					
						
							|  |  |  |   if (await api.recipes.updateImagebyURL(props.slug, url.value)) { | 
					
						
							|  |  |  |     emit(REFRESH_EVENT); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   loading.value = false; | 
					
						
							|  |  |  |   menu.value = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18n = useI18n(); | 
					
						
							|  |  |  | const messages = computed(() => | 
					
						
							|  |  |  |   props.slug ? [""] : [i18n.t("recipe.save-recipe-before-use")], | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <style lang="scss" scoped></style> |