enrecipes/app/components/settings/Reset.vue

111 lines
2.6 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, *">
2021-05-25 14:32:53 +00:00
<OptionsList title="rest" :items="items" :action="resetListItems" />
2021-04-12 18:09:48 +00:00
<GridLayout
2021-05-25 14:32:53 +00:00
:hidden="toast"
2021-04-12 18:09:48 +00:00
row="1"
class="appbar"
2021-05-22 08:56:31 +00:00
@loaded="onAppBarLoad"
2021-04-12 18:09:48 +00:00
columns="auto, *"
>
2021-04-01 10:55:35 +00:00
<Button class="ico" :text="icon.back" @tap="$navigateBack()" />
</GridLayout>
2021-05-25 14:32:53 +00:00
<Toast :toast="toast" :action="hideToast" />
2021-03-21 17:02:04 +00:00
</GridLayout>
</Page>
</template>
<script>
2021-05-22 08:56:31 +00:00
import { Observable, CoreTypes } from "@nativescript/core";
2021-03-21 17:02:04 +00:00
import { localize } from "@nativescript/localize";
import { mapState, mapActions } from "vuex";
2021-04-12 18:09:48 +00:00
import * as utils from "~/shared/utils";
2021-05-25 14:32:53 +00:00
import OptionsList from "../sub/OptionsList";
import Toast from "../sub/Toast";
2021-03-21 17:02:04 +00:00
export default {
2021-05-25 14:32:53 +00:00
components: { OptionsList, Toast },
2021-04-12 18:09:48 +00:00
data() {
return {
toast: null,
2021-05-22 08:56:31 +00:00
appbar: null,
2021-04-12 18:09:48 +00:00
};
},
2021-03-21 17:02:04 +00:00
computed: {
...mapState(["icon"]),
items() {
return [
2021-04-01 10:55:35 +00:00
{},
2021-03-21 17:02:04 +00:00
{
2021-05-25 14:32:53 +00:00
type: "list",
icon: "reset",
2021-03-21 17:02:04 +00:00
title: "restCuiL",
2021-05-25 14:32:53 +00:00
data: "cuisines",
2021-03-21 17:02:04 +00:00
},
{
2021-05-25 14:32:53 +00:00
type: "list",
icon: "reset",
2021-03-21 17:02:04 +00:00
title: "restCatL",
2021-05-25 14:32:53 +00:00
data: "categories",
2021-03-21 17:02:04 +00:00
},
{
2021-05-25 14:32:53 +00:00
type: "list",
icon: "reset",
2021-03-21 17:02:04 +00:00
title: "restYUL",
2021-05-25 14:32:53 +00:00
data: "yieldUnits",
2021-03-21 17:02:04 +00:00
},
{
2021-05-25 14:32:53 +00:00
type: "list",
icon: "reset",
2021-03-21 17:02:04 +00:00
title: "restUL",
2021-05-25 14:32:53 +00:00
data: "units",
2021-03-21 17:02:04 +00:00
},
2021-04-01 10:55:35 +00:00
{},
{},
2021-03-21 17:02:04 +00:00
];
},
},
methods: {
...mapActions(["resetListItemsAction"]),
2021-05-25 14:32:53 +00:00
onPageLoad({ object }) {
object.bindingContext = new Observable();
2021-03-21 17:02:04 +00:00
},
2021-05-22 08:56:31 +00:00
onAppBarLoad({ object }) {
this.appbar = object;
},
2021-03-21 17:02:04 +00:00
// RESET
resetListItems(listName) {
this.resetListItemsAction(listName);
2021-05-22 08:56:31 +00:00
this.showToast();
},
showToast() {
2021-04-12 18:09:48 +00:00
this.toast = localize("restDone");
utils.timer(5, (val) => {
if (!val) this.toast = val;
});
2021-03-21 17:02:04 +00:00
},
2021-05-22 08:56:31 +00:00
hideToast({ object }) {
2021-05-25 14:32:53 +00:00
this.appbar.translateY = 64;
2021-05-22 08:56:31 +00:00
object
.animate({
opacity: 0,
translate: { x: 0, y: 64 },
duration: 250,
curve: CoreTypes.AnimationCurve.ease,
})
.then(() => {
this.showUndo = false;
2021-05-25 14:32:53 +00:00
this.toast = null;
2021-05-22 08:56:31 +00:00
this.appbar.animate({
translate: { x: 0, y: 0 },
duration: 250,
curve: CoreTypes.AnimationCurve.ease,
});
object.opacity = 1;
object.translateY = 0;
});
},
2021-03-21 17:02:04 +00:00
},
};
</script>