mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: add vue-toastification for alerting
This commit is contained in:
1 parent
2d0fffc8f4
commit
d0e2a4125d
7 files changed
+58
-22
No files matched your search
@@ -1,6 +1,7 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { RouterLink, useRouter } from 'vue-router'
|
||||
import { useToast } from 'vue-toastification'
|
||||
import api from '../utils/api'
|
||||
|
||||
const emit = defineEmits(['onSubmit', 'onChange'])
|
||||
@@ -24,6 +25,7 @@ const username = ref('')
|
||||
const email = ref('')
|
||||
const password = ref('')
|
||||
const errorMessage = ref('')
|
||||
const toast = useToast()
|
||||
|
||||
const availableMethods = ref({})
|
||||
onMounted(async () => {
|
||||
@@ -39,11 +41,10 @@ const hasSocialLogins = computed(() => {
|
||||
})
|
||||
|
||||
const success = () => {
|
||||
router.push({ name: 'game' })
|
||||
router.push({ name: 'game', params: { questId: 'helloworld' } })
|
||||
}
|
||||
|
||||
const error = (err) => {
|
||||
console.error(err)
|
||||
errorMessage.value = err
|
||||
}
|
||||
|
||||
@@ -62,8 +63,8 @@ const handleSubmit = () => {
|
||||
error,
|
||||
})
|
||||
} catch (err) {
|
||||
toast.error('Something went wrong.')
|
||||
console.error(err)
|
||||
errorMessage.value = 'Something went wrong'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
<script setup>
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useToast } from 'vue-toastification'
|
||||
import { logout } from '../utils/auth'
|
||||
import { bugReportUrl } from '../config'
|
||||
import sessionStore, { reset } from '../store/session'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const toast = useToast()
|
||||
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
await logout()
|
||||
reset()
|
||||
router.push({ name: 'login' })
|
||||
} catch (err) {
|
||||
toast.error('Failed to logout')
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
@@ -33,14 +37,12 @@ const handleLogout = async () => {
|
||||
class="text-text-tertiary h-full w-full"
|
||||
/>
|
||||
</button> -->
|
||||
<button>
|
||||
<p
|
||||
class="text-text-primary inline-block font-bold whitespace-nowrap"
|
||||
v-if="sessionStore.quest"
|
||||
>
|
||||
{{ sessionStore.quest.title }}
|
||||
</p>
|
||||
</button>
|
||||
<p
|
||||
class="text-text-primary inline-block font-bold whitespace-nowrap"
|
||||
v-if="sessionStore.quest"
|
||||
>
|
||||
{{ sessionStore.quest.title }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="h-full w-full flex gap-3 items-center justify-end">
|
||||
<!-- <button id="warning" class="flex items-center h-5 w-5">
|
||||
|
||||
@@ -3,6 +3,9 @@ import './style.css'
|
||||
/* import font awesome icon component */
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
|
||||
import './library'
|
||||
/* import Vue Toastification */
|
||||
import Toast, { POSITION } from 'vue-toastification'
|
||||
import 'vue-toastification/dist/index.css'
|
||||
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
@@ -13,4 +16,10 @@ app.component('font-awesome-icon', FontAwesomeIcon)
|
||||
|
||||
app.use(router)
|
||||
|
||||
const options = {
|
||||
position: POSITION.TOP_RIGHT,
|
||||
}
|
||||
|
||||
app.use(Toast, options)
|
||||
|
||||
app.mount('#app')
|
||||
+9
-1
@@ -8,7 +8,12 @@ import { isLoggedIn } from './utils/auth'
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/game',
|
||||
redirect: {
|
||||
name: 'game',
|
||||
params: {
|
||||
questId: 'helloworld',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
@@ -55,6 +60,9 @@ router.beforeEach(async (to, from, next) => {
|
||||
} else if (to.meta.requiresGuest && loggedIn) {
|
||||
next({
|
||||
name: 'game', // Or any default authenticated user route
|
||||
params: {
|
||||
questId: 'helloworld',
|
||||
},
|
||||
})
|
||||
} else {
|
||||
next() // Always call next() at the end
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { reactive } from 'vue'
|
||||
import { useToast } from 'vue-toastification'
|
||||
import { FileGraph } from '@linux-odyssey/file-graph'
|
||||
import api from '../utils/api'
|
||||
import Socket from '../utils/socket'
|
||||
import SocketTerminal from '../utils/terminal'
|
||||
|
||||
const toast = useToast()
|
||||
|
||||
function newSession() {
|
||||
const graph = new FileGraph({
|
||||
path: '/',
|
||||
@@ -50,15 +53,22 @@ export async function createSession() {
|
||||
await setSession(data)
|
||||
}
|
||||
|
||||
async function getActiveSession(questId) {
|
||||
const res = await api.post('/sessions/active', { questId })
|
||||
const session = res.data
|
||||
try {
|
||||
await setSession(session)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
await createSession().catch(console.error)
|
||||
}
|
||||
function getActiveSession(questId) {
|
||||
return api
|
||||
.post('/sessions/active', { questId })
|
||||
.then((res) => {
|
||||
const session = res.data
|
||||
return setSession(session)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
toast.warning('Failed to connect previous session. Creating a new one...')
|
||||
return createSession()
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
toast.error('Failed to create a new session. Please try again later.')
|
||||
})
|
||||
}
|
||||
|
||||
function updateGraph(event) {
|
||||
|
||||
Reference in new issue
Block a user