fix: error when switching accounts on virtualfeed
This commit is contained in:
1 parent
b90703d9f8
commit
602af2996c
4 files changed
+23
-138
No files matched your search
+13
-20
@@ -6,7 +6,6 @@ import { toast } from 'mono-svelte'
|
|||||||
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
|
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
|
||||||
import { client, getClient } from '$lib/lemmy.js'
|
import { client, getClient } from '$lib/lemmy.js'
|
||||||
import { site } from './lemmy'
|
import { site } from './lemmy'
|
||||||
import { userSettings } from '$lib/settings.js'
|
|
||||||
import { instanceToURL, moveItem } from '$lib/util.js'
|
import { instanceToURL, moveItem } from '$lib/util.js'
|
||||||
import {
|
import {
|
||||||
LemmyHttp,
|
LemmyHttp,
|
||||||
@@ -18,7 +17,7 @@ import { derived, get, writable, type Writable } from 'svelte/store'
|
|||||||
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
import type { ResumableItem } from './lemmy/item'
|
import { t } from './translations'
|
||||||
|
|
||||||
const getDefaultProfile = (): Profile => ({
|
const getDefaultProfile = (): Profile => ({
|
||||||
id: -1,
|
id: -1,
|
||||||
@@ -169,7 +168,7 @@ profileData.subscribe(async (pd) => {
|
|||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
instance: DEFAULT_INSTANCE_URL,
|
instance: DEFAULT_INSTANCE_URL,
|
||||||
username: 'Guest',
|
username: t.get('account.guest') || 'Guest',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
profile: 1,
|
profile: 1,
|
||||||
@@ -218,25 +217,23 @@ export async function setUser(jwt: string, inst: string, username: string) {
|
|||||||
})
|
})
|
||||||
if (!user?.user) {
|
if (!user?.user) {
|
||||||
toast({
|
toast({
|
||||||
content: 'Failed to fetch your user. Is your instance down?',
|
content: 'Failed to fetch your user.',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.set(inst)
|
instance.set(inst)
|
||||||
|
|
||||||
profileData.update((pd) => {
|
profileData.update((pd) => {
|
||||||
// too lazy to make a decent system
|
// too lazy to make a decent system
|
||||||
const id = Math.floor(Math.random() * 100000)
|
const id = Math.max(...pd.profiles.map(p => p.id)) + 1
|
||||||
|
|
||||||
const newProfile: Profile = {
|
const newProfile: Profile = {
|
||||||
id: id,
|
id: id,
|
||||||
instance: inst,
|
instance: inst,
|
||||||
jwt: jwt,
|
jwt: jwt,
|
||||||
username: user.user.local_user_view.person.name,
|
username: user?.user?.local_user_view.person.name,
|
||||||
avatar: user.user.local_user_view.person.avatar,
|
avatar: user?.user?.local_user_view.person.avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -257,8 +254,9 @@ async function userFromJwt(
|
|||||||
let timer = setTimeout(
|
let timer = setTimeout(
|
||||||
() =>
|
() =>
|
||||||
toast({
|
toast({
|
||||||
content: `It's taking a while to fetch your user. Is your instance down?`,
|
content: `Still loading your user data...`,
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
|
loading: true
|
||||||
}),
|
}),
|
||||||
5000
|
5000
|
||||||
)
|
)
|
||||||
@@ -288,21 +286,16 @@ export function resetProfile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function deleteProfile(id: number) {
|
export function deleteProfile(id: number) {
|
||||||
const pd = get(profileData)
|
profileData.update((pd) => {
|
||||||
|
|
||||||
const index = pd.profiles.findIndex((p) => p.id == id)
|
const index = pd.profiles.findIndex((p) => p.id == id)
|
||||||
if (index <= -1) return
|
if (index <= -1) return pd
|
||||||
|
|
||||||
pd.profiles.splice(index, 1)
|
pd.profiles.splice(index, 1)
|
||||||
|
|
||||||
profileData.update((p) => ({
|
if (id == pd.profile) resetProfile()
|
||||||
...p,
|
|
||||||
profiles: pd.profiles,
|
|
||||||
}))
|
|
||||||
|
|
||||||
if (id == get(profile)?.id) {
|
return pd
|
||||||
resetProfile()
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeUser(user: Profile): Profile {
|
function serializeUser(user: Profile): Profile {
|
||||||
|
|||||||
@@ -13,68 +13,9 @@
|
|||||||
import { afterNavigate, beforeNavigate } from '$app/navigation'
|
import { afterNavigate, beforeNavigate } from '$app/navigation'
|
||||||
import { _posts } from '../../../../../routes/+page.svelte'
|
import { _posts } from '../../../../../routes/+page.svelte'
|
||||||
|
|
||||||
type PostViewWithCrossposts = PostView & {
|
|
||||||
withCrossposts: true
|
|
||||||
crossposts: PostView[]
|
|
||||||
}
|
|
||||||
type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
|
|
||||||
|
|
||||||
export let posts: PostView[]
|
export let posts: PostView[]
|
||||||
export let community: boolean = false
|
export let community: boolean = false
|
||||||
|
|
||||||
const addCrosspostProperty = (
|
|
||||||
post: PostView,
|
|
||||||
crossposts: PostView[]
|
|
||||||
): PostViewWithCrossposts => ({
|
|
||||||
...post,
|
|
||||||
crossposts: crossposts,
|
|
||||||
withCrossposts: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
const combineCrossposts = (
|
|
||||||
posts: PostView[]
|
|
||||||
): (PostViewWithCrossposts | PostViewWithoutCrossposts)[] => {
|
|
||||||
const urlMap = new Map<
|
|
||||||
string,
|
|
||||||
PostViewWithCrossposts | PostViewWithoutCrossposts
|
|
||||||
>()
|
|
||||||
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
|
|
||||||
const seenUrls = new Set<string>()
|
|
||||||
|
|
||||||
posts?.forEach((post) => {
|
|
||||||
if (
|
|
||||||
!post ||
|
|
||||||
($userSettings.hidePosts.deleted && post.post.deleted) ||
|
|
||||||
($userSettings.hidePosts.removed && post.post.removed)
|
|
||||||
)
|
|
||||||
return
|
|
||||||
if (!post?.post?.url) {
|
|
||||||
results.push(post)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let existing = urlMap.get(post.post.url)
|
|
||||||
if (existing) {
|
|
||||||
existing.withCrossposts = true
|
|
||||||
if (existing.withCrossposts) {
|
|
||||||
existing.crossposts = [...(existing.crossposts || []), post]
|
|
||||||
}
|
|
||||||
|
|
||||||
urlMap.set(post.post.url, existing)
|
|
||||||
} else {
|
|
||||||
urlMap.set(post.post.url, post)
|
|
||||||
results.push(post)
|
|
||||||
}
|
|
||||||
seenUrls.add(post.post.url)
|
|
||||||
})
|
|
||||||
|
|
||||||
return results
|
|
||||||
}
|
|
||||||
|
|
||||||
// $: combinedPosts = combineCrossposts(posts)
|
|
||||||
|
|
||||||
let viewPost: number = -1
|
|
||||||
|
|
||||||
const virtualizer = createWindowVirtualizer({
|
const virtualizer = createWindowVirtualizer({
|
||||||
count: posts.length,
|
count: posts.length,
|
||||||
estimateSize: () => 150,
|
estimateSize: () => 150,
|
||||||
@@ -125,16 +66,14 @@
|
|||||||
</Placeholder>
|
</Placeholder>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<!-- {#each combinedPosts as post, index} -->
|
|
||||||
<!-- {#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)} -->
|
|
||||||
<div
|
<div
|
||||||
style="position:relative; height: {browser
|
style="position:relative; height: {browser
|
||||||
? `${$virtualizer.getTotalSize()}px`
|
? `${$virtualizer.getTotalSize()}px`
|
||||||
: '100%'}; width: 100%;"
|
: '100%'}; width: 100%;"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items[0]
|
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items?.[0]
|
||||||
? items[0].start
|
? items?.[0]?.start
|
||||||
: 0}px);"
|
: 0}px);"
|
||||||
class="divide-y divide-slate-200 dark:divide-zinc-800"
|
class="divide-y divide-slate-200 dark:divide-zinc-800"
|
||||||
id="feed"
|
id="feed"
|
||||||
@@ -151,72 +90,25 @@
|
|||||||
data-index={row.index}
|
data-index={row.index}
|
||||||
class="relative post-container"
|
class="relative post-container"
|
||||||
>
|
>
|
||||||
|
{#if posts[row.index]}
|
||||||
<Post
|
<Post
|
||||||
hideCommunity={community}
|
hideCommunity={community}
|
||||||
view={(posts[row.index].post.featured_community ||
|
view={(posts[row.index]?.post.featured_community ||
|
||||||
posts[row.index].post.featured_local) &&
|
posts[row.index]?.post.featured_local) &&
|
||||||
$userSettings.posts.compactFeatured
|
$userSettings.posts.compactFeatured
|
||||||
? 'compact'
|
? 'compact'
|
||||||
: $userSettings.view}
|
: $userSettings.view}
|
||||||
post={posts[row.index]}
|
post={posts?.[row.index]}
|
||||||
class="transition-all duration-250"
|
class="transition-all duration-250"
|
||||||
on:hide={() => {
|
on:hide={() => {
|
||||||
posts = posts.toSpliced(row.index, 1)
|
posts = posts.toSpliced(row.index, 1)
|
||||||
}}
|
}}
|
||||||
>
|
></Post>
|
||||||
<svelte:fragment slot="badges">
|
|
||||||
<!-- {#if posts[index].withCrossposts}
|
|
||||||
<button
|
|
||||||
on:click={() => {
|
|
||||||
if (viewPost == posts[index].post.id) viewPost = -1
|
|
||||||
else viewPost = posts[index].post.id
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Badge
|
|
||||||
class="z-10 backdrop-blur-xl hover:brightness-110 cursor-pointer transition-all"
|
|
||||||
color="gray-subtle"
|
|
||||||
>
|
|
||||||
{#if viewPost == posts[index].post.id}
|
|
||||||
<Icon mini src={Minus} size="14" />
|
|
||||||
{:else}
|
|
||||||
<Icon mini src={Plus} size="14" />
|
|
||||||
{/if}
|
{/if}
|
||||||
{posts[index].crossposts.length} crosspost{posts[index]
|
|
||||||
.crossposts.length == 1
|
|
||||||
? ''
|
|
||||||
: 's'}
|
|
||||||
</Badge>
|
|
||||||
</button>{/if} -->
|
|
||||||
</svelte:fragment>
|
|
||||||
</Post>
|
|
||||||
<!-- {#if posts[index].withCrossposts && viewPost == posts[index].post.id}
|
|
||||||
<div
|
|
||||||
transition:slide|global={{
|
|
||||||
axis: 'y',
|
|
||||||
duration: 500,
|
|
||||||
easing: expoOut,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="text-sm flex flex-row gap-2 items-center"
|
|
||||||
class:my-4={$userSettings.view == 'card'}
|
|
||||||
>
|
|
||||||
Crossposts <hr class="w-full dark:border-zinc-800" />
|
|
||||||
{posts[index].crossposts.length}
|
|
||||||
</span>
|
|
||||||
{#each posts[index].crossposts as crosspost, index}
|
|
||||||
<div class="w-full transition-all mb-4">
|
|
||||||
<Post post={crosspost} view={$userSettings.view} />
|
|
||||||
</div>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{/if} -->
|
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- {/if} -->
|
|
||||||
<!-- {/each} -->
|
|
||||||
{/if}
|
{/if}
|
||||||
<slot />
|
<slot />
|
||||||
</ul>
|
</ul>
|
||||||
@@ -532,7 +532,8 @@
|
|||||||
"unblockUser": "Unblocked that user.",
|
"unblockUser": "Unblocked that user.",
|
||||||
"purgeUser": "Purged that user.",
|
"purgeUser": "Purged that user.",
|
||||||
"settingsImport": "Successfully imported settings",
|
"settingsImport": "Successfully imported settings",
|
||||||
"settingsImportWarning": "The imported settings don't seem valid. Are you sure you want to import this?"
|
"settingsImportWarning": "The imported settings don't seem valid. Are you sure you want to import this?",
|
||||||
|
"userLoading": "Still loading your user data..."
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"title": "Settings",
|
"title": "Settings",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
export const shouldReload = (
|
export const shouldReload = (
|
||||||
cache: CachedPosts | undefined,
|
cache: CachedPosts | undefined,
|
||||||
params: string,
|
params: string,
|
||||||
instance: string
|
instance: string,
|
||||||
): boolean =>
|
): boolean =>
|
||||||
cache?.instance != instance || cache?.params.toString() != params
|
cache?.instance != instance || cache?.params.toString() != params
|
||||||
</script>
|
</script>
|
||||||
@@ -57,7 +57,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
loading = true
|
loading = true
|
||||||
console.log(`loading more with cursor ${data.cursor.next}`)
|
|
||||||
const newPosts = await getClient()
|
const newPosts = await getClient()
|
||||||
.getPosts({
|
.getPosts({
|
||||||
limit: limit,
|
limit: limit,
|
||||||
|
|||||||
Reference in new issue
Block a user