enrecipes/app/components/Settings/Options.vue

120 lines
3.1 KiB
Vue
Raw Normal View History

2021-03-21 17:02:04 +00:00
<template>
2021-04-01 10:55:35 +00:00
<Page @loaded="onPageLoad" actionBarHidden="true">
<GridLayout rows="*, auto" columns="auto, *">
<ListView
colSpan="2"
rowSpan="2"
class="options-list"
for="item in items"
>
<v-template if="$index == 0">
<Label class="pageTitle" :text="'opts' | L" />
</v-template>
<v-template if="item.type == 'switch'">
<GridLayout columns="auto, *, auto" class="option">
<Label class="ico" :text="icon[item.icon]" />
2021-04-12 18:09:48 +00:00
<StackLayout col="1" verticalAlignment="center">
2021-04-01 10:55:35 +00:00
<Label :text="item.title | L" class="info" />
2021-04-12 18:09:48 +00:00
<Label
v-if="item.subTitle"
:text="item.subTitle | L"
class="sub"
/>
2021-04-01 10:55:35 +00:00
</StackLayout>
<Switch
2021-04-12 18:09:48 +00:00
:color="item.checked ? '#ff5200' : '#adb5bd'"
2021-04-01 10:55:35 +00:00
col="2"
2021-04-12 18:09:48 +00:00
:checked="item.checked"
2021-04-01 10:55:35 +00:00
@checkedChange="item.action"
/>
</GridLayout>
</v-template>
<v-template>
<StackLayout class="listSpace"> </StackLayout>
</v-template>
</ListView>
2021-04-12 18:09:48 +00:00
<GridLayout
v-show="!toast"
row="1"
class="appbar"
rows="*"
columns="auto, *"
>
<Button class="ico" :text="icon.back" @tap="$navigateBack()" />
</GridLayout>
<GridLayout
v-show="toast"
row="1"
colSpan="2"
class="appbar snackBar"
columns="*"
@tap="toast = null"
>
<FlexboxLayout minHeight="48" alignItems="center">
<Label class="title msg" :text="toast" />
</FlexboxLayout>
2021-03-21 17:02:04 +00:00
</GridLayout>
2021-04-01 10:55:35 +00:00
</GridLayout>
2021-03-21 17:02:04 +00:00
</Page>
</template>
<script>
2021-04-15 16:44:21 +00:00
import { Observable } from "@nativescript/core";
2021-03-21 17:02:04 +00:00
import { mapState, mapActions } from "vuex";
2021-04-15 16:44:21 +00:00
import { localize } from "@nativescript/localize";
2021-03-21 17:02:04 +00:00
import * as utils from "~/shared/utils";
export default {
2021-04-12 18:09:48 +00:00
data() {
return {
toast: null,
};
},
2021-03-21 17:02:04 +00:00
computed: {
2021-04-12 18:09:48 +00:00
...mapState(["icon", "shakeEnabled", "mondayFirst"]),
2021-04-01 10:55:35 +00:00
items() {
return [
{},
{
type: "switch",
icon: "shuf",
title: "sVw",
subTitle: "sVwInfo",
2021-04-12 18:09:48 +00:00
checked: this.shakeEnabled,
2021-04-01 10:55:35 +00:00
action: this.toggleShake,
2021-04-12 18:09:48 +00:00
},
{
type: "switch",
icon: "week",
title: "swm",
checked: this.mondayFirst,
action: this.toggleFirstDay,
2021-04-01 10:55:35 +00:00
},
{},
];
},
2021-03-21 17:02:04 +00:00
},
methods: {
2021-04-12 18:09:48 +00:00
...mapActions(["setShake", "setFirstDay"]),
2021-03-21 17:02:04 +00:00
onPageLoad(args) {
const page = args.object;
page.bindingContext = new Observable();
},
2021-04-12 18:09:48 +00:00
toggleFirstDay({ object }) {
this.setFirstDay(object.checked);
},
2021-03-21 17:02:04 +00:00
// SHAKE VIEW RANDOM RECIPE
2021-04-12 18:09:48 +00:00
toggleShake({ object }) {
let checked = object.checked;
2021-03-21 17:02:04 +00:00
if (checked && !utils.hasAccelerometer()) {
2021-04-15 16:44:21 +00:00
object.checked = false;
2021-04-12 18:09:48 +00:00
this.toast = localize("noAccSensor");
utils.timer(5, (val) => {
if (!val) this.toast = val;
});
} else this.setShake(checked);
2021-03-21 17:02:04 +00:00
},
},
};
</script>