Skip to content

Commit 1d0ceca

Browse files
authored
Merge pull request #25 from connorabbas/develop
Improvements
2 parents 50749cf + 481cb54 commit 1d0ceca

File tree

14 files changed

+59
-34
lines changed

14 files changed

+59
-34
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"hollowtree.vue-snippets",
2121
"Vue.volar",
2222
"bradlc.vscode-tailwindcss",
23-
"shd101wyy.markdown-preview-enhanced"
23+
"shd101wyy.markdown-preview-enhanced",
24+
"formulahendry.auto-rename-tag"
2425
],
2526
"settings": {
2627
"terminal.integrated.shell.linux": "/bin/sh"

src/App.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<script setup>
2-
import { RouterView } from "vue-router";
2+
import { RouterView } from 'vue-router';
33
</script>
44

55
<template>
66
<!-- Use key to re-generate the page view component on each navigation :key="$route.path" -->
77
<!-- Alteratively, use a watch() on each component to re-render dynamic data as needed -->
88
<Toast position="top-center" />
9-
<Suspense>
10-
<RouterView />
11-
</Suspense>
9+
<RouterView v-slot="{ Component }">
10+
<Suspense timeout="0">
11+
<template #default>
12+
<component :is="Component" />
13+
</template>
14+
<template #fallback>
15+
<div class="h-screen flex items-center justify-center">
16+
<ProgressSpinner />
17+
</div>
18+
</template>
19+
</Suspense>
20+
</RouterView>
1221
</template>

src/composables/useAxiosForm.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ export function useAxiosForm(initialData = {}) {
2525
};
2626

2727
const makeRequest = async (method, url, options = {}) => {
28+
options = {
29+
showProgress: false,
30+
...options,
31+
};
2832
try {
2933
clearErrors();
3034
processing.value = true;
31-
progress.start();
35+
if (options.showProgress) {
36+
progress.start();
37+
}
3238

3339
if (options.onBefore) options.onBefore();
3440

@@ -48,9 +54,10 @@ export function useAxiosForm(initialData = {}) {
4854
} finally {
4955
if (onFinishCallback) onFinishCallback();
5056
if (options.onFinish) options.onFinish();
51-
5257
processing.value = false;
53-
progress.done();
58+
if (progress.isStarted()) {
59+
progress.done();
60+
}
5461
}
5562
};
5663

src/middleware/verified.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
export default async function verified({ to, from, authStore }) {
2+
if (to.name === 'verifyEmail') return;
3+
24
if (!authStore.user) {
35
await authStore.fetchUser();
46
}
5-
if (
6-
authStore.mustVerifyEmail &&
7-
new Boolean(authStore.user?.id) &&
8-
authStore.user.email_verified_at === null
9-
) {
10-
if (to.name !== 'verifyEmail') {
11-
return { name: 'verifyEmail' };
12-
}
7+
8+
if (authStore.mustVerifyEmail && new Boolean(authStore.user?.id) && authStore.user.email_verified_at === null) {
9+
return { name: 'verifyEmail' };
1310
}
1411
}

src/router/index.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,38 @@ const router = createRouter({
1414
{
1515
path: '/:pathMatch(.*)*', // 404 route not found
1616
name: 'NotFound',
17-
component: () => import('@/views/NotFound.vue'),
17+
component: () => import('@/views/error/NotFound.vue'),
1818
},
1919
],
2020
});
2121

22+
let progressTimeout = null;
2223
router.beforeEach(async (to, from) => {
23-
progress.start();
24+
progressTimeout = setTimeout(() => progress.start(), 250);
2425
const authStore = useAuthStore();
2526

2627
// Run middleware pipeline
27-
const context = { to, from, authStore };
28-
const routeMiddleware = to.meta.middleware || [];
29-
for (const middleware of routeMiddleware) {
30-
const result = await middleware(context);
31-
if (result) {
32-
return result; // Exit and redirect if middleware returns a route
28+
try {
29+
const context = { to, from, authStore };
30+
const routeMiddleware = to.meta.middleware || [];
31+
for (const middleware of routeMiddleware) {
32+
const result = await middleware(context);
33+
if (result) {
34+
return result; // Exit and redirect if middleware returns a route
35+
}
36+
}
37+
} finally {
38+
clearTimeout(progressTimeout);
39+
if (progress.isStarted()) {
40+
progress.done();
3341
}
3442
}
3543
});
3644

3745
router.afterEach(() => {
38-
progress.done();
46+
if (progress.isStarted()) {
47+
progress.done();
48+
}
3949
});
4050

4151
export default router;

src/stores/auth.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const useAuthStore = defineStore('auth', () => {
4545
const { post: submitLogoutForm } = useAxiosForm();
4646
function logout() {
4747
return submitLogoutForm('/logout', {
48+
showProgress: true,
4849
onSuccess: (response) => {
4950
user.value = null;
5051
router.push({ name: 'welcome' });

src/views/auth/ForgotPassword.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const submit = () => {
3030
};
3131
3232
const loading = computed(() => {
33-
return submittingRequest.value || authStore.fetchingCsrfToken.value;
33+
return submittingRequest.value || authStore.fetchingCsrfToken;
3434
});
3535
3636
onMounted(() => {

src/views/auth/Login.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const submit = () => {
4343
};
4444
4545
const loading = computed(() => {
46-
return loggingIn.value || authStore.fetchingCsrfToken.value;
46+
return loggingIn.value || authStore.fetchingCsrfToken;
4747
});
4848
4949
onMounted(() => {

src/views/auth/Register.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const submit = () => {
3333
};
3434
3535
const loading = computed(() => {
36-
return registering.value || authStore.fetchingCsrfToken.value;
36+
return registering.value || authStore.fetchingCsrfToken;
3737
});
3838
3939
onMounted(() => {
@@ -123,7 +123,7 @@ onMounted(() => {
123123
<div class="flex justify-end items-center pt-2">
124124
<RouterLink
125125
:to="{ name: 'login' }"
126-
class="mr-4 text-muted-color underline text-muted-color hover:text-color"
126+
class="mr-4 underline text-muted-color hover:text-color"
127127
>
128128
Already registered?
129129
</RouterLink>

src/views/auth/ResetPassword.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const submit = () => {
4545
};
4646
4747
const loading = computed(() => {
48-
return resetting.value || authStore.fetchingCsrfToken.value;
48+
return resetting.value || authStore.fetchingCsrfToken;
4949
});
5050
5151
onMounted(() => {

0 commit comments

Comments
 (0)