mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-04 03:03:18 -05:00 
			
		
		
		
	More localization (#358)
* Translate missing items on About page * Localize import summary dialog * Make site menu translation reactive * Localize import options * Include semi colon in string * Move API texts to frontend + better status codes * Provide feedback to user when no meal is planned * Fix API tests after latest rework * Add warning for API changes in changelog * Refactor API texts handling * Refactor API texts handling #2 * Better API feedback * Rearrange strings hierarchy * Add messages upon recipe updated * Fix 'recipe effected' typo * Remove snackbar usage in backend * Translate toolbox * Provide feedback for tags CRUD * Fix messed up merge * Translate sign-up form * Better feedback for sign-up CRUD * Refactor log-in API texts handling * No error message when user is not authenticated * Remove unimportant console log
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
import { baseURL } from "./api-utils";
 | 
			
		||||
import { apiReq } from "./api-utils";
 | 
			
		||||
import { store } from "../store";
 | 
			
		||||
import { router } from "../main";
 | 
			
		||||
import i18n from '@/i18n.js';
 | 
			
		||||
 | 
			
		||||
const prefix = baseURL + "recipes/";
 | 
			
		||||
 | 
			
		||||
@@ -26,9 +26,12 @@ export const recipeAPI = {
 | 
			
		||||
   * @returns {string} Recipe Slug
 | 
			
		||||
   */
 | 
			
		||||
  async createByURL(recipeURL) {
 | 
			
		||||
    let response = await apiReq.post(recipeURLs.createByURL, {
 | 
			
		||||
      url: recipeURL,
 | 
			
		||||
    });
 | 
			
		||||
    const response = await apiReq.post(
 | 
			
		||||
      recipeURLs.createByURL, 
 | 
			
		||||
      { url: recipeURL },
 | 
			
		||||
      function() { return i18n.t('recipe.recipe-creation-failed'); },
 | 
			
		||||
      function() { return i18n.t('recipe.recipe-created'); }
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    store.dispatch("requestRecentRecipes");
 | 
			
		||||
    return response;
 | 
			
		||||
@@ -43,7 +46,12 @@ export const recipeAPI = {
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  async create(recipeData) {
 | 
			
		||||
    let response = await apiReq.post(recipeURLs.create, recipeData);
 | 
			
		||||
    const response = await apiReq.post(
 | 
			
		||||
      recipeURLs.create, 
 | 
			
		||||
      recipeData,
 | 
			
		||||
      function() { return i18n.t('recipe.recipe-creation-failed'); },
 | 
			
		||||
      function() { return i18n.t('recipe.recipe-created'); }
 | 
			
		||||
    );
 | 
			
		||||
    store.dispatch("requestRecentRecipes");
 | 
			
		||||
    return response.data;
 | 
			
		||||
  },
 | 
			
		||||
@@ -53,14 +61,24 @@ export const recipeAPI = {
 | 
			
		||||
    return response.data;
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  async updateImage(recipeSlug, fileObject) {
 | 
			
		||||
    const fd = new FormData();
 | 
			
		||||
    fd.append("image", fileObject);
 | 
			
		||||
    fd.append("extension", fileObject.name.split(".").pop());
 | 
			
		||||
    let response = apiReq.put(recipeURLs.updateImage(recipeSlug), fd);
 | 
			
		||||
    return response;
 | 
			
		||||
  },
 | 
			
		||||
  updateImage(recipeSlug, fileObject, overrideSuccessMsg = false) {
 | 
			
		||||
    const formData = new FormData();
 | 
			
		||||
    formData.append("image", fileObject);
 | 
			
		||||
    formData.append("extension", fileObject.name.split(".").pop());
 | 
			
		||||
 | 
			
		||||
    let successMessage = null;
 | 
			
		||||
    if(!overrideSuccessMsg) {
 | 
			
		||||
      successMessage = function() { return overrideSuccessMsg ? null : i18n.t('recipe.recipe-image-updated'); };
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return apiReq.put(
 | 
			
		||||
      recipeURLs.updateImage(recipeSlug), 
 | 
			
		||||
      formData,
 | 
			
		||||
      function() { return i18n.t('general.image-upload-failed'); },
 | 
			
		||||
      successMessage
 | 
			
		||||
    );
 | 
			
		||||
  },
 | 
			
		||||
  
 | 
			
		||||
  async createAsset(recipeSlug, fileObject, name, icon) {
 | 
			
		||||
    const fd = new FormData();
 | 
			
		||||
    fd.append("file", fileObject);
 | 
			
		||||
@@ -70,17 +88,27 @@ export const recipeAPI = {
 | 
			
		||||
    let response = apiReq.post(recipeURLs.createAsset(recipeSlug), fd);
 | 
			
		||||
    return response;
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  async updateImagebyURL(slug, url) {
 | 
			
		||||
    const response = apiReq.post(recipeURLs.updateImage(slug), { url: url });
 | 
			
		||||
    return response;
 | 
			
		||||
  
 | 
			
		||||
  updateImagebyURL(slug, url) {
 | 
			
		||||
    return apiReq.post(
 | 
			
		||||
      recipeURLs.updateImage(slug), 
 | 
			
		||||
      { url: url },
 | 
			
		||||
      function() { return i18n.t('general.image-upload-failed'); },
 | 
			
		||||
      function() { return i18n.t('recipe.recipe-image-updated'); }
 | 
			
		||||
    );
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  async update(data) {
 | 
			
		||||
    console.log(data)
 | 
			
		||||
    let response = await apiReq.put(recipeURLs.update(data.slug), data);
 | 
			
		||||
    store.dispatch("patchRecipe", response.data);
 | 
			
		||||
    return response.data.slug; // ! Temporary until I rewrite to refresh page without additional request
 | 
			
		||||
    let response = await apiReq.put(
 | 
			
		||||
      recipeURLs.update(data.slug),
 | 
			
		||||
      data, 
 | 
			
		||||
      function() { return i18n.t('recipe.recipe-update-failed'); },
 | 
			
		||||
      function() { return i18n.t('recipe.recipe-updated'); }
 | 
			
		||||
    );
 | 
			
		||||
    if(response) {
 | 
			
		||||
      store.dispatch("patchRecipe", response.data);
 | 
			
		||||
      return response.data.slug; // ! Temporary until I rewrite to refresh page without additional request
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  async patch(data) {
 | 
			
		||||
@@ -89,10 +117,13 @@ export const recipeAPI = {
 | 
			
		||||
    return response.data;
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  async delete(recipeSlug) {
 | 
			
		||||
    await apiReq.delete(recipeURLs.delete(recipeSlug));
 | 
			
		||||
    store.dispatch("requestRecentRecipes");
 | 
			
		||||
    router.push(`/`);
 | 
			
		||||
  delete(recipeSlug) {
 | 
			
		||||
    return apiReq.delete(
 | 
			
		||||
      recipeURLs.delete(recipeSlug),
 | 
			
		||||
      null,
 | 
			
		||||
      function() { return i18n.t('recipe.unable-to-delete-recipe'); },
 | 
			
		||||
      function() { return i18n.t('recipe.recipe-deleted'); }
 | 
			
		||||
    );
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  async allSummary(start = 0, limit = 9999) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user