fix: fix guest instance not working

This commit is contained in:
Xyphyn committed 2023-08-03 10:40:12 -07:00
1 parent 7e7197a676
commit 4fb4d2b7b8
6 files changed
+78 -57

No files matched your search

+9 -15
View File
@@ -23,6 +23,7 @@ interface Profile {
jwt?: string jwt?: string
user?: PersonData user?: PersonData
username?: string username?: string
favorites?: number[]
} }
/** /**
@@ -43,13 +44,10 @@ export const profileData = writable<ProfileData>(
getFromStorage<ProfileData>('profileData') ?? { profiles: [], profile: -1 } getFromStorage<ProfileData>('profileData') ?? { profiles: [], profile: -1 }
) )
let initialInstance = get(profileData).defaultInstance
profileData.subscribe(async (pd) => { profileData.subscribe(async (pd) => {
setFromStorage('profileData', pd) setFromStorage('profileData', pd)
if (pd.profile == -1 && pd.defaultInstance != initialInstance) { if (pd.profile == -1) {
initialInstance = get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL
instance.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL) instance.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
} }
}) })
@@ -132,17 +130,11 @@ async function userFromJwt(
} }
} }
const userToPersonData = (user: MyUserInfo): PersonData => ({
...user,
unreads: 0,
reports: 0,
})
function getProfile() { function getProfile() {
const id = get(profileData).profile const id = get(profileData).profile
if (id == -1) { if (id == -1) {
return return getDefaultProfile()
} }
const pd = get(profileData) const pd = get(profileData)
@@ -150,10 +142,12 @@ function getProfile() {
return pd.profiles.find((p) => p.id == id) return pd.profiles.find((p) => p.id == id)
} }
const getDefaultProfile = () => ({ function getDefaultProfile() {
id: -1, return {
instance: get(instance), id: -1,
}) instance: get(profileData)?.defaultInstance ?? get(instance),
}
}
export function resetProfile() { export function resetProfile() {
profile.set(getDefaultProfile()) profile.set(getDefaultProfile())
@@ -10,6 +10,7 @@
viewBox="0 0 20 22" viewBox="0 0 20 22"
fill="none" fill="none"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="inline"
> >
<path <path
d="M10.516 1.17C10.3767 1.03791 10.192 0.964283 10 0.964283C9.80801 0.964283 9.62333 1.03791 9.484 1.17C7.36127 3.18588 4.53412 4.29133 1.607 4.25C1.44753 4.24793 1.29156 4.29674 1.16172 4.38935C1.03189 4.48196 0.934957 4.61355 0.885 4.765C0.462973 6.05116 0.248618 7.39637 0.25 8.75C0.25 14.692 4.314 19.683 9.813 21.098C9.93566 21.1296 10.0643 21.1296 10.187 21.098C15.686 19.683 19.75 14.692 19.75 8.75C19.75 7.36 19.527 6.02 19.115 4.765C19.0652 4.61336 18.9684 4.48156 18.8385 4.38875C18.7087 4.29595 18.5526 4.247 18.393 4.249L18.25 4.25C15.254 4.25 12.533 3.08 10.516 1.17Z" d="M10.516 1.17C10.3767 1.03791 10.192 0.964283 10 0.964283C9.80801 0.964283 9.62333 1.03791 9.484 1.17C7.36127 3.18588 4.53412 4.29133 1.607 4.25C1.44753 4.24793 1.29156 4.29674 1.16172 4.38935C1.03189 4.48196 0.934957 4.61355 0.885 4.765C0.462973 6.05116 0.248618 7.39637 0.25 8.75C0.25 14.692 4.314 19.683 9.813 21.098C9.93566 21.1296 10.0643 21.1296 10.187 21.098C15.686 19.683 19.75 14.692 19.75 8.75C19.75 7.36 19.527 6.02 19.115 4.765C19.0652 4.61336 18.9684 4.48156 18.8385 4.38875C18.7087 4.29595 18.5526 4.247 18.393 4.249L18.25 4.25C15.254 4.25 12.533 3.08 10.516 1.17Z"
@@ -23,6 +24,7 @@
viewBox="0 0 20 22" viewBox="0 0 20 22"
fill="none" fill="none"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="inline"
> >
<path <path
fill-rule="evenodd" fill-rule="evenodd"
@@ -0,0 +1,28 @@
<script lang="ts">
import Button from '$lib/components/input/Button.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import type { Community } from 'lemmy-js-client'
export let items: Community[]
export let expanded: boolean
</script>
{#each items.sort((a, b) => a.title.localeCompare(b.title)) as follow}
<Button
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
color="tertiary"
alignment="left"
href="/c/{follow.name}@{new URL(follow.actor_id).hostname}"
>
<Avatar
url={follow.icon}
alt={follow.name}
title={follow.title}
width={20}
slot="icon"
/>
<span class:hidden={!expanded}>
{follow.title}
</span>
</Button>
{/each}
@@ -8,12 +8,14 @@
Plus, Plus,
UserCircle, UserCircle,
} from 'svelte-hero-icons' } from 'svelte-hero-icons'
import Button from '../input/Button.svelte' import Button from '../../input/Button.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte' import Avatar from '$lib/components/ui/Avatar.svelte'
import { profile, profileData, setUserID } from '$lib/auth.js' import { profile, profileData, setUserID } from '$lib/auth.js'
import { goto } from '$app/navigation' import { goto } from '$app/navigation'
import { page } from '$app/stores' import { page } from '$app/stores'
import { slide } from 'svelte/transition' import { slide } from 'svelte/transition'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import CommunityList from '$lib/components/ui/sidebar/CommunityList.svelte'
let expanded = true let expanded = true
</script> </script>
@@ -37,36 +39,24 @@
title="Toggle expanded" title="Toggle expanded"
/> />
</Button> </Button>
<Button <SidebarButton href="/" {expanded}>
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
href="/"
color="tertiary"
alignment="left"
>
<Icon src={Home} solid size="20" title="Frontpage" /> <Icon src={Home} solid size="20" title="Frontpage" />
<span class:hidden={!expanded}>Frontpage</span> <span class:hidden={!expanded}>Frontpage</span>
</Button> </SidebarButton>
<Button <SidebarButton href="/settings" {expanded}>
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
href="/settings"
color="tertiary"
alignment="left"
>
<Icon src={Cog6Tooth} solid size="20" title="Settings" /> <Icon src={Cog6Tooth} solid size="20" title="Settings" />
<span class:hidden={!expanded}>Settings</span> <span class:hidden={!expanded}>Settings</span>
</Button> </SidebarButton>
{#if $profileData.profiles.length >= 1} {#if $profileData.profiles.length >= 1}
<hr class="border-slate-300 dark:border-zinc-800 my-1" /> <hr class="border-slate-300 dark:border-zinc-800 my-1" />
{#each $profileData.profiles as prof, index} {#each $profileData.profiles as prof, index}
<Button <SidebarButton
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'} {$profile?.id == class={$profile?.id == prof.id
prof.id
? expanded ? expanded
? 'font-bold' ? 'font-bold'
: 'text-sky-500' : 'text-sky-500'
: ''}" : ''}
color="tertiary" {expanded}
alignment="left"
on:click={() => { on:click={() => {
setUserID(prof.id) setUserID(prof.id)
goto($page.url, { goto($page.url, {
@@ -88,30 +78,23 @@
{prof.instance} {prof.instance}
</span> </span>
</span> </span>
</Button> </SidebarButton>
{/each} {/each}
{/if} {/if}
<hr class="border-slate-300 dark:border-zinc-800 my-1" /> <hr class="border-slate-300 dark:border-zinc-800 my-1" />
{#if $profile?.user} {#if $profile?.user}
{#each $profile.user.follows {#if $profile?.user.moderates.length > 0}
.map((f) => f.community) <CommunityList
.sort((a, b) => a.title.localeCompare(b.title)) as follow} {expanded}
<Button items={$profile.user.moderates.map((i) => i.community)}
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}" />
color="tertiary" <hr class="border-slate-300 dark:border-zinc-800 my-1" />
alignment="left" {/if}
href="/c/{follow.name}@{new URL(follow.actor_id).hostname}"
> <CommunityList
<Avatar {expanded}
url={follow.icon} items={$profile.user.follows.map((i) => i.community)}
alt={follow.name} />
title={follow.title}
width={20}
slot="icon"
/>
<span class:hidden={!expanded}>{follow.title}</span>
</Button>
{/each}
{#if $profile.user.follows.length == 0} {#if $profile.user.follows.length == 0}
<Button <Button
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}" class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
@@ -0,0 +1,14 @@
<script lang="ts">
import Button from '$lib/components/input/Button.svelte'
export let expanded: boolean
</script>
<Button
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
color="tertiary"
alignment="left"
{...$$restProps}
>
<slot />
</Button>
+1 -1
View File
@@ -6,7 +6,7 @@
import 'nprogress/nprogress.css' import 'nprogress/nprogress.css'
import ToastContainer from '$lib/components/ui/toasts/ToastContainer.svelte' import ToastContainer from '$lib/components/ui/toasts/ToastContainer.svelte'
import Moderation from '$lib/components/lemmy/moderation/Moderation.svelte' import Moderation from '$lib/components/lemmy/moderation/Moderation.svelte'
import Sidebar from '$lib/components/ui/Sidebar.svelte' import Sidebar from '$lib/components/ui/sidebar/Sidebar.svelte'
import { onMount } from 'svelte' import { onMount } from 'svelte'
// @ts-ignore // @ts-ignore
import { pwaInfo } from 'virtual:pwa-info' import { pwaInfo } from 'virtual:pwa-info'