From f042214c9226b215314adbaf4d36a1cf20ba8127 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Sun, 4 Mar 2018 23:37:10 +0100 Subject: [PATCH] Better feedbacks in UI --- cuizin/js_src/api.js | 64 ++++++++++++++++++++++++ cuizin/js_src/components/ErrorDialog.vue | 33 ++++++++++++ cuizin/js_src/components/Home.vue | 15 ++++-- cuizin/js_src/components/New.vue | 48 ++++++++++++------ cuizin/js_src/components/Recipe.vue | 54 +++++++++++++------- cuizin/web.py | 22 ++++---- 6 files changed, 188 insertions(+), 48 deletions(-) create mode 100644 cuizin/js_src/api.js create mode 100644 cuizin/js_src/components/ErrorDialog.vue diff --git a/cuizin/js_src/api.js b/cuizin/js_src/api.js new file mode 100644 index 0000000..8491e47 --- /dev/null +++ b/cuizin/js_src/api.js @@ -0,0 +1,64 @@ +import * as constants from '@/constants'; + + +function loadJSON(response) { + return response.json(); +} + + +function _postProcessRecipes(response) { + return loadJSON(response) + .then((jsonResponse) => { + const parsed = jsonResponse; + + if (parsed.recipes) { + // Customize instructions + parsed.recipes = parsed.recipes.map(item => Object.assign( + item, + { + instructions: item.instructions.split(/\r\n/).map( + line => line.trim(), + ), + }, + )); + } + + return parsed; + }); +} + + +export function loadRecipes() { + return fetch(`${constants.API_URL}api/v1/recipes`) + .then(_postProcessRecipes); +} + + +export function loadRecipe(id) { + return fetch(`${constants.API_URL}api/v1/recipe/${id}`) + .then(_postProcessRecipes); +} + + +export function refetchRecipe(id) { + return fetch(`${constants.API_URL}api/v1/recipe/${id}/refetch`, { + method: 'GET', + }) + .then(_postProcessRecipes); +} + + +export function postRecipe(recipe) { + return fetch(`${constants.API_URL}api/v1/recipes`, { + method: 'POST', + body: JSON.stringify(recipe), + }) + .then(_postProcessRecipes); +} + + +export function deleteRecipe(id) { + return fetch(`${constants.API_URL}api/v1/recipe/${id}`, { + method: 'DELETE', + }); +} diff --git a/cuizin/js_src/components/ErrorDialog.vue b/cuizin/js_src/components/ErrorDialog.vue new file mode 100644 index 0000000..142aa64 --- /dev/null +++ b/cuizin/js_src/components/ErrorDialog.vue @@ -0,0 +1,33 @@ + + + diff --git a/cuizin/js_src/components/Home.vue b/cuizin/js_src/components/Home.vue index 9054d05..cdd3d6f 100644 --- a/cuizin/js_src/components/Home.vue +++ b/cuizin/js_src/components/Home.vue @@ -2,6 +2,8 @@ + +

Start by adding a recipe with the "+" button on the top right corner!

@@ -32,16 +34,20 @@