mirror of
https://git.shipoclu.com/moon/plspace.git
synced 2026-08-13 02:42:30 +00:00
more targeted refresh
This commit is contained in:
@@ -17,12 +17,14 @@
|
||||
import { displayNameOf, fallbackMood, formatCount, profilePath } from '$lib/util/profile'
|
||||
import { toPlainText } from '$lib/util/html'
|
||||
import { relativeTime, shortDate, stampDate } from '$lib/util/time'
|
||||
import { useTimelineRefresh } from '$lib/timeline-refresh'
|
||||
import Module from '$components/common/Module.svelte'
|
||||
import Avatar from '$components/common/Avatar.svelte'
|
||||
import RichText from '$components/common/RichText.svelte'
|
||||
import Composer from '$components/blog/Composer.svelte'
|
||||
|
||||
const { endpoints, session } = useAppServices()
|
||||
const timelineRefresh = useTimelineRefresh()
|
||||
|
||||
let friendStatus = $state<Status[]>([])
|
||||
let bulletins = $state<Status[]>([])
|
||||
@@ -38,6 +40,7 @@
|
||||
let friendStatusError = $state<string | null>(null)
|
||||
let bulletinError = $state<string | null>(null)
|
||||
let loadGeneration = 0
|
||||
let primaryRefreshGeneration = 0
|
||||
|
||||
const me = $derived(session.me)
|
||||
const domain = $derived(session.host ? instanceDomain(session.instance, session.host) : '')
|
||||
@@ -76,6 +79,13 @@
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
const host = session.host
|
||||
const signedIn = session.signedIn
|
||||
if (!timelineRefresh || !host) return
|
||||
return timelineRefresh.register(() => void refreshPrimaryTimeline(signedIn, host))
|
||||
})
|
||||
|
||||
async function load(signedIn: boolean, host = session.host, generation = ++loadGeneration): Promise<void> {
|
||||
loading = true
|
||||
error = null
|
||||
@@ -132,6 +142,46 @@
|
||||
}
|
||||
}
|
||||
|
||||
/** Refresh only the dashboard's visible primary timeline, not its sidebars. */
|
||||
async function refreshPrimaryTimeline(signedIn: boolean, host: string): Promise<void> {
|
||||
const generation = ++primaryRefreshGeneration
|
||||
|
||||
if (signedIn) {
|
||||
friendStatusError = null
|
||||
try {
|
||||
const page = await endpoints.fetchTimeline(session.api, 'home', { limit: 10 })
|
||||
if (
|
||||
generation === primaryRefreshGeneration &&
|
||||
session.host === host &&
|
||||
session.signedIn === signedIn
|
||||
) {
|
||||
friendStatus = page.items
|
||||
}
|
||||
} catch (cause) {
|
||||
if (generation === primaryRefreshGeneration && session.host === host) {
|
||||
friendStatusError = messageOf(cause)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
bulletinError = null
|
||||
try {
|
||||
const page = await endpoints.fetchTimeline(session.api, 'local', { limit: 10 })
|
||||
if (
|
||||
generation === primaryRefreshGeneration &&
|
||||
session.host === host &&
|
||||
session.signedIn === signedIn
|
||||
) {
|
||||
bulletins = page.items
|
||||
}
|
||||
} catch (cause) {
|
||||
if (generation === primaryRefreshGeneration && session.host === host) {
|
||||
bulletinError = messageOf(cause)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function moodFor(status: Status): string {
|
||||
return fallbackMood(status.account.id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user