fix: decrease site fetches
This commit is contained in:
1 parent
b7038b1832
commit
da6f4bab6a
7 files changed
+30
-29
No files matched your search
+16
-1
@@ -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
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
$: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : ''
|
||||
$: darkTheme = $theme && inDarkTheme()
|
||||
|
||||
$: console.log(darkTheme)
|
||||
|
||||
onMount(() => {
|
||||
if (browser) {
|
||||
window
|
||||
|
||||
+12
-15
@@ -10,6 +10,7 @@
|
||||
import { GlobeAmericas, Icon } from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import ViewSelect from '$lib/components/lemmy/ViewSelect.svelte'
|
||||
import { site } from '$lib/lemmy.js'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -23,13 +24,13 @@
|
||||
<Modal bind:open={sidebar}>
|
||||
<span slot="title">About</span>
|
||||
<div class="mx-auto">
|
||||
{#await data.streamed.site then site}
|
||||
{#if $site}
|
||||
<SiteCard
|
||||
site={site.site_view}
|
||||
taglines={site.taglines}
|
||||
admins={site.admins}
|
||||
site={$site.site_view}
|
||||
taglines={$site.taglines}
|
||||
admins={$site.admins}
|
||||
/>
|
||||
{/await}
|
||||
{/if}
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -75,22 +76,18 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden xl:block">
|
||||
{#await data.streamed.site}
|
||||
{#if !$site}
|
||||
<StickyCard>
|
||||
<div class="h-64 grid place-items-center">
|
||||
<Spinner width={32} />
|
||||
</div>
|
||||
</StickyCard>
|
||||
{:then site}
|
||||
{:else}
|
||||
<SiteCard
|
||||
site={site.site_view}
|
||||
taglines={site.taglines}
|
||||
admins={site.admins}
|
||||
site={$site.site_view}
|
||||
taglines={$site.taglines}
|
||||
admins={$site.admins}
|
||||
/>
|
||||
{:catch}
|
||||
<StickyCard>
|
||||
<h1 class="font-bold text-lg">Failed to load</h1>
|
||||
</StickyCard>
|
||||
{/await}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -27,9 +27,6 @@ export async function load({ url, fetch }) {
|
||||
type_: listingType,
|
||||
auth: get(profile)?.jwt,
|
||||
}),
|
||||
streamed: {
|
||||
site: getClient(undefined, fetch).getSite({}),
|
||||
},
|
||||
}
|
||||
} catch (err) {
|
||||
throw error(500, {
|
||||
|
||||
Reference in new issue
Block a user