Skip to content

Commit

Permalink
refactor and styles b00tc4mp#407
Browse files Browse the repository at this point in the history
  • Loading branch information
berlem committed Apr 26, 2024
1 parent 16c878a commit 7242b13
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { ContentError, NotFoundError } from 'com/errors.js'
import logic from '../logic/index.js'
import { validate } from 'com'
import jwt from 'jsonwebtoken'

const complexRetrieve = async (req, res) => {
const userId = req.params.id

const token = req.headers.authorization.substring(7)

const payload = jwt.verify(token, process.env.JWT_SECRET)
const { sub: userId } = payload

try {
validate.id(userId, 'id')
Expand Down
4 changes: 3 additions & 1 deletion staff/belen-ivars/project/api/logic/editRecipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ export default async function editRecipe(userId, recipeId, title, description, i
const ingredientList = ingredients.split(', ')
for (let ingredient of ingredientList) {
const result = await checkIngredient(user.id, ingredient)

ingredientsOfThisRecipe.push(result._id)
}
} catch (error) {
throw new SystemError(error.message)
throw new SystemError(error.message, 'es trenca ací')
}

try {
console.log(recipe.id, 'hay recipe.id?')
recipeUpdated = await Recipe.findOneAndUpdate({ _id: recipe.id }, { ingredients: ingredientsOfThisRecipe })
console.log(ingredientsOfThisRecipe)
} catch (error) {
throw new SystemError(error.message)
}
Expand Down
4 changes: 2 additions & 2 deletions staff/belen-ivars/project/api/logic/helpers/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function text() {

function ingredientName() {

const ingredientNames = ['harina', 'azúcar', 'sal', 'aceite', 'leche', 'huevos', 'mantequilla', 'levadura', 'chocolate', 'vainilla'];
const ingredientNames = ['harina', 'azúcar', 'sal', 'aceite', 'leche', 'huevos', 'mantequilla', 'levadura', 'chocolate', 'vainilla', 'berenjena', 'ajo', 'queso', 'pan'];

const randomIngredient = ingredientNames[Math.floor(Math.random() * ingredientNames.length)];

Expand All @@ -29,7 +29,7 @@ function ingredientName() {

function ingredientObject() {

const ingredientNames = ['harina', 'azúcar', 'sal', 'aceite', 'leche', 'huevos', 'mantequilla', 'levadura', 'chocolate', 'vainilla'];
const ingredientNames = ['harina', 'azúcar', 'sal', 'aceite', 'leche', 'huevos', 'mantequilla', 'levadura', 'chocolate', 'vainilla', 'berenjena', 'ajo', 'queso', 'pan'];

const randomIngredientName = ingredientNames[Math.floor(Math.random() * ingredientNames.length)];

Expand Down
2 changes: 1 addition & 1 deletion staff/belen-ivars/project/api/logic/toggleFavRecipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NotFoundError } from 'com/errors.js'

export default async function toggleFavRecipe(userId, recipeId) {
validate.id(userId, 'user id')
validate.id(recipeId, 'user id')
validate.id(recipeId, 'recipe id')

let user

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export default function ComplexityOptions(props) {

return (
<div>
Tria la complexitat de la recepta:
<h2 className="form-subtitle-text">Tria la complexitat de la recepta:</h2>Tria la complexitat de la recepta:
<div className="flex flex-col">
<div>
<div className="form-options-text">
<input
type="checkbox"
id="easy"
Expand All @@ -35,7 +35,7 @@ export default function ComplexityOptions(props) {
/>
Fàcil
</div>
<div>
<div className="form-options-text">
<input
type="checkbox"
id="regular"
Expand All @@ -46,7 +46,7 @@ export default function ComplexityOptions(props) {
/>
Regular
</div>
<div>
<div className="form-options-text">
<input
type="checkbox"
id="complex"
Expand Down
8 changes: 4 additions & 4 deletions staff/belen-ivars/project/app/src/components/DietOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export default function DietOptions(props) {

return (
<div>
Selecciona una dieta:
<div className="flex flex-col">
<div>
<h2 className="form-subtitle-text">Selecciona una dieta: </h2>
<div className="form-options-text">
<input
type="checkbox"
id="gluten"
Expand All @@ -35,7 +35,7 @@ export default function DietOptions(props) {
/>
Gluten Free
</div>
<div>
<div className="form-options-text">
<input
type="checkbox"
id="vegan"
Expand All @@ -46,7 +46,7 @@ export default function DietOptions(props) {
/>
Vegà
</div>
<div>
<div className="form-options-text">
<input
type="checkbox"
id="veggie"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function FavsButton() {

return <div>

<Link className="link-profile-items" onClick={handleFavRecipesClick}>💛 Les millors 💛 </Link>
<Link className="link-profile-items" onClick={handleFavRecipesClick}> Les preferides </Link>


</div>
Expand Down
16 changes: 8 additions & 8 deletions staff/belen-ivars/project/app/src/components/MethodOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export default function MethodOptions(props) {

return (
<div>
Tria el mètode d'elaboració:
<h2 className="form-subtitle-text"> Tria el mètode d'elaboració: </h2>
<div className="flex flex-col">
<div>
<div className="form-options-text">
<input
type="checkbox"
id="steamed"
Expand All @@ -53,7 +53,7 @@ export default function MethodOptions(props) {
/>
Al vapor
</div>
<div>
<div className="form-options-text">
<input
type="checkbox"
id="oven"
Expand All @@ -64,7 +64,7 @@ export default function MethodOptions(props) {
/>
Forn
</div>
<div>
<div className="form-options-text">
<input
type="checkbox"
id="microwave"
Expand All @@ -75,7 +75,7 @@ export default function MethodOptions(props) {
/>
Microones
</div>
<div>
<div className="form-options-text">
<input
type="checkbox"
id="grill"
Expand All @@ -86,7 +86,7 @@ export default function MethodOptions(props) {
/>
Planxa
</div>
<div>
<div className="form-options-text">
<input
type="checkbox"
id="fresh"
Expand All @@ -97,7 +97,7 @@ export default function MethodOptions(props) {
/>
Fresc
</div>
<div>
<div className="form-options-text">
<input
type="checkbox"
id="cooked"
Expand All @@ -109,6 +109,6 @@ export default function MethodOptions(props) {
Cuit
</div>
</div>
</div>
</div >
);
}
2 changes: 1 addition & 1 deletion staff/belen-ivars/project/app/src/components/Recipe.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Recipe(props) {
{session.sessionUserId === props.recipe.author && view === null && <Button className='button-recipe' onClick={handleDeleteClick}>🗑️</Button>}
{session.sessionUserId === props.recipe.author && view === null && <Button className='button-recipe' onClick={() => props.onEditClick(props.recipe)}>Edit</Button>}
<Button className='button-recipe' onClick={handleToggleFavClick}>{props.recipe.fav ? '❤️' : '🤍'}</Button>
<Button onClick={handleRecipeClick} >Mostra més</Button>
<Button className='button-recipe' onClick={handleRecipeClick} >Mostra més</Button>

</div>

Expand Down
55 changes: 31 additions & 24 deletions staff/belen-ivars/project/app/src/components/Recipes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,46 @@ function Recipes(props) {
refreshRecipes()
}, [props.stamp])

return <div className="recipes">
return <div>

{view !== 'edit' && <>
{recipes.length === 0 ? <div >
<Container className="container-search-no-result">
<h1 className="recipe-title">No s'han trobat receptes</h1>
<p className="recipe-text">
Oooohhh, no hi ha receptes que conicidisquen amb els teus criteris de búsqueda!
</p>

</Container>
</div> : recipes.map(recipe => <Recipe onEditClick={handleEditClick} onRecipeClick={props.setRecipe} key={recipe._id} recipe={recipe} onError={props.onError} onSuccess={refreshRecipes} />)}
{recipes.length === 0 ?
<NoResults />
: <div className="recipes">{recipes.map(recipe => <Recipe onEditClick={handleEditClick} onRecipeClick={props.setRecipe} key={recipe._id} recipe={recipe} onError={props.onError} onSuccess={refreshRecipes} />)} </div>
}
</>}


{view === 'edit' && <Container className='new-form'>
<h2 className='form-title'>Modifica la teua recepta</h2>
<Button onClick={() => setView(null)}>Cancel</Button>
<Form id='edit-form' onSubmit={handleSubmit}>
<Field type='text' id='title' placeholder={recipeToEdit.title} />
<Field type='text' id='description' placeholder={recipeToEdit.description} />
<Field type='url' id='image' placeholder={recipeToEdit.image} />
<Field type='text' id='ingredients' placeholder={recipeToEdit.ingredients} />
<Field type='text' id='diet' placeholder={dietTranslations[recipeToEdit.diet]} />
<Field type='text' id='complexity' placeholder={complexityTranslations[recipeToEdit.complexity]} />
<Field type='text' id='method' placeholder={methodTranslations[recipeToEdit.method]} />
{view === 'edit' && <div className="recipe-complet-div">
<Container className='new-form'>
<h2 className='form-title'>Modifica la teua recepta</h2>
<Button className='button-recipe' onClick={() => setView(null)}>Cancel</Button>
<Form id='edit-form' onSubmit={handleSubmit}>
<Field type='text' id='title' placeholder={recipeToEdit.title}>Títol</Field>
<Field type='text' id='description' placeholder={recipeToEdit.description}>Descripció</Field>
<Field type='url' id='image' placeholder={recipeToEdit.image} >Imatge</Field>
<Field type='text' id='ingredients' placeholder={recipeToEdit.ingredients} >Ingredients</Field>
<Field type='text' id='diet' placeholder={dietTranslations[recipeToEdit.diet]} >Tipus de dieta</Field>
<Field type='text' id='complexity' placeholder={complexityTranslations[recipeToEdit.complexity]} >Nivell de complexitat</Field>
<Field type='text' id='method' placeholder={methodTranslations[recipeToEdit.method]} >Mètode d'elaboració</Field>

<Button type='submit' > Modificar </Button>
<Button className='button-recipe' type='submit' > Modificar </Button>

</Form>
</Container>}
</Form>
</Container>
</div>}

</div >
}

const NoResults = () => {
return <Container className="container-search-no-result">
<h1 className="recipe-title">No s'han trobat receptes</h1>
<p className="recipe-text">
Oooohhh, no hi ha receptes que conicidisquen amb els teus criteris de búsqueda!
</p>

</Container>
}

export default Recipes
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function TopProfileImage({ name, email }) {

return <div className='profile-menu'>
<Link className="link-profile-menu" onClick={handleProfileClick}>
<Gravatar email={email} /> {name}
<Gravatar className="avatar" email={email} /> {name}
{isOpen && (
<Container >
<FavsButton />
Expand Down
Loading

0 comments on commit 7242b13

Please sign in to comment.