improved start page

This commit is contained in:
vabene1111
2024-03-16 22:51:15 +01:00
committed by smilerz
parent bdd9ff796a
commit 728bb76a43
2 changed files with 55 additions and 38 deletions

View File

@@ -3,54 +3,72 @@
<v-col> <v-col>
<h2>{{ title }}</h2> <h2>{{ title }}</h2>
</v-col> </v-col>
</v-row>
<v-row v-if="recipeWindows.length > 0">
<v-col> <v-col>
<v-btn density="default" variant="outlined" size="x-small" icon="fas fa-chevron-left" @click="scrollList('left', scroll_id)"></v-btn> <v-window show-arrows>
<v-btn density="default" variant="outlined" size="x-small" icon="fas fa-chevron-right" @click="scrollList('right', scroll_id)"></v-btn> <v-window-item v-for="w in recipeWindows">
<v-row>
<v-col v-for="r in w" :key="r.id">
<recipe-card :recipe="r" :show_description="true" :show_keywords="true" style="height: 20vh"></recipe-card>
</v-col>
</v-row>
</v-window-item>
</v-window>
</v-col> </v-col>
</v-row> </v-row>
<v-row>
<v-col>
<v-infinite-scroll direction="horizontal" mode="manual" :id="scroll_id">
<div v-for="r in recipes" class="mr-2">
<recipe-card :recipe="r" :show_description="false" :show_keywords="false" style="width: 45vw; height: 30vh"></recipe-card>
</div>
<template #load-more></template>
</v-infinite-scroll>
</v-col>
</v-row>
</template> </template>
<script lang="ts">
import {defineComponent, PropType} from 'vue'
import {Recipe, RecipeOverview} from "@/openapi";
import RecipeCard from "@/components/display/RecipeCard.vue";
export default defineComponent({ <script lang="ts" setup>
name: "HorizontalRecipeScroller", import {computed, PropType, toRefs} from 'vue'
components: {RecipeCard}, import RecipeCard from "@/components/display/RecipeCard.vue";
props: { import {useDisplay} from "vuetify";
import {Recipe, RecipeOverview} from "@/openapi";
const {mdAndUp} = useDisplay()
const props = defineProps(
{
title: {type: String, required: true}, title: {type: String, required: true},
recipes: {type: Array as PropType<Array<Recipe | RecipeOverview>>, required: true}, recipes: {
}, type: Array as PropType<Recipe[] | RecipeOverview[]>,
data() { required: true
return { },
scroll_id: Math.random(1000).toString() }
} )
}, const {title, recipes} = toRefs(props)
methods: {
scrollList(direction: string, target: string) { let numberOfCols = computed(() => {
const newRecipeScroll = document.getElementById(target) return mdAndUp.value ? 4 : 2
if (newRecipeScroll != null) { })
newRecipeScroll.scrollLeft = newRecipeScroll.scrollLeft + (200 * ((direction == 'left') ? -1 : 1))
type CustomWindow = {
id: number,
recipes: Array<Recipe | RecipeOverview>
}
let recipeWindows = computed(() => {
let windows = []
let current_window = []
for (const [i, r] of recipes?.value.entries()) {
current_window.push(r)
if (i % numberOfCols.value == numberOfCols.value - 1) {
if (current_window.length > 0) {
windows.push(current_window)
} }
current_window = []
} }
} }
if (current_window.length > 0) {
windows.push(current_window)
}
return windows
}) })
</script> </script>

View File

@@ -3,8 +3,7 @@
<!--TODO ideas for "start page": new recipes, meal plan, "last year/month/cooked long ago", high rated, random keyword --> <!--TODO ideas for "start page": new recipes, meal plan, "last year/month/cooked long ago", high rated, random keyword -->
<horizontal-recipe-scroller title="New Recipes" :recipes="new_recipes"></horizontal-recipe-scroller> <horizontal-recipe-scroller title="New Recipes" :recipes="new_recipes"></horizontal-recipe-scroller>
<horizontal-recipe-scroller title="Top Rated" :recipes="high_rated_recipes" ></horizontal-recipe-scroller> <horizontal-recipe-scroller title="Top Rated" :recipes="high_rated_recipes"></horizontal-recipe-scroller>
</v-container> </v-container>