From 3e3b43c9770ca0bce90fa05dabb42727d03c0715 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 1 Apr 2022 11:05:25 -0800 Subject: [PATCH] feat: add on mounted hook for bookmarklets (#1120) * add utility type to hide Advanced items * add default text * fix #1115 and minor refactorings * generate types * hotfix: add validator to catch null vlaues --- .../Domain/Recipe/RecipeOrganizerSelector.vue | 2 + frontend/components/global/AdvancedOnly.vue | 23 +++++ frontend/pages/recipe/create.vue | 93 +++++++++++++------ frontend/types/components.d.ts | 4 + mealie/schema/cookbook/cookbook.py | 4 + 5 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 frontend/components/global/AdvancedOnly.vue diff --git a/frontend/components/Domain/Recipe/RecipeOrganizerSelector.vue b/frontend/components/Domain/Recipe/RecipeOrganizerSelector.vue index 5d924dce..26a55c5a 100644 --- a/frontend/components/Domain/Recipe/RecipeOrganizerSelector.vue +++ b/frontend/components/Domain/Recipe/RecipeOrganizerSelector.vue @@ -87,6 +87,8 @@ export default defineComponent({ return i18n.t("category.categories"); case "tool": return "Tools"; + default: + return "Organizer"; } }); diff --git a/frontend/components/global/AdvancedOnly.vue b/frontend/components/global/AdvancedOnly.vue new file mode 100644 index 00000000..37986eac --- /dev/null +++ b/frontend/components/global/AdvancedOnly.vue @@ -0,0 +1,23 @@ + + + diff --git a/frontend/pages/recipe/create.vue b/frontend/pages/recipe/create.vue index 8e58e4a0..2d80ace7 100644 --- a/frontend/pages/recipe/create.vue +++ b/frontend/pages/recipe/create.vue @@ -257,33 +257,36 @@ - + :items="allCategories || []" + selector-type="category" + :input-attrs="{ + filled: true, + singleLine: true, + dense: true, + rounded: true, + class: 'rounded-lg', + hideDetails: true, + clearable: true, + }" + /> - + :items="allTags || []" + selector-type="tag" + :input-attrs="{ + filled: true, + singleLine: true, + dense: true, + rounded: true, + class: 'rounded-lg', + hideDetails: true, + clearable: true, + }" + /> @@ -307,9 +310,11 @@ - - Looking For Migrations? - + + + Looking For Migrations? + + @@ -325,16 +330,19 @@ import { useRoute, } from "@nuxtjs/composition-api"; import { AxiosResponse } from "axios"; +import { onMounted } from "vue-demi"; import { useUserApi } from "~/composables/api"; -import RecipeCategoryTagSelector from "~/components/Domain/Recipe/RecipeCategoryTagSelector.vue"; import { validators } from "~/composables/use-validators"; import { Recipe } from "~/types/api-types/recipe"; import { alert } from "~/composables/use-toast"; import { VForm } from "~/types/vuetify"; import { MenuItem } from "~/components/global/BaseOverflowButton.vue"; +import AdvancedOnly from "~/components/global/AdvancedOnly.vue"; +import RecipeOrganizerSelector from "~/components/Domain/Recipe/RecipeOrganizerSelector.vue"; +import { useCategories, useTags } from "~/composables/recipes"; export default defineComponent({ - components: { RecipeCategoryTagSelector }, + components: { AdvancedOnly, RecipeOrganizerSelector }, setup() { const state = reactive({ error: false, @@ -405,6 +413,16 @@ export default defineComponent({ }, }); + onMounted(() => { + if (!recipeUrl.value) { + return; + } + + if (recipeUrl.value.includes("https")) { + createByUrl(recipeUrl.value); + } + }); + // =================================================== // Recipe Debug URL Scraper @@ -412,7 +430,11 @@ export default defineComponent({ const debugData = ref(null); - async function debugUrl(url: string) { + async function debugUrl(url: string | null) { + if (url === null) { + return; + } + state.loading = true; const { data } = await api.recipes.testCreateOneUrl(url); @@ -425,7 +447,10 @@ export default defineComponent({ // Recipe URL Import const domUrlForm = ref(null); - async function createByUrl(url: string) { + async function createByUrl(url: string | null) { + if (url === null) { + return; + } if (!domUrlForm.value?.validate() || url === "") { console.log("Invalid URL", url); return; @@ -487,7 +512,15 @@ export default defineComponent({ } } + const { allTags, useAsyncGetAll: getAllTags } = useTags(); + const { allCategories, useAsyncGetAll: getAllCategories } = useCategories(); + + getAllTags(); + getAllCategories(); + return { + allTags, + allCategories, tab, recipeUrl, bulkCreate, diff --git a/frontend/types/components.d.ts b/frontend/types/components.d.ts index 146de564..450198ea 100644 --- a/frontend/types/components.d.ts +++ b/frontend/types/components.d.ts @@ -11,6 +11,7 @@ import BaseDialog from "@/components/global/BaseDialog.vue"; import RecipeJsonEditor from "@/components/global/RecipeJsonEditor.vue"; import StatsCards from "@/components/global/StatsCards.vue"; + import HelpIcon from "@/components/global/HelpIcon.vue"; import InputLabelType from "@/components/global/InputLabelType.vue"; import BaseStatCard from "@/components/global/BaseStatCard.vue"; import DevDumpJson from "@/components/global/DevDumpJson.vue"; @@ -23,6 +24,7 @@ import BaseDivider from "@/components/global/BaseDivider.vue"; import AutoForm from "@/components/global/AutoForm.vue"; import AppButtonUpload from "@/components/global/AppButtonUpload.vue"; + import AdvancedOnly from "@/components/global/AdvancedOnly.vue"; import BasePageTitle from "@/components/global/BasePageTitle.vue"; import ButtonLink from "@/components/global/ButtonLink.vue"; @@ -47,6 +49,7 @@ declare module "vue" { BaseDialog: typeof BaseDialog; RecipeJsonEditor: typeof RecipeJsonEditor; StatsCards: typeof StatsCards; + HelpIcon: typeof HelpIcon; InputLabelType: typeof InputLabelType; BaseStatCard: typeof BaseStatCard; DevDumpJson: typeof DevDumpJson; @@ -59,6 +62,7 @@ declare module "vue" { BaseDivider: typeof BaseDivider; AutoForm: typeof AutoForm; AppButtonUpload: typeof AppButtonUpload; + AdvancedOnly: typeof AdvancedOnly; BasePageTitle: typeof BasePageTitle; ButtonLink: typeof ButtonLink; // Layout Components diff --git a/mealie/schema/cookbook/cookbook.py b/mealie/schema/cookbook/cookbook.py index 5089fb6a..641e83dc 100644 --- a/mealie/schema/cookbook/cookbook.py +++ b/mealie/schema/cookbook/cookbook.py @@ -17,6 +17,10 @@ class CreateCookBook(MealieModel): tags: list[TagBase] = [] tools: list[RecipeTool] = [] + @validator("public", always=True, pre=True) + def validate_public(public: bool | None, values: dict) -> bool: # type: ignore + return False if public is None else public + @validator("slug", always=True, pre=True) def validate_slug(slug: str, values): # type: ignore name: str = values["name"]