Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Improved layout of RecipeCard, RecipeView, and how steps work #3417

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions vue3/src/components/display/IngredientsInline.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script setup lang="ts">
import {PropType, reactive} from 'vue'
import {Step} from "@/openapi";

const props = defineProps({
step: {
type: Object as PropType<Step>,
required: true
}
})

const checked = reactive(Array(props.step?.ingredients.length).fill(false))
</script>

<template>
<v-chip v-if="props.step?.ingredients.length" variant="text" color="">Ingredients</v-chip>
<v-chip
v-for="ingredient in props.step.ingredients" :key="ingredient.id" class="ma-1"
@click="checked[ingredient.id || 0] = !checked[ingredient.id || 0]"
:class="{ 'checked': checked[ingredient.id || 0] }"
:color="checked[ingredient.id || 0] ? 'grey' : 'primary'"
:variant="checked[ingredient.id || 0] ? 'tonal' : 'elevated'"
>
<b>
{{ `${ingredient.amount}` + (ingredient.unit ? ` ${ingredient.unit.name}` : '') + '&nbsp'}}
</b>
{{ ingredient.food?.name }}
</v-chip>
</template>

<style scoped>

.checked {
text-decoration: line-through;
}

</style>
172 changes: 98 additions & 74 deletions vue3/src/components/display/RecipeCard.vue
Original file line number Diff line number Diff line change
@@ -1,62 +1,71 @@
<template>
<template v-if="!componentProps.loading">
<v-card :to="`/recipe/${componentProps.recipe.id}`" :style="{'height': componentProps.height}">
<v-tooltip
class="align-center justify-center"
location="top center" origin="overlap"
no-click-animation
:open-on-hover="componentProps.recipe.description != null && componentProps.recipe.description != ''"
contained
>
<template v-slot:activator="{ props }">
<recipe-image
height="70%"
width="100%"
:recipe="componentProps.recipe"
>

</recipe-image>

<v-divider class="p-0" v-if="componentProps.recipe.image == null"></v-divider>

</template>
<div v-if="componentProps.recipe.description != null && componentProps.recipe.description != ''">
{{ componentProps.recipe.description }}
</div>
</v-tooltip>
<v-card-item>
<div class="text-rows-2">
<h3>{{ componentProps.recipe.name }}</h3>
<template v-if="!componentProps.loading">
<v-card :to="`/recipe/${componentProps.recipe.id}`" :style="{'height': componentProps.height}">
<v-tooltip
class="align-center justify-center"
location="top center" origin="overlap"
no-click-animation
:open-on-hover="componentProps.recipe.description != null && componentProps.recipe.description != ''"
contained
>
<template v-slot:activator="{ props }">
<recipe-image
height="100%"
width="100%"
:recipe="componentProps.recipe"
cover
class="align-end"
>
<template #overlay>
<v-card
style="backdrop-filter: blur(2px); background: rgba(0, 0, 0, 0.5)"
>
<v-card-title class="text-white py-0">{{ componentProps.recipe.name }}
</v-card-title>

<div style="padding: 0 7px 7px 7px">
<v-chip size="small" color="white" variant="flat" style="margin-right: 5px"
v-for="badge in generateInfoBadges(componentProps.recipe, componentProps.info_badges)">
{{ badge }}
</v-chip>
<span v-if="componentProps.show_keywords">
<v-chip v-for="(keyword, index) in componentProps.recipe.keywords?.slice(0, 2)" :key="index"
size="small" color="white" variant="outlined" style="margin-right: 5px">
{{ keyword.label }}
</v-chip>
<v-chip v-if="(componentProps.recipe.keywords?.length || 0) > 2" size="small" color="white"
variant="outlined" style="margin-right: 5px">
{{ (componentProps.recipe.keywords?.length || 0) - 2 }} more
</v-chip>
</span>
</div>
<!-- TODO decide if context menu should be re-added (maybe make it a setting) -->
<!-- <recipe-context-menu class="float-end" :recipe="recipe"></recipe-context-menu>-->
</v-card-item>
<!-- <v-card-text>-->
<!-- <div class="text-rows-2">-->
<!-- <keywords-component variant="outlined" :keywords="componentProps.recipe.keywords">-->
<!-- <template #prepend>-->
<!-- <v-chip class="mb-1 me-1" size="x-small" prepend-icon="far fa-clock" label variant="outlined" v-if="componentProps.recipe.workingTime != undefined && componentProps.recipe.workingTime > 0">-->
<!-- {{ recipe.workingTime! + recipe.waitingTime! }}-->
<!-- </v-chip>-->
<!-- </template>-->
<!-- </keywords-component>-->
<!-- </div>-->
<!-- </v-card-text>-->

</v-card>
</template>
<template v-else>
<v-card :style="{'height': componentProps.height}">
<v-img src="../../assets/recipe_no_image.svg" cover height="60%"></v-img>
<v-card-title>
<v-skeleton-loader type="heading"></v-skeleton-loader>
</v-card-title>
<v-card-text>
<v-skeleton-loader type="subtitle"></v-skeleton-loader>
</v-card-text>
</v-card>

</template>

</v-card>
</template>
</recipe-image>

<v-divider class="p-0" v-if="componentProps.recipe.image == null"></v-divider>
</template>

<div v-if="componentProps.recipe.description != null && componentProps.recipe.description != ''">
{{ componentProps.recipe.description }}
</div>
</v-tooltip>

</v-card>
</template>
<template v-else>
<v-card :style="{'height': componentProps.height}">
<v-img src="../../assets/recipe_no_image.svg" cover height="60%"></v-img>
<v-card-title>
<v-skeleton-loader type="heading"></v-skeleton-loader>
</v-card-title>
<v-card-text>
<v-skeleton-loader type="subtitle"></v-skeleton-loader>
</v-card-text>
</v-card>

</template>

</template>

Expand All @@ -69,32 +78,47 @@ import RecipeContextMenu from "@/components/inputs/RecipeContextMenu.vue";
import RecipeImage from "@/components/display/RecipeImage.vue";

const componentProps = defineProps({
recipe: {type: {} as PropType<Recipe | RecipeOverview>, required: true,},
loading: {type: Boolean, required: false},
show_keywords: {type: Boolean, required: false},
show_description: {type: Boolean, required: false},
height: {type: String, required: false, default: '25vh'},
recipe: {type: {} as PropType<Recipe | RecipeOverview>, required: true,},
loading: {type: Boolean, required: false},
show_keywords: {type: Boolean, required: false},
show_description: {type: Boolean, required: false},
height: {type: String, required: false, default: '25vh'},
info_badges: {type: Array as PropType<infoBadgeProperties[]>, required: false, default: () => ['serves', 'time']}
})

// Can add more..
type infoBadgeProperties = 'serves' | 'time'

const generateInfoBadges = (recipe: Recipe | RecipeOverview, properties: infoBadgeProperties[]) => {
const badges = {
'serves': `Serves ${recipe.servings}`,
'time': `Ready in ${(recipe.waitingTime || 0) + (recipe.workingTime || 0)} min`,
}

return properties.map((property) => {
return badges[property]
})
}

</script>

<style scoped>

.text-rows-1 {
overflow: hidden;
text-overflow: clip;
display: -webkit-box;
-webkit-line-clamp: 1;
line-clamp: 1;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: clip;
display: -webkit-box;
-webkit-line-clamp: 1;
line-clamp: 1;
-webkit-box-orient: vertical;
}

.text-rows-2 {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
}
</style>
Loading