enrecipes/app/components/settings/Reset.vue

111 lines
2.6 KiB
Vue
Raw Normal View History

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