mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-25 08:09:41 +02:00
feat(frontend): 🚧 CRUD Functionality
This commit is contained in:
parent
00a8fdda41
commit
afcad2f701
49 changed files with 845 additions and 275 deletions
|
@ -56,7 +56,7 @@ function getRequests(axoisInstance: NuxtAxiosInstance): ApiRequestInstance {
|
|||
|
||||
|
||||
|
||||
export const useApi = function (): Api {
|
||||
export const useApiSingleton = function (): Api {
|
||||
const { $axios } = useContext();
|
||||
const requests = getRequests($axios);
|
||||
|
||||
|
|
38
frontend/composables/use-recipe-context.ts
Normal file
38
frontend/composables/use-recipe-context.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { useAsync, ref } from "@nuxtjs/composition-api";
|
||||
import { useApiSingleton } from "~/composables/use-api";
|
||||
import { Recipe } from "~/types/api-types/recipe";
|
||||
|
||||
export const useRecipeContext = function () {
|
||||
const api = useApiSingleton();
|
||||
const loading = ref(false)
|
||||
|
||||
|
||||
function getBySlug(slug: string) {
|
||||
loading.value = true
|
||||
const recipe = useAsync(async () => {
|
||||
const { data } = await api.recipes.getOne(slug);
|
||||
return data;
|
||||
}, slug);
|
||||
|
||||
loading.value = false
|
||||
|
||||
return recipe;
|
||||
}
|
||||
|
||||
async function deleteRecipe(slug: string) {
|
||||
loading.value = true
|
||||
const { data } = await api.recipes.deleteOne(slug);
|
||||
loading.value = false
|
||||
return data;
|
||||
}
|
||||
|
||||
async function updateRecipe(slug: string, recipe: Recipe) {
|
||||
loading.value = true
|
||||
const { data } = await api.recipes.updateOne(slug, recipe);
|
||||
loading.value = false
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
return {loading, getBySlug, deleteRecipe, updateRecipe}
|
||||
};
|
|
@ -1,8 +1,11 @@
|
|||
const EMAIL_REGEX =
|
||||
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@(([[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
||||
|
||||
const URL_REGEX = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,256}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/gm;
|
||||
|
||||
export const validators = {
|
||||
required: (v: string) => !!v || "This Field is Required",
|
||||
email: (v: string) => !v || EMAIL_REGEX.test(v) || "Email Must Be Valid",
|
||||
whitespace: (v: string) => !v || v.split(" ").length <= 1 || "No Whitespace Allowed"
|
||||
whitespace: (v: string) => !v || v.split(" ").length <= 1 || "No Whitespace Allowed",
|
||||
url: (v: string) => !v || URL_REGEX.test(v) || "Must Be A Valid URL",
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue