refactor: add onMastoInit
parent
6092b27da6
commit
6729666170
|
@ -1,6 +1,4 @@
|
|||
<script setup lang="ts">
|
||||
import { warn } from 'vue'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
text?: string
|
||||
icon: string
|
||||
|
@ -31,7 +29,7 @@ useCommand({
|
|||
})
|
||||
|
||||
let activeClass = $ref('text-primary')
|
||||
watch(isMastoInitialised, async () => {
|
||||
onMastoInit(async () => {
|
||||
if (!props.userOnly) {
|
||||
// TODO: force NuxtLink to reevaluate, we now we are in this route though, so we should force it to active
|
||||
// we don't have currentServer defined until later
|
||||
|
|
|
@ -7,6 +7,12 @@ export const useMasto = () => useNuxtApp().$masto as ElkMasto
|
|||
|
||||
export const isMastoInitialised = computed(() => process.client && useMasto().loggedIn.value)
|
||||
|
||||
export const onMastoInit = (cb: () => unknown) => {
|
||||
watchOnce(isMastoInitialised, () => {
|
||||
cb()
|
||||
}, { immediate: isMastoInitialised.value })
|
||||
}
|
||||
|
||||
// @unocss-include
|
||||
export const STATUS_VISIBILITIES = [
|
||||
{
|
||||
|
|
|
@ -86,7 +86,7 @@ export function usePaginator<T>(
|
|||
}, 1000)
|
||||
|
||||
if (!isMastoInitialised.value) {
|
||||
watchOnce(isMastoInitialised, () => {
|
||||
onMastoInit(() => {
|
||||
state.value = 'idle'
|
||||
loadNext()
|
||||
})
|
||||
|
|
|
@ -4,18 +4,10 @@ export default defineNuxtRouteMiddleware((to) => {
|
|||
if (to.path === '/signin/callback')
|
||||
return
|
||||
|
||||
if (!isMastoInitialised.value) {
|
||||
watchOnce(isMastoInitialised, () => {
|
||||
if (!currentUser.value)
|
||||
return navigateTo(`/${currentServer.value}/public`)
|
||||
if (to.path === '/')
|
||||
return navigateTo('/home')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!currentUser.value)
|
||||
return navigateTo(`/${currentServer.value}/public`)
|
||||
if (to.path === '/')
|
||||
return navigateTo('/home')
|
||||
onMastoInit(() => {
|
||||
if (!currentUser.value)
|
||||
return navigateTo(`/${currentServer.value}/public`)
|
||||
if (to.path === '/')
|
||||
return navigateTo('/home')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -45,10 +45,7 @@ const { form, reset, submitter, dirtyFields, isError } = useForm({
|
|||
},
|
||||
})
|
||||
|
||||
watch(isMastoInitialised, async (val) => {
|
||||
if (!val)
|
||||
return
|
||||
|
||||
onMastoInit(async () => {
|
||||
// Keep the information to be edited up to date
|
||||
await pullMyAccountInfo()
|
||||
reset()
|
||||
|
|
Loading…
Reference in New Issue