Skip to content

Commit

Permalink
Add total time to recipe cards with a toggle switch
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcat committed Nov 8, 2023
1 parent 4b55b83 commit 364ffeb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
15 changes: 13 additions & 2 deletions frontend/components/Domain/Recipe/RecipeCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
{{ name }}
</div>
</v-card-title>

<v-card-text v-if="totalTime && displayTotalTimes" class="px-1 pt-1 pb-0">
<RecipeTimeCard :total-time="totalTime"/>
</v-card-text>
<slot name="actions">
<v-card-actions class="px-1">
<RecipeFavoriteBadge v-if="isOwnGroup" class="absolute" :slug="slug" show-always />
Expand Down Expand Up @@ -74,10 +76,11 @@ import RecipeChips from "./RecipeChips.vue";
import RecipeContextMenu from "./RecipeContextMenu.vue";
import RecipeCardImage from "./RecipeCardImage.vue";
import RecipeRating from "./RecipeRating.vue";
import RecipeTimeCard from "./RecipeTimeCard.vue";
import { useLoggedInState } from "~/composables/use-logged-in-state";
export default defineComponent({
components: { RecipeFavoriteBadge, RecipeChips, RecipeContextMenu, RecipeRating, RecipeCardImage },
components: { RecipeFavoriteBadge, RecipeChips, RecipeContextMenu, RecipeRating, RecipeCardImage, RecipeTimeCard },
props: {
name: {
type: String,
Expand Down Expand Up @@ -117,6 +120,14 @@ export default defineComponent({
type: Number,
default: 200,
},
totalTime: {
type: Number,
default: 0
},
displayTotalTimes: {
type: Boolean,
default: false
}
},
setup(props) {
const { $auth } = useContext();
Expand Down
13 changes: 13 additions & 0 deletions frontend/components/Domain/Recipe/RecipeCardMobile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<v-list-item-subtitle>
<SafeMarkdown :source="description" />
</v-list-item-subtitle>
<v-card-text v-if="totalTime && displayTotalTimes" class="px-0 py-0 mb-0">
<RecipeTimeCard :total-time="totalTime"/>
</v-card-text>
<div class="d-flex flex-wrap justify-end align-center">
<slot name="actions">
<RecipeFavoriteBadge v-if="isOwnGroup" :slug="slug" show-always />
Expand Down Expand Up @@ -83,13 +86,15 @@ import { computed, defineComponent, useContext, useRoute } from "@nuxtjs/composi
import RecipeFavoriteBadge from "./RecipeFavoriteBadge.vue";
import RecipeContextMenu from "./RecipeContextMenu.vue";
import RecipeCardImage from "./RecipeCardImage.vue";
import RecipeTimeCard from "./RecipeTimeCard.vue";
import { useLoggedInState } from "~/composables/use-logged-in-state";
export default defineComponent({
components: {
RecipeFavoriteBadge,
RecipeContextMenu,
RecipeCardImage,
RecipeTimeCard,
},
props: {
name: {
Expand Down Expand Up @@ -129,6 +134,14 @@ export default defineComponent({
type: Boolean,
default: false,
},
totalTime: {
type: Number,
default: 0,
},
displayTotalTimes: {
type: Boolean,
default: false
}
},
setup(props) {
const { $auth } = useContext();
Expand Down
8 changes: 8 additions & 0 deletions frontend/components/Domain/Recipe/RecipeCardSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
:image="recipe.image"
:tags="recipe.tags"
:recipe-id="recipe.id"
:total-time="recipe.totalTime"
:display-total-times="displayTotalTimes"
/>
</v-lazy>
</v-col>
Expand All @@ -104,6 +106,8 @@
:image="recipe.image"
:tags="recipe.tags"
:recipe-id="recipe.id"
:total-time="recipe.totalTime"
:display-total-times="displayTotalTimes"
/>
</v-lazy>
</v-col>
Expand Down Expand Up @@ -173,6 +177,10 @@ export default defineComponent({
type: Object as () => RecipeSearchQuery,
default: null,
},
displayTotalTimes: {
type: Boolean,
default: false
}
},
setup(props, context) {
const preferences = useUserSortPreferences();
Expand Down
8 changes: 8 additions & 0 deletions frontend/components/Domain/Recipe/RecipeExplorerPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<v-card>
<v-card-text>
<v-switch v-model="state.auto" :label="$t('search.auto-search')" single-line></v-switch>
<v-switch v-model="state.displayTotalTimes" :label="$t('search.display-total-times')" single-line></v-switch>
<v-btn block color="primary" @click="reset">
{{ $tc("general.reset") }}
</v-btn>
Expand All @@ -125,6 +126,7 @@
:title="$tc('search.results')"
:recipes="recipes"
:query="passedQuery"
:display-total-times="state.displayTotalTimes"
@replaceRecipes="replaceRecipes"
@appendRecipes="appendRecipes"
/>
Expand Down Expand Up @@ -157,6 +159,7 @@ export default defineComponent({
const { isOwnGroup } = useLoggedInState();
const state = ref({
auto: true,
displayTotalTimes: true,
search: "",
orderBy: "created_at",
orderDirection: "desc" as "asc" | "desc",
Expand Down Expand Up @@ -230,6 +233,7 @@ export default defineComponent({
// Only add the query param if it's or not default
...{
auto: state.value.auto ? undefined : "false",
displayTotalTimes: state.value.displayTotalTimes ? undefined : "false",
search: state.value.search === "" ? undefined : state.value.search,
orderBy: state.value.orderBy === "createdAt" ? undefined : state.value.orderBy,
orderDirection: state.value.orderDirection === "desc" ? undefined : state.value.orderDirection,
Expand Down Expand Up @@ -336,6 +340,10 @@ export default defineComponent({
state.value.auto = query.auto === "true";
}
if (query.auto) {
state.value.displayTotalTimes = query.displayTotalTimes === "true";
}
if (query.search) {
state.value.search = query.search as string;
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/lang/messages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@
"tag-filter": "Tag Filter",
"search-hint": "Press '/'",
"advanced": "Advanced",
"auto-search": "Auto Search"
"auto-search": "Auto Search",
"display-total-times": "Display Total Times"
},
"settings": {
"add-a-new-theme": "Add a New Theme",
Expand Down

0 comments on commit 364ffeb

Please sign in to comment.