Merge branch 'main' into command-palette

This commit is contained in:
Xylight committed 2024-07-19 19:59:33 -07:00
commit 132a887db7
3 files changed
+41 -28

No files matched your search

+27 -15
View File
@@ -13,7 +13,13 @@ import {
type MyUserInfo,
type Community,
} from 'lemmy-js-client'
import { derived, get, writable, type Readable, type Writable } from 'svelte/store'
import {
derived,
get,
writable,
type Readable,
type Writable,
} from 'svelte/store'
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
import { browser } from '$app/environment'
import { env } from '$env/dynamic/public'
@@ -57,7 +63,7 @@ interface ProfileData {
defaultInstance?: string
}
interface PersonData extends MyUserInfo { }
interface PersonData extends MyUserInfo {}
interface Notifications {
inbox: number
@@ -93,7 +99,7 @@ export let profileData = writable<ProfileData>(
let fetchUser = {
loading: false,
prevProfile: -1
prevProfile: -1,
}
export let profile: Readable<Profile> = derived(
@@ -106,7 +112,7 @@ export let profile: Readable<Profile> = derived(
set(profile)
if (profile?.jwt) {
if ((profile.id != fetchUser.prevProfile) && !fetchUser.loading) {
if (profile.id != fetchUser.prevProfile && !fetchUser.loading) {
site.set(undefined)
fetchUser.loading = true
@@ -125,6 +131,7 @@ export let profile: Readable<Profile> = derived(
profile.user = res?.user
profile.avatar = res?.user?.local_user_view.person.avatar
profile.username = res?.user?.local_user_view.person.name
fetchUser.loading = false
fetchUser.prevProfile = profile.id
@@ -146,7 +153,6 @@ export let profile: Readable<Profile> = derived(
fetchUser.loading = false
}
}
}
)
@@ -223,7 +229,7 @@ export async function setUser(jwt: string, inst: string, username?: string) {
})
if (!user?.user) {
toast({
content: 'Your instance\'s API did not return your user data.',
content: "Your instance's API did not return your user data.",
type: 'error',
})
}
@@ -232,14 +238,14 @@ export async function setUser(jwt: string, inst: string, username?: string) {
profileData.update((pd) => {
// too lazy to make a decent system
const id = Math.max(...pd.profiles.map(p => p.id)) + 1
const id = Math.max(...pd.profiles.map((p) => p.id)) + 1
const newProfile: Profile = {
id: id,
instance: inst,
jwt: jwt,
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 {
@@ -254,7 +260,9 @@ export async function setUser(jwt: string, inst: string, username?: string) {
async function userFromJwt(
jwt: string,
instance: string
): Promise<{ user: PersonData | undefined; site: GetSiteResponse } | undefined> {
): Promise<
{ user: PersonData | undefined; site: GetSiteResponse } | undefined
> {
const sitePromise = client({ instanceURL: instance, auth: jwt }).getSite()
let timer = setTimeout(
@@ -262,15 +270,19 @@ async function userFromJwt(
toast({
content: `Still loading your user data...`,
type: 'warning',
loading: true
loading: true,
}),
5000
)
const site = await sitePromise.then((r) => {
clearTimeout(timer)
return r
}).catch((e) => { toast({ content: `Failed to contact the instance. ${e}` }) })
const site = await sitePromise
.then((r) => {
clearTimeout(timer)
return r
})
.catch((e) => {
toast({ content: `Failed to contact the instance. ${e}` })
})
if (!site) return
@@ -319,7 +331,7 @@ instance.subscribe(async (i) => {
const s = await new LemmyHttp(`https://${i}`).getSite()
site.set(s)
} catch (e) { }
} catch (e) {}
})
export async function setUserID(id: number) {
@@ -37,21 +37,22 @@
export let posts: PostView[]
export let community: boolean = false
export let lastSeen: number | undefined = undefined
export let feedId: PostFeedID
let combinedPosts = combineCrossposts(posts)
$: combinedPosts = combineCrossposts(posts)
let virtualItemEls: HTMLElement[] = []
let virtualListEl: HTMLElement | undefined = undefined
$: virtualizer = createWindowVirtualizer({
count: combinedPosts.length,
estimateSize: () => 0,
scrollMargin: virtualListEl?.offsetTop ?? 0,
const virtualizer = createWindowVirtualizer({
count: posts.length,
estimateSize: () => 150,
})
$: if (posts.length)
$virtualizer.setOptions({
count: posts.length,
scrollMargin: virtualListEl?.offsetTop,
})
$: items = $virtualizer.getVirtualItems()
$: {
if (virtualItemEls.length)
@@ -59,12 +60,12 @@
}
afterNavigate(() => {
console.log($postFeeds[feedId].lastSeen)
$virtualizer.scrollToIndex($postFeeds[feedId].lastSeen ?? 0)
})
export let feedData: PostFeed['data']
const limit = 20
let error: any = undefined
let loading = false
let hasMore = true
@@ -220,15 +221,15 @@
data-index={row.index}
class="relative post-container"
>
{#if combinedPosts[row.index]}
{#if posts[row.index]}
<Post
hideCommunity={community}
view={(combinedPosts[row.index]?.post.featured_community ||
combinedPosts[row.index]?.post.featured_local) &&
view={(posts[row.index]?.post.featured_community ||
posts[row.index]?.post.featured_local) &&
$userSettings.posts.compactFeatured
? 'compact'
: $userSettings.view}
post={combinedPosts?.[row.index]}
post={posts?.[row.index]}
class="transition-all duration-250"
on:hide={() => {
posts = posts.toSpliced(row.index, 1)