feat: add guest instance
This commit is contained in:
1 parent
2da415b670
commit
6bb47c2b1d
3 files changed
+114
-7
No files matched your search
+9
-6
@@ -1,13 +1,8 @@
|
||||
import { env } from '$env/dynamic/public'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { getClient, instance } from '$lib/lemmy.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { DEFAULT_INSTANCE_URL, getClient, instance } from '$lib/lemmy.js'
|
||||
import type { MyUserInfo } from 'lemmy-js-client'
|
||||
import { get, writable } from 'svelte/store'
|
||||
|
||||
const LINKED_INSTANCE_URL = env.PUBLIC_INSTANCE_URL
|
||||
const DEFAULT_INSTANCE_URL = env.PUBLIC_INSTANCE_URL || 'lemmy.ml'
|
||||
|
||||
function getFromStorage<T>(key: string): T | undefined {
|
||||
if (typeof localStorage == 'undefined') return undefined
|
||||
const lc = localStorage.getItem(key)
|
||||
@@ -35,6 +30,7 @@ interface Profile {
|
||||
interface ProfileData {
|
||||
profiles: Profile[]
|
||||
profile: number
|
||||
defaultInstance?: string
|
||||
}
|
||||
|
||||
interface PersonData extends MyUserInfo {
|
||||
@@ -48,11 +44,18 @@ export const profileData = writable<ProfileData>(
|
||||
|
||||
profileData.subscribe((pd) => {
|
||||
setFromStorage('profileData', pd)
|
||||
|
||||
if (pd.profile == -1) {
|
||||
instance.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
|
||||
}
|
||||
})
|
||||
|
||||
export const profile = writable<Profile | undefined>(getProfile())
|
||||
|
||||
profile.subscribe(async (p) => {
|
||||
if (p?.id == -1) {
|
||||
instance.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
|
||||
}
|
||||
if (!p || !p.jwt) {
|
||||
profileData.update((pd) => ({ ...pd, profile: -1 }))
|
||||
return
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
{item.post.removed ? 'Restore' : 'Remove'}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if $profile.user && $profile.user?.local_user_view.person.id != item.creator.id}
|
||||
{#if $profile?.user && $profile.user?.local_user_view.person.id != item.creator.id}
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
User
|
||||
</span>
|
||||
|
||||
Reference in new issue
Block a user