diff --git a/src/client/types/toast.ts b/src/client/types/toast.ts new file mode 100644 index 0000000..2f47846 --- /dev/null +++ b/src/client/types/toast.ts @@ -0,0 +1,62 @@ +import journey_wrapper from "./wrapper"; +import { focus_leg } from "../helper/nav"; + +interface toaster { + show: boolean, + title: String, + desc: String, + special: String, + acceptText: String, + cancelText: String, + func: () => void, +} + +const default_toaster = { + show: false, + title: ' ', + desc: ' ', + special: ' ', + acceptText: ' ', + cancelText: ' ', + func: () => { } +} + +class toast { + data: toaster = default_toaster; + + reset = function (): void { + this.data.show = false + this.data.title = ' ' + this.data.desc = ' ' + this.data.special = ' ' + this.data.acceptText = ' ' + this.data.cancelText = ' ' + this.data.func = () => { }; + } + constructor() { + this.reset() + } + + impexp = function (is_import: boolean, journey: journey_wrapper): void { + this.data.show = true; + this.data.title = is_import ? 'Import' : 'Export'; + this.data.desc = '' + this.data.special = JSON.stringify(journey.data).toEncoded(); + this.data.acceptText = is_import ? 'load' : '' + this.data.cancelText = 'cancel' + this.data.func = () => { journey.import_data(JSON.parse(this.data.special.toDecoded().toString())); this.reset(toast); } + } + + delete_leg = function (v: number, journey: journey_wrapper): void { + this.data.show = true; + this.data.title = `Delete Leg`; + this.data.desc = `Remove leg <${journey.leg_get(v).title || v}>` + this.data.special = ''; + this.data.acceptText = 'delete' + this.data.cancelText = 'cancel' + this.data.func = () => { journey.rm_leg(v); focus_leg(journey); this.reset(toast); } + } + +} + +export default toast; \ No newline at end of file