fix: posts not reloading when changing instance
This commit is contained in:
1 parent
c8efc4c44b
commit
6a4a60ec7d
2 files changed
+6
-9
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" context="module">
|
||||
interface CachedPosts {
|
||||
export interface CachedPosts {
|
||||
data: GetPostsResponse
|
||||
params: URLSearchParams
|
||||
lastSeen: number
|
||||
@@ -9,14 +9,11 @@
|
||||
export const _posts = writable<CachedPosts>(undefined)
|
||||
|
||||
export const shouldReload = (
|
||||
cache: CachedPosts,
|
||||
cache: CachedPosts | undefined,
|
||||
params: string,
|
||||
instance: string
|
||||
): boolean =>
|
||||
!(
|
||||
cache &&
|
||||
(params == cache.params.toString() || cache.instance != instance)
|
||||
)
|
||||
cache?.instance != instance || cache?.params.toString() != params
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
@@ -112,7 +109,7 @@
|
||||
const observer = new IntersectionObserver(callback, {
|
||||
root: null,
|
||||
rootMargin: '0px',
|
||||
threshold: 0.5,
|
||||
threshold: 0.25,
|
||||
})
|
||||
|
||||
const elements = document.querySelectorAll('.post-container')
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { userSettings } from '$lib/settings.js'
|
||||
import type { GetPostsResponse, ListingType, SortType } from 'lemmy-js-client'
|
||||
import { get, writable } from 'svelte/store'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import { _posts, shouldReload } from './+page.svelte'
|
||||
import { _posts, shouldReload, type CachedPosts } from './+page.svelte'
|
||||
import { browser } from '$app/environment'
|
||||
import { instance } from '$lib/instance'
|
||||
|
||||
@@ -19,7 +19,7 @@ export async function load({ url, fetch }) {
|
||||
const listingType: ListingType =
|
||||
(url.searchParams.get('type') as ListingType) || settings.defaultSort.feed
|
||||
|
||||
const cached = get(_posts)
|
||||
const cached: CachedPosts | undefined = get(_posts)
|
||||
|
||||
const posts = shouldReload(cached, url.searchParams.toString(), get(instance))
|
||||
? await getClient(undefined, fetch).getPosts({
|
||||
|
||||
Reference in new issue
Block a user