fix: revert timelines loading optimization

This commit is contained in:
patak 2022-12-23 06:02:13 +01:00
parent 2e5270f453
commit ef4a240800
24 changed files with 87 additions and 146 deletions

View file

@ -5,15 +5,12 @@ provideGlobalCommands()
// We want to trigger rerendering the page when account changes // We want to trigger rerendering the page when account changes
const key = computed(() => `${currentUser.value?.server ?? currentServer.value}:${currentUser.value?.account.id || ''}`) const key = computed(() => `${currentUser.value?.server ?? currentServer.value}:${currentUser.value?.account.id || ''}`)
const { params } = useRoute()
</script> </script>
<template> <template>
<NuxtLoadingIndicator color="repeating-linear-gradient(to right,var(--c-primary) 0%,var(--c-primary-active) 100%)" /> <NuxtLoadingIndicator color="repeating-linear-gradient(to right,var(--c-primary) 0%,var(--c-primary-active) 100%)" />
<NuxtLayout :key="key"> <NuxtLayout :key="key">
<!-- TODO: rework the /[account] routes to remove conditional loading --> <NuxtPage v-if="isMastoInitialised" />
<NuxtPage v-if="!params.account || isMastoInitialised" />
</NuxtLayout> </NuxtLayout>
<PWAPrompt /> <PWAPrompt />
</template> </template>

View file

@ -5,7 +5,6 @@ const { options, command, replace, preventScrollTop = false } = $defineProps<{
options: { options: {
to: RouteLocationRaw to: RouteLocationRaw
display: string display: string
disabled?: boolean
name?: string name?: string
icon?: string icon?: string
}[] }[]
@ -29,25 +28,18 @@ useCommands(() => command
<template> <template>
<div flex w-full items-center lg:text-lg of-x-auto scrollbar-hide> <div flex w-full items-center lg:text-lg of-x-auto scrollbar-hide>
<template <NuxtLink
v-for="(option, index) in options" v-for="(option, index) in options"
:key="option?.name || index" :key="option?.name || index"
:to="option.to"
:replace="replace"
relative flex flex-auto cursor-pointer sm:px6 px2 rounded transition-all
tabindex="1"
hover:bg-active transition-100
exact-active-class="children:(font-bold !border-primary !op100)"
@click="!preventScrollTop && $scrollToTop()"
> >
<NuxtLink <span ws-nowrap mxa sm:px2 sm:py3 py2 text-center border-b-3 op50 hover:op70 border-transparent>{{ option.display }}</span>
v-if="!option.disabled" </NuxtLink>
:to="option.to"
:replace="replace"
relative flex flex-auto cursor-pointer sm:px6 px2 rounded transition-all
tabindex="1"
hover:bg-active transition-100
exact-active-class="children:(text-secondary !border-primary !op100)"
@click="!preventScrollTop && $scrollToTop()"
>
<span ws-nowrap mxa sm:px2 sm:py3 py2 text-center border-b-3 text-secondary-light hover:text-secondary border-transparent>{{ option.display }}</span>
</NuxtLink>
<div v-else flex flex-auto sm:px6 px2>
<span ws-nowrap mxa sm:px2 sm:py3 py2 text-center text-secondary-light op50>{{ option.display }}</span>
</div>
</template>
</div> </div>
</template> </template>

View file

@ -1,7 +0,0 @@
<script setup lang="ts">
const paginator = useMasto().blocks.iterate()
</script>
<template>
<AccountPaginator :paginator="paginator" />
</template>

View file

@ -1,7 +0,0 @@
<script setup lang="ts">
const paginator = useMasto().bookmarks.iterate()
</script>
<template>
<TimelinePaginator :paginator="paginator" />
</template>

View file

@ -1,7 +0,0 @@
<script setup lang="ts">
const paginator = useMasto().conversations.iterate()
</script>
<template>
<ConversationPaginator :paginator="paginator" />
</template>

View file

@ -1,21 +0,0 @@
<script setup lang="ts">
const masto = useMasto()
const paginator = masto.domainBlocks.iterate()
const unblock = async (domain: string) => {
await masto.domainBlocks.unblock(domain)
}
</script>
<template>
<CommonPaginator :paginator="paginator">
<template #default="{ item }">
<CommonDropdownItem class="!cursor-auto">
{{ item }}
<template #actions>
<div i-ri:lock-unlock-line text-primary cursor-pointer @click="unblock(item)" />
</template>
</CommonDropdownItem>
</template>
</CommonPaginator>
</template>

View file

@ -1,7 +0,0 @@
<script setup lang="ts">
const paginator = useMasto().favourites.iterate()
</script>
<template>
<TimelinePaginator :paginator="paginator" />
</template>

View file

@ -1,12 +0,0 @@
<script setup lang="ts">
const paginator = useMasto().timelines.iterateHome()
const stream = await useMasto().stream.streamUser()
onBeforeUnmount(() => stream.disconnect())
</script>
<template>
<div>
<PublishWidget draft-key="home" border="b base" />
<TimelinePaginator v-bind="{ paginator, stream }" context="home" />
</div>
</template>

View file

@ -1,13 +0,0 @@
<script setup lang="ts">
// Default limit is 20 notifications, and servers are normally caped to 30
const paginator = useMasto().notifications.iterate({ limit: 30, types: ['mention'] })
const { clearNotifications } = useNotifications()
onActivated(clearNotifications)
const stream = await useMasto().stream.streamUser()
</script>
<template>
<NotificationPaginator v-bind="{ paginator, stream }" />
</template>

View file

@ -1,7 +0,0 @@
<script setup lang="ts">
const paginator = useMasto().mutes.iterate()
</script>
<template>
<AccountPaginator :paginator="paginator" />
</template>

View file

@ -1,13 +0,0 @@
<script setup lang="ts">
// Default limit is 20 notifications, and servers are normally caped to 30
const paginator = useMasto().notifications.iterate({ limit: 30 })
const { clearNotifications } = useNotifications()
onActivated(clearNotifications)
const stream = await useMasto().stream.streamUser()
</script>
<template>
<NotificationPaginator v-bind="{ paginator, stream }" />
</template>

View file

@ -1,7 +0,0 @@
<script setup lang="ts">
const paginator = useMasto().accounts.iterateStatuses(currentUser.value!.account.id, { pinned: true })
</script>
<template>
<TimelinePaginator :paginator="paginator" />
</template>

View file

@ -17,11 +17,15 @@ const tabs = $computed(() => [
display: t('tab.news'), display: t('tab.news'),
}, },
// This section can only be accessed after logging in // This section can only be accessed after logging in
{ ...invoke(() => currentUser.value
to: `/${currentServer.value}/explore/users`, ? [
display: t('tab.for_you'), {
disabled: !isMastoInitialised.value || !currentUser.value, to: `/${currentServer.value}/explore/users`,
}, display: t('tab.for_you'),
},
]
: [],
),
] as const) ] as const)
</script> </script>
@ -37,6 +41,6 @@ const tabs = $computed(() => [
<template #header> <template #header>
<CommonRouteTabs replace :options="tabs" /> <CommonRouteTabs replace :options="tabs" />
</template> </template>
<NuxtPage v-if="isMastoInitialised" /> <NuxtPage />
</MainContent> </MainContent>
</template> </template>

View file

@ -3,6 +3,8 @@ definePageMeta({
middleware: 'auth', middleware: 'auth',
}) })
const paginator = useMasto().blocks.iterate()
useHeadFixed({ useHeadFixed({
title: 'Blocked users', title: 'Blocked users',
}) })
@ -13,7 +15,6 @@ useHeadFixed({
<template #title> <template #title>
<span text-lg font-bold>{{ $t('account.blocked_users') }}</span> <span text-lg font-bold>{{ $t('account.blocked_users') }}</span>
</template> </template>
<AccountPaginator :paginator="paginator" />
<TimelineBlocks v-if="isMastoInitialised" />
</MainContent> </MainContent>
</template> </template>

View file

@ -3,6 +3,8 @@ definePageMeta({
middleware: 'auth', middleware: 'auth',
}) })
const paginator = useMasto().bookmarks.iterate()
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHeadFixed({
@ -19,6 +21,8 @@ useHeadFixed({
</NuxtLink> </NuxtLink>
</template> </template>
<TimelineBookmarks v-if="isMastoInitialised" /> <slot>
<TimelinePaginator :paginator="paginator" />
</slot>
</MainContent> </MainContent>
</template> </template>

View file

@ -3,6 +3,8 @@ definePageMeta({
middleware: 'auth', middleware: 'auth',
}) })
const paginator = useMasto().conversations.iterate()
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHeadFixed({
@ -19,6 +21,8 @@ useHeadFixed({
</NuxtLink> </NuxtLink>
</template> </template>
<TimelineConversations v-if="isMastoInitialised" /> <slot>
<ConversationPaginator :paginator="paginator" />
</slot>
</MainContent> </MainContent>
</template> </template>

View file

@ -1,13 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
import TimelineDomainBlocks from '~~/components/timeline/TimelineDomainBlocks.vue'
definePageMeta({ definePageMeta({
middleware: 'auth', middleware: 'auth',
}) })
const paginator = useMasto().domainBlocks.iterate()
useHeadFixed({ useHeadFixed({
title: 'Blocked domains', title: 'Blocked domains',
}) })
const unblock = async (domain: string) => {
await useMasto().domainBlocks.unblock(domain)
}
</script> </script>
<template> <template>
@ -16,6 +20,15 @@ useHeadFixed({
<span text-lg font-bold>{{ $t('account.blocked_domains') }}</span> <span text-lg font-bold>{{ $t('account.blocked_domains') }}</span>
</template> </template>
<TimelineDomainBlocks v-if="isMastoInitialised" /> <CommonPaginator :paginator="paginator">
<template #default="{ item }">
<CommonDropdownItem class="!cursor-auto">
{{ item }}
<template #actions>
<div i-ri:lock-unlock-line text-primary cursor-pointer @click="unblock(item)" />
</template>
</CommonDropdownItem>
</template>
</CommonPaginator>
</MainContent> </MainContent>
</template> </template>

View file

@ -3,6 +3,7 @@ definePageMeta({
middleware: 'auth', middleware: 'auth',
}) })
const paginator = useMasto().favourites.iterate()
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHeadFixed({
@ -18,7 +19,8 @@ useHeadFixed({
<span>{{ t('nav_side.favourites') }}</span> <span>{{ t('nav_side.favourites') }}</span>
</NuxtLink> </NuxtLink>
</template> </template>
<slot>
<TimelineFavourites v-if="isMastoInitialised" /> <TimelinePaginator :paginator="paginator" />
</slot>
</MainContent> </MainContent>
</template> </template>

View file

@ -11,6 +11,10 @@ if (useRoute().path === '/signin/callback') {
useRouter().push('/home') useRouter().push('/home')
} }
const paginator = useMasto().timelines.iterateHome()
const stream = await useMasto().stream.streamUser()
onBeforeUnmount(() => stream.disconnect())
const { t } = useI18n() const { t } = useI18n()
useHeadFixed({ useHeadFixed({
title: () => t('nav_side.home'), title: () => t('nav_side.home'),
@ -25,7 +29,9 @@ useHeadFixed({
<span>{{ $t('nav_side.home') }}</span> <span>{{ $t('nav_side.home') }}</span>
</NuxtLink> </NuxtLink>
</template> </template>
<slot>
<TimelineHome v-if="isMastoInitialised" /> <PublishWidget draft-key="home" border="b base" />
<TimelinePaginator v-bind="{ paginator, stream }" context="home" />
</slot>
</MainContent> </MainContent>
</template> </template>

View file

@ -2,6 +2,9 @@
definePageMeta({ definePageMeta({
middleware: 'auth', middleware: 'auth',
}) })
const paginator = useMasto().mutes.iterate()
useHeadFixed({ useHeadFixed({
title: 'Muted users', title: 'Muted users',
}) })
@ -12,7 +15,6 @@ useHeadFixed({
<template #title> <template #title>
<span text-lg font-bold>{{ $t('account.muted_users') }}</span> <span text-lg font-bold>{{ $t('account.muted_users') }}</span>
</template> </template>
<AccountPaginator :paginator="paginator" />
<TimelineMutes v-if="isMastoInitialised" />
</MainContent> </MainContent>
</template> </template>

View file

@ -53,7 +53,6 @@ onActivated(() => {
<template v-if="pwaEnabled"> <template v-if="pwaEnabled">
<NotificationPreferences :show="showSettings" /> <NotificationPreferences :show="showSettings" />
</template> </template>
<NuxtPage /> <NuxtPage />
</slot> </slot>
</MainContent> </MainContent>

View file

@ -1,10 +1,19 @@
<script setup lang="ts"> <script setup lang="ts">
const { t } = useI18n() const { t } = useI18n()
// Default limit is 20 notifications, and servers are normally caped to 30
const paginator = useMasto().notifications.iterate({ limit: 30 })
const { clearNotifications } = useNotifications()
onActivated(clearNotifications)
const stream = await useMasto().stream.streamUser()
useHeadFixed({ useHeadFixed({
title: () => `${t('tab.notifications_all')} | ${t('nav_side.notifications')}`, title: () => `${t('tab.notifications_all')} | ${t('nav_side.notifications')}`,
}) })
</script> </script>
<template> <template>
<TimelineNotifications v-if="isMastoInitialised" /> <NotificationPaginator v-bind="{ paginator, stream }" />
</template> </template>

View file

@ -1,10 +1,19 @@
<script setup lang="ts"> <script setup lang="ts">
const { t } = useI18n() const { t } = useI18n()
// Default limit is 20 notifications, and servers are normally caped to 30
const paginator = useMasto().notifications.iterate({ limit: 30, types: ['mention'] })
const { clearNotifications } = useNotifications()
onActivated(clearNotifications)
const stream = await useMasto().stream.streamUser()
useHeadFixed({ useHeadFixed({
title: () => `${t('tab.notifications_mention')} | ${t('nav_side.notifications')}`, title: () => `${t('tab.notifications_mention')} | ${t('nav_side.notifications')}`,
}) })
</script> </script>
<template> <template>
<TimelineNotifications v-if="isMastoInitialised" /> <NotificationPaginator v-bind="{ paginator, stream }" />
</template> </template>

View file

@ -18,6 +18,6 @@ useHeadFixed({
<span>{{ t('account.pinned') }}</span> <span>{{ t('account.pinned') }}</span>
</template> </template>
<TimelinePinned v-if="isMastoInitialised" /> <TimelinePaginator :paginator="paginator" />
</MainContent> </MainContent>
</template> </template>