| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-data-table | 
					
						
							|  |  |  |     v-model="selected" | 
					
						
							|  |  |  |     item-key="id" | 
					
						
							|  |  |  |     show-select | 
					
						
							| 
									
										
										
										
											2024-09-22 09:59:20 -05:00
										 |  |  |     sort-by="dateAdded" | 
					
						
							|  |  |  |     sort-desc | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     :headers="headers" | 
					
						
							|  |  |  |     :items="recipes" | 
					
						
							|  |  |  |     :items-per-page="15" | 
					
						
							|  |  |  |     class="elevation-0" | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     :loading="loading" | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     @input="setValue(selected)" | 
					
						
							|  |  |  |   > | 
					
						
							|  |  |  |     <template #body.preappend> | 
					
						
							|  |  |  |       <tr> | 
					
						
							|  |  |  |         <td></td> | 
					
						
							|  |  |  |         <td>Hello</td> | 
					
						
							|  |  |  |         <td colspan="4"></td> | 
					
						
							|  |  |  |       </tr> | 
					
						
							|  |  |  |     </template> | 
					
						
							| 
									
										
										
										
											2023-03-21 14:47:26 -05:00
										 |  |  |     <template #item.name="{ item }"> | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |       <a :href="`/g/${groupSlug}/r/${item.slug}`" style="color: inherit; text-decoration: inherit; " @click="$emit('click')">{{ item.name }}</a> | 
					
						
							| 
									
										
										
										
											2023-03-21 14:47:26 -05:00
										 |  |  |     </template> | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     <template #item.tags="{ item }"> | 
					
						
							| 
									
										
										
										
											2025-01-14 09:18:16 -08:00
										 |  |  |       <RecipeChip small :items="item.tags" :is-category="false" url-prefix="tags" @item-selected="filterItems" /> | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     </template> | 
					
						
							|  |  |  |     <template #item.recipeCategory="{ item }"> | 
					
						
							| 
									
										
										
										
											2025-01-14 09:18:16 -08:00
										 |  |  |       <RecipeChip small :items="item.recipeCategory" @item-selected="filterItems" /> | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     </template> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     <template #item.tools="{ item }"> | 
					
						
							| 
									
										
										
										
											2025-01-14 09:18:16 -08:00
										 |  |  |       <RecipeChip small :items="item.tools" url-prefix="tools" @item-selected="filterItems" /> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     </template> | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     <template #item.userId="{ item }"> | 
					
						
							|  |  |  |       <v-list-item class="justify-start"> | 
					
						
							| 
									
										
										
										
											2024-10-11 19:36:26 -05:00
										 |  |  |         <UserAvatar :user-id="item.userId" :tooltip="false" size="40" /> | 
					
						
							| 
									
										
										
										
											2024-10-19 04:33:32 -05:00
										 |  |  |         <v-list-item-content class="pl-2"> | 
					
						
							|  |  |  |           <v-list-item-title class="text-left"> | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |             {{ getMember(item.userId) }} | 
					
						
							|  |  |  |           </v-list-item-title> | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |         </v-list-item-content> | 
					
						
							|  |  |  |       </v-list-item> | 
					
						
							|  |  |  |     </template> | 
					
						
							| 
									
										
										
										
											2024-09-22 09:59:20 -05:00
										 |  |  |     <template #item.dateAdded="{ item }"> | 
					
						
							|  |  |  |       {{ formatDate(item.dateAdded) }} | 
					
						
							|  |  |  |     </template> | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |   </v-data-table> | 
					
						
							|  |  |  | </template> | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2025-01-14 09:18:16 -08:00
										 |  |  | import { computed, defineComponent, onMounted, ref, useContext, useRouter } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2023-03-21 14:47:26 -05:00
										 |  |  | import UserAvatar from "../User/UserAvatar.vue"; | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  | import RecipeChip from "./RecipeChips.vue"; | 
					
						
							| 
									
										
										
										
											2025-01-14 09:18:16 -08:00
										 |  |  | import { Recipe, RecipeCategory, RecipeTool } from "~/lib/api/types/recipe"; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  | import { useUserApi } from "~/composables/api"; | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  | import { UserSummary } from "~/lib/api/types/user"; | 
					
						
							| 
									
										
										
										
											2025-01-14 09:18:16 -08:00
										 |  |  | import { RecipeTag } from "~/lib/api/types/household"; | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const INPUT_EVENT = "input"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | interface ShowHeaders { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |   id: boolean; | 
					
						
							|  |  |  |   owner: boolean; | 
					
						
							|  |  |  |   tags: boolean; | 
					
						
							|  |  |  |   categories: boolean; | 
					
						
							|  |  |  |   tools: boolean; | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  |   recipeServings: boolean; | 
					
						
							|  |  |  |   recipeYieldQuantity: boolean; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |   recipeYield: boolean; | 
					
						
							|  |  |  |   dateAdded: boolean; | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							| 
									
										
										
										
											2023-03-21 14:47:26 -05:00
										 |  |  |   components: { RecipeChip, UserAvatar }, | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |   props: { | 
					
						
							|  |  |  |     value: { | 
					
						
							|  |  |  |       type: Array, | 
					
						
							|  |  |  |       required: false, | 
					
						
							|  |  |  |       default: () => [], | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     loading: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       required: false, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     recipes: { | 
					
						
							|  |  |  |       type: Array as () => Recipe[], | 
					
						
							|  |  |  |       default: () => [], | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     showHeaders: { | 
					
						
							|  |  |  |       type: Object as () => ShowHeaders, | 
					
						
							|  |  |  |       required: false, | 
					
						
							|  |  |  |       default: () => { | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |           id: true, | 
					
						
							|  |  |  |           owner: false, | 
					
						
							|  |  |  |           tags: true, | 
					
						
							|  |  |  |           categories: true, | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  |           recipeServings: true, | 
					
						
							|  |  |  |           recipeYieldQuantity: true, | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |           recipeYield: true, | 
					
						
							|  |  |  |           dateAdded: true, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   setup(props, context) { | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |     const { $auth, i18n } = useContext(); | 
					
						
							|  |  |  |     const groupSlug = $auth.user?.groupSlug; | 
					
						
							| 
									
										
										
										
											2025-01-14 09:18:16 -08:00
										 |  |  |     const router = useRouter(); | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     function setValue(value: Recipe[]) { | 
					
						
							|  |  |  |       context.emit(INPUT_EVENT, value); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const headers = computed(() => { | 
					
						
							|  |  |  |       const hdrs = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |       if (props.showHeaders.id) { | 
					
						
							| 
									
										
										
										
											2022-08-10 07:12:45 +02:00
										 |  |  |         hdrs.push({ text: i18n.t("general.id"), value: "id" }); | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |       if (props.showHeaders.owner) { | 
					
						
							| 
									
										
										
										
											2022-08-10 07:12:45 +02:00
										 |  |  |         hdrs.push({ text: i18n.t("general.owner"), value: "userId", align: "center" }); | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-08-10 07:12:45 +02:00
										 |  |  |       hdrs.push({ text: i18n.t("general.name"), value: "name" }); | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |       if (props.showHeaders.categories) { | 
					
						
							| 
									
										
										
										
											2022-08-10 07:12:45 +02:00
										 |  |  |         hdrs.push({ text: i18n.t("recipe.categories"), value: "recipeCategory" }); | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |       if (props.showHeaders.tags) { | 
					
						
							| 
									
										
										
										
											2022-08-10 07:12:45 +02:00
										 |  |  |         hdrs.push({ text: i18n.t("tag.tags"), value: "tags" }); | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |       if (props.showHeaders.tools) { | 
					
						
							| 
									
										
										
										
											2022-08-10 07:12:45 +02:00
										 |  |  |         hdrs.push({ text: i18n.t("tool.tools"), value: "tools" }); | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  |       if (props.showHeaders.recipeServings) { | 
					
						
							|  |  |  |         hdrs.push({ text: i18n.t("recipe.servings"), value: "recipeServings" }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (props.showHeaders.recipeYieldQuantity) { | 
					
						
							|  |  |  |         hdrs.push({ text: i18n.t("recipe.yield"), value: "recipeYieldQuantity" }); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |       if (props.showHeaders.recipeYield) { | 
					
						
							| 
									
										
										
										
											2024-11-20 08:46:27 -06:00
										 |  |  |         hdrs.push({ text: i18n.t("recipe.yield-text"), value: "recipeYield" }); | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |       if (props.showHeaders.dateAdded) { | 
					
						
							| 
									
										
										
										
											2022-08-10 07:12:45 +02:00
										 |  |  |         hdrs.push({ text: i18n.t("general.date-added"), value: "dateAdded" }); | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       return hdrs; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-22 09:59:20 -05:00
										 |  |  |     function formatDate(date: string) { | 
					
						
							|  |  |  |       try { | 
					
						
							|  |  |  |         return i18n.d(Date.parse(date), "medium"); | 
					
						
							|  |  |  |       } catch { | 
					
						
							|  |  |  |         return ""; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     // ============
 | 
					
						
							|  |  |  |     // Group Members
 | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |     const api = useUserApi(); | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |     const members = ref<UserSummary[]>([]); | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async function refreshMembers() { | 
					
						
							|  |  |  |       const { data } = await api.groups.fetchMembers(); | 
					
						
							|  |  |  |       if (data) { | 
					
						
							| 
									
										
										
										
											2024-10-11 19:36:26 -05:00
										 |  |  |         members.value = data.items; | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-14 09:18:16 -08:00
										 |  |  |     function filterItems(item: RecipeTag | RecipeCategory | RecipeTool, itemType: string) { | 
					
						
							|  |  |  |       if (!groupSlug || !item.id) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       router.push(`/g/${groupSlug}?${itemType}=${item.id}`); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     onMounted(() => { | 
					
						
							|  |  |  |       refreshMembers(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     function getMember(id: string) { | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       if (members.value[0]) { | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |         return members.value.find((m) => m.id === id)?.fullName; | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-10 07:12:45 +02:00
										 |  |  |       return i18n.t("general.none"); | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |     return { | 
					
						
							|  |  |  |       groupSlug, | 
					
						
							|  |  |  |       setValue, | 
					
						
							|  |  |  |       headers, | 
					
						
							| 
									
										
										
										
											2024-09-22 09:59:20 -05:00
										 |  |  |       formatDate, | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |       members, | 
					
						
							|  |  |  |       getMember, | 
					
						
							| 
									
										
										
										
											2025-01-14 09:18:16 -08:00
										 |  |  |       filterItems, | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-10-18 19:41:41 -08:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   data() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       selected: [], | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   watch: { | 
					
						
							|  |  |  |     value(val) { | 
					
						
							|  |  |  |       this.selected = val; | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | </script> |