fix: decrease site fetches

This commit is contained in:
Xyphyn committed 2023-09-15 14:19:04 -07:00
1 parent b7038b1832
commit da6f4bab6a
7 files changed
+30 -29

No files matched your search

+16 -1
View File
@@ -5,7 +5,11 @@ import { getClient, site } from '$lib/lemmy.js'
import { getInbox, getInboxItemPublished } from '$lib/lemmy/inbox.js'
import { userSettings } from '$lib/settings.js'
import { moveItem } from '$lib/util.js'
import type { GetSiteResponse, MyUserInfo } from 'lemmy-js-client'
import {
LemmyHttp,
type GetSiteResponse,
type MyUserInfo,
} from 'lemmy-js-client'
import { get, writable } from 'svelte/store'
const getDefaultProfile = (): Profile => ({
@@ -197,9 +201,20 @@ const serializeUser = (user: Profile): Profile => ({
user: undefined,
})
instance.subscribe(async (i) => {
try {
// fetching site is handled by auth.ts if logged in
if (get(profile)?.jwt) return
const s = await new LemmyHttp(`https://${i}`).getSite()
site.set(s)
} catch (e) {}
})
export async function setUserID(id: number) {
const pd = get(profileData)
if (id == -1) {
instance.set(DEFAULT_INSTANCE_URL)
resetProfile()
return
}
+1 -1
View File
@@ -66,7 +66,7 @@
Powered by <Link
href="https://github.com/Xyphyn/photon"
highlight={false}
class="font-bold flex items-center gap-0.5 hover:underline text-black dark:text-white"
class="!font-bold flex items-center gap-0.5 hover:underline text-black dark:text-white"
>
<Logo width={12} /> Photon
</Link>
-6
View File
@@ -39,12 +39,6 @@ export const getInstance = () => get(instance)
export const site = writable<GetSiteResponse | undefined>(undefined)
if (LINKED_INSTANCE_URL) {
getClient(LINKED_INSTANCE_URL)
.getSite({})
.then((s) => site.set(s))
}
export async function validateInstance(instance: string): Promise<boolean> {
if (instance == '') return false