parsley/app/javascript/components/TheRecipe.vue

70 lines
2.2 KiB
Vue
Raw Normal View History

2018-04-01 21:43:23 -05:00
<template>
<div>
<div v-if="recipe === null">
Loading...
</div>
<div v-else>
2018-04-14 15:04:08 -05:00
<h1 class="title">{{ recipe.name }}</h1>
<div class="subtitle tags">
<span v-for="tag in recipe.tags" :key="tag" class="tag is-medium">{{tag}}</span>
</div>
2018-04-17 09:59:38 -05:00
<div class="tags">
<span v-if="isScaled" class="tag is-large">{{recipe.converted_scale}} X</span>
<span v-if="recipe.converted_system !== null" class="tag is-large">{{recipe.converted_system}}</span>
<span v-if="recipe.converted_unit !== null" class="tag is-large">{{recipe.converted_unit}}</span>
</div>
2018-04-14 15:04:08 -05:00
<hr>
2018-04-01 21:43:23 -05:00
<recipe-show :recipe="recipe"></recipe-show>
</div>
2024-10-02 16:20:07 -05:00
<router-link v-if="appConfig.isLoggedIn" class="button" :to="{name: 'edit_recipe', params: { id: recipeId }}">Edit</router-link>
2018-04-01 22:32:13 -05:00
<router-link class="button" to="/">Back</router-link>
2018-04-01 21:43:23 -05:00
</div>
</template>
2024-10-02 14:34:50 -05:00
<script setup>
2018-04-01 21:43:23 -05:00
2024-10-02 14:34:50 -05:00
import { computed, ref, watch } from "vue";
import { useRoute } from "vue-router";
2018-04-01 21:43:23 -05:00
import RecipeShow from "./RecipeShow";
import api from "../lib/Api";
2024-10-02 14:34:50 -05:00
import { useLoadResource } from "../lib/useLoadResource";
2024-10-02 16:20:07 -05:00
import { useAppConfigStore } from "../stores/appConfig";
2018-04-01 21:43:23 -05:00
2024-10-02 16:20:07 -05:00
const appConfig = useAppConfigStore();
2024-10-02 14:34:50 -05:00
const route = useRoute();
const { loadResource } = useLoadResource();
const recipe = ref(null);
2018-04-17 09:59:38 -05:00
2024-10-02 14:34:50 -05:00
const recipeId = computed(() => route.params.id);
const scale = computed(() => route.query.scale || null);
const system = computed(() => route.query.system || null);
const unit = computed(() => route.query.unit || null);
const isScaled = computed(() => recipe.value?.converted_scale?.length !== undefined && recipe.value.converted_scale.length > 0 && recipe.value.converted_scale !== "1");
2018-04-17 09:59:38 -05:00
2024-10-02 14:34:50 -05:00
watch(
() => route.query,
() => refreshData(),
{ immediate: true }
);
2022-02-02 21:12:27 -06:00
2024-10-02 14:34:50 -05:00
watch(
() => recipe.value?.name,
(newRecipe) => {
2022-02-02 21:12:27 -06:00
if (newRecipe) {
document.title = `${newRecipe.name}`;
}
2018-04-17 09:59:38 -05:00
}
2024-10-02 14:34:50 -05:00
)
2018-04-01 21:43:23 -05:00
2024-10-02 14:34:50 -05:00
function refreshData() {
loadResource(
api.getRecipe(recipeId.value, scale.value, system.value, unit.value, data => recipe.value = data)
);
2018-04-01 21:43:23 -05:00
}
</script>
<style lang="scss" scoped>
2022-02-02 21:12:27 -06:00
</style>