Skip to content

Commit

Permalink
testing a different way to handle toasting
Browse files Browse the repository at this point in the history
  • Loading branch information
RGBKnights committed Jan 8, 2025
1 parent 6356991 commit 3fde762
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 36 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"pinia": "^2.3.0",
"vue": "^3.4.38",
"vue-toast-notification": "^3.1.3",
"vue3-markdown-it": "^1.0.10",
"vue3-toastify": "^0.2.8"
},
Expand Down
27 changes: 25 additions & 2 deletions src/components/ActionSection.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<script setup lang="ts">
import { toast } from "vue3-toastify";
import "vue3-toastify/dist/index.css";
import ProgressBar from '@/components/ProgressBar.vue';
import { useIterateStore } from '@/stores/iterate'
import { ref } from 'vue';
Expand All @@ -8,12 +11,32 @@ const isLocked = ref(false)
const start = () => {
isLocked.value = true
iterate.start()
setTimeout(() => {
isLocked.value = false
}, 1000)
iterate.start().catch(error => {
let message = '';
switch (error.status) {
case 401:
message = 'Unauthorized: Access denied.';
break;
case 429:
message = 'Timeout: Try again in 1 hour.';
break;
case 500:
message = 'Error: We messed up.';
break;
default:
message = 'Error: Something Unexpected.';
break;
}
console.error('Error:', message)
toast(message, {
"theme": "auto",
"type": "error"
})
});
}
</script>

<template>
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import './style.css'
//import "vue3-toastify/dist/index.css";

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'

import './style.css'

const pinia = createPinia()
const app = createApp(App)

Expand Down
34 changes: 3 additions & 31 deletions src/stores/iterate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
//import { toast, ToastOptions } from "vue3-toastify";
import { defineStore } from 'pinia'

type State = 'Pending' | 'Running' | 'Completed' | 'Failed' | 'Terminated'

const URL_BASE = 'https://03600f7f7081.ngrok.app' //import.meta.env.VITE_API_URL
const URL_BASE = import.meta.env.VITE_API_URL
const API_CODE = import.meta.env.VITE_API_CODE

// const TOAST_ERROR_CONFIG = {
// "theme": "auto",
// "type": "error",
// "transition": "slide"
// } as ToastOptions;

export const useIterateStore = defineStore('iterate', {
state: () => {
return {
Expand Down Expand Up @@ -101,7 +94,7 @@ export const useIterateStore = defineStore('iterate', {
});
},
start() {
fetch(`${URL_BASE}/api/Iterator_Start`, {
return fetch(`${URL_BASE}/api/Iterator_Start`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
Expand All @@ -121,31 +114,10 @@ export const useIterateStore = defineStore('iterate', {
this.id = Id
this.interval = setInterval(() => this.next(), 1000)
this.next()
})
.catch(error => {
this.id = ''

let message = '';
switch (error.status) {
case 401:
message = 'Unauthorized: Access denied.';
break;
case 429:
message = 'Timeout: Try again in 1 hour.';
break;
case 500:
message = 'Error: We messed up.';
break;
default:
message = 'Error: Something Unexpected.';
break;
}
console.error('Error:', message)
//toast(message, TOAST_ERROR_CONFIG)
});
},
stop() {
fetch(`${URL_BASE}/runtime/webhooks/durabletask/instances/${this.id}/terminate?reason=Canceled&code=${API_CODE}`, {
return fetch(`${URL_BASE}/runtime/webhooks/durabletask/instances/${this.id}/terminate?reason=Canceled&code=${API_CODE}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
})
Expand Down

0 comments on commit 3fde762

Please sign in to comment.