enrecipes/app/components/settings/Options.vue

89 lines
2.1 KiB
Vue
Raw Normal View History

2021-05-25 14:32:53 +00:00
<template>
2021-06-15 11:04:42 +00:00
<Page @loaded="pgLoad" actionBarHidden="true">
<RGridLayout :rtl="RTL" rows="*, auto" columns="auto, *">
2021-05-25 14:32:53 +00:00
<OptionsList title="opts" :items="items" />
<GridLayout
2021-06-15 11:04:42 +00:00
:hidden="toast"
@loaded="abLoad"
2021-05-25 14:32:53 +00:00
row="1"
2021-06-15 11:04:42 +00:00
class="appbar rtl"
2021-05-25 14:32:53 +00:00
rows="*"
columns="auto, *"
>
<Button class="ico" :text="icon.back" @tap="$navigateBack()" />
</GridLayout>
2021-06-15 11:04:42 +00:00
<Toast :onload="tbLoad" :toast="toast" :action="hideBar" />
</RGridLayout>
2021-05-25 14:32:53 +00:00
</Page>
</template>
<script>
import { Observable } from "@nativescript/core";
import { mapState, mapActions } from "vuex";
import { localize } from "@nativescript/localize";
import OptionsList from "../sub/OptionsList";
import Toast from "../sub/Toast";
import * as utils from "~/shared/utils";
export default {
components: { OptionsList, Toast },
data() {
return {
2021-06-15 11:04:42 +00:00
appbar: null,
toastbar: null,
2021-05-25 14:32:53 +00:00
toast: null,
};
},
computed: {
2021-06-15 11:04:42 +00:00
...mapState(["icon", "shake", "RTL"]),
2021-05-25 14:32:53 +00:00
items() {
return [
{},
{
type: "switch",
icon: "shuf",
title: "sVw",
2021-06-15 11:04:42 +00:00
subTitle: localize("sVwInfo"),
checked: !!this.shake,
2021-05-25 14:32:53 +00:00
action: this.toggleShake,
},
{},
];
},
},
methods: {
...mapActions(["setShake"]),
2021-06-15 11:04:42 +00:00
pgLoad({ object }) {
2021-05-25 14:32:53 +00:00
object.bindingContext = new Observable();
},
2021-06-15 11:04:42 +00:00
abLoad({ object }) {
this.appbar = object;
},
tbLoad({ object }) {
this.toastbar = object;
},
2021-05-25 14:32:53 +00:00
// SHAKE VIEW RANDOM RECIPE
toggleShake() {
2021-06-15 11:04:42 +00:00
let checked = this.shake;
if (checked && !utils.hasAccelerometer())
this.showToast(localize("noAccSensor"));
else this.setShake(!checked | 0);
},
showToast(data) {
this.animateBar(this.appbar, 0).then(() => {
this.toast = data;
this.animateBar(this.toastbar, 1);
utils.timer(5, (val) => !val && this.hideBar());
});
},
hideBar() {
this.animateBar(this.toastbar, 0).then(() => {
this.toast = null;
this.animateBar(this.appbar, 1);
});
2021-05-25 14:32:53 +00:00
},
},
};
</script>