Merge branch 'main' into command-palette
This commit is contained in:
commit
132a887db7
3 files changed
+37
-24
No files matched your search
+23
-11
@@ -13,7 +13,13 @@ import {
|
|||||||
type MyUserInfo,
|
type MyUserInfo,
|
||||||
type Community,
|
type Community,
|
||||||
} from 'lemmy-js-client'
|
} 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 { 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'
|
||||||
@@ -93,7 +99,7 @@ export let profileData = writable<ProfileData>(
|
|||||||
|
|
||||||
let fetchUser = {
|
let fetchUser = {
|
||||||
loading: false,
|
loading: false,
|
||||||
prevProfile: -1
|
prevProfile: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
export let profile: Readable<Profile> = derived(
|
export let profile: Readable<Profile> = derived(
|
||||||
@@ -106,7 +112,7 @@ export let profile: Readable<Profile> = derived(
|
|||||||
set(profile)
|
set(profile)
|
||||||
|
|
||||||
if (profile?.jwt) {
|
if (profile?.jwt) {
|
||||||
if ((profile.id != fetchUser.prevProfile) && !fetchUser.loading) {
|
if (profile.id != fetchUser.prevProfile && !fetchUser.loading) {
|
||||||
site.set(undefined)
|
site.set(undefined)
|
||||||
|
|
||||||
fetchUser.loading = true
|
fetchUser.loading = true
|
||||||
@@ -125,6 +131,7 @@ export let profile: Readable<Profile> = derived(
|
|||||||
|
|
||||||
profile.user = res?.user
|
profile.user = res?.user
|
||||||
profile.avatar = res?.user?.local_user_view.person.avatar
|
profile.avatar = res?.user?.local_user_view.person.avatar
|
||||||
|
profile.username = res?.user?.local_user_view.person.name
|
||||||
|
|
||||||
fetchUser.loading = false
|
fetchUser.loading = false
|
||||||
fetchUser.prevProfile = profile.id
|
fetchUser.prevProfile = profile.id
|
||||||
@@ -146,7 +153,6 @@ export let profile: Readable<Profile> = derived(
|
|||||||
fetchUser.loading = false
|
fetchUser.loading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -223,7 +229,7 @@ export async function setUser(jwt: string, inst: string, username?: string) {
|
|||||||
})
|
})
|
||||||
if (!user?.user) {
|
if (!user?.user) {
|
||||||
toast({
|
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',
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -232,14 +238,14 @@ export async function setUser(jwt: string, inst: string, username?: string) {
|
|||||||
|
|
||||||
profileData.update((pd) => {
|
profileData.update((pd) => {
|
||||||
// too lazy to make a decent system
|
// 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 = {
|
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 {
|
||||||
@@ -254,7 +260,9 @@ export async function setUser(jwt: string, inst: string, username?: string) {
|
|||||||
async function userFromJwt(
|
async function userFromJwt(
|
||||||
jwt: string,
|
jwt: string,
|
||||||
instance: 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()
|
const sitePromise = client({ instanceURL: instance, auth: jwt }).getSite()
|
||||||
|
|
||||||
let timer = setTimeout(
|
let timer = setTimeout(
|
||||||
@@ -262,15 +270,19 @@ async function userFromJwt(
|
|||||||
toast({
|
toast({
|
||||||
content: `Still loading your user data...`,
|
content: `Still loading your user data...`,
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
loading: true
|
loading: true,
|
||||||
}),
|
}),
|
||||||
5000
|
5000
|
||||||
)
|
)
|
||||||
|
|
||||||
const site = await sitePromise.then((r) => {
|
const site = await sitePromise
|
||||||
|
.then((r) => {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
return r
|
return r
|
||||||
}).catch((e) => { toast({ content: `Failed to contact the instance. ${e}` }) })
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
toast({ content: `Failed to contact the instance. ${e}` })
|
||||||
|
})
|
||||||
|
|
||||||
if (!site) return
|
if (!site) return
|
||||||
|
|
||||||
|
|||||||
@@ -37,19 +37,20 @@
|
|||||||
|
|
||||||
export let posts: PostView[]
|
export let posts: PostView[]
|
||||||
export let community: boolean = false
|
export let community: boolean = false
|
||||||
export let lastSeen: number | undefined = undefined
|
|
||||||
export let feedId: PostFeedID
|
export let feedId: PostFeedID
|
||||||
|
|
||||||
let combinedPosts = combineCrossposts(posts)
|
|
||||||
$: combinedPosts = combineCrossposts(posts)
|
|
||||||
|
|
||||||
let virtualItemEls: HTMLElement[] = []
|
let virtualItemEls: HTMLElement[] = []
|
||||||
let virtualListEl: HTMLElement | undefined = undefined
|
let virtualListEl: HTMLElement | undefined = undefined
|
||||||
|
|
||||||
$: virtualizer = createWindowVirtualizer({
|
const virtualizer = createWindowVirtualizer({
|
||||||
count: combinedPosts.length,
|
count: posts.length,
|
||||||
estimateSize: () => 0,
|
estimateSize: () => 150,
|
||||||
scrollMargin: virtualListEl?.offsetTop ?? 0,
|
})
|
||||||
|
|
||||||
|
$: if (posts.length)
|
||||||
|
$virtualizer.setOptions({
|
||||||
|
count: posts.length,
|
||||||
|
scrollMargin: virtualListEl?.offsetTop,
|
||||||
})
|
})
|
||||||
|
|
||||||
$: items = $virtualizer.getVirtualItems()
|
$: items = $virtualizer.getVirtualItems()
|
||||||
@@ -59,12 +60,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
afterNavigate(() => {
|
afterNavigate(() => {
|
||||||
|
console.log($postFeeds[feedId].lastSeen)
|
||||||
$virtualizer.scrollToIndex($postFeeds[feedId].lastSeen ?? 0)
|
$virtualizer.scrollToIndex($postFeeds[feedId].lastSeen ?? 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
export let feedData: PostFeed['data']
|
export let feedData: PostFeed['data']
|
||||||
|
|
||||||
const limit = 20
|
|
||||||
let error: any = undefined
|
let error: any = undefined
|
||||||
let loading = false
|
let loading = false
|
||||||
let hasMore = true
|
let hasMore = true
|
||||||
@@ -220,15 +221,15 @@
|
|||||||
data-index={row.index}
|
data-index={row.index}
|
||||||
class="relative post-container"
|
class="relative post-container"
|
||||||
>
|
>
|
||||||
{#if combinedPosts[row.index]}
|
{#if posts[row.index]}
|
||||||
<Post
|
<Post
|
||||||
hideCommunity={community}
|
hideCommunity={community}
|
||||||
view={(combinedPosts[row.index]?.post.featured_community ||
|
view={(posts[row.index]?.post.featured_community ||
|
||||||
combinedPosts[row.index]?.post.featured_local) &&
|
posts[row.index]?.post.featured_local) &&
|
||||||
$userSettings.posts.compactFeatured
|
$userSettings.posts.compactFeatured
|
||||||
? 'compact'
|
? 'compact'
|
||||||
: $userSettings.view}
|
: $userSettings.view}
|
||||||
post={combinedPosts?.[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)
|
||||||
|
|||||||
Reference in new issue
Block a user