From 4fb4d2b7b86c30abd7d69edd87f7eeeba49d6fb0 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Thu, 3 Aug 2023 10:40:12 -0700 Subject: [PATCH] fix: fix guest instance not working --- src/lib/auth.ts | 24 +++---- .../lemmy/moderation/ShieldIcon.svelte | 2 + .../ui/sidebar/CommunityList.svelte | 28 ++++++++ .../ui/{ => sidebar}/Sidebar.svelte | 65 +++++++------------ .../ui/sidebar/SidebarButton.svelte | 14 ++++ src/routes/+layout.svelte | 2 +- 6 files changed, 78 insertions(+), 57 deletions(-) create mode 100644 src/lib/components/ui/sidebar/CommunityList.svelte rename src/lib/components/ui/{ => sidebar}/Sidebar.svelte (71%) create mode 100644 src/lib/components/ui/sidebar/SidebarButton.svelte diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 8c8bc566..7442a980 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -23,6 +23,7 @@ interface Profile { jwt?: string user?: PersonData username?: string + favorites?: number[] } /** @@ -43,13 +44,10 @@ export const profileData = writable( getFromStorage('profileData') ?? { profiles: [], profile: -1 } ) -let initialInstance = get(profileData).defaultInstance - profileData.subscribe(async (pd) => { setFromStorage('profileData', pd) - if (pd.profile == -1 && pd.defaultInstance != initialInstance) { - initialInstance = get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL + if (pd.profile == -1) { 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() { const id = get(profileData).profile if (id == -1) { - return + return getDefaultProfile() } const pd = get(profileData) @@ -150,10 +142,12 @@ function getProfile() { return pd.profiles.find((p) => p.id == id) } -const getDefaultProfile = () => ({ - id: -1, - instance: get(instance), -}) +function getDefaultProfile() { + return { + id: -1, + instance: get(profileData)?.defaultInstance ?? get(instance), + } +} export function resetProfile() { profile.set(getDefaultProfile()) diff --git a/src/lib/components/lemmy/moderation/ShieldIcon.svelte b/src/lib/components/lemmy/moderation/ShieldIcon.svelte index 99047c74..c13554f3 100644 --- a/src/lib/components/lemmy/moderation/ShieldIcon.svelte +++ b/src/lib/components/lemmy/moderation/ShieldIcon.svelte @@ -10,6 +10,7 @@ viewBox="0 0 20 22" fill="none" xmlns="http://www.w3.org/2000/svg" + class="inline" > + 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 + + +{#each items.sort((a, b) => a.title.localeCompare(b.title)) as follow} + +{/each} diff --git a/src/lib/components/ui/Sidebar.svelte b/src/lib/components/ui/sidebar/Sidebar.svelte similarity index 71% rename from src/lib/components/ui/Sidebar.svelte rename to src/lib/components/ui/sidebar/Sidebar.svelte index 47f55b5f..7add28fa 100644 --- a/src/lib/components/ui/Sidebar.svelte +++ b/src/lib/components/ui/sidebar/Sidebar.svelte @@ -8,12 +8,14 @@ Plus, UserCircle, } 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 { profile, profileData, setUserID } from '$lib/auth.js' import { goto } from '$app/navigation' import { page } from '$app/stores' 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 @@ -37,36 +39,24 @@ title="Toggle expanded" /> - - + {#if $profileData.profiles.length >= 1}
{#each $profileData.profiles as prof, index} - + {/each} {/if}
{#if $profile?.user} - {#each $profile.user.follows - .map((f) => f.community) - .sort((a, b) => a.title.localeCompare(b.title)) as follow} - - {/each} + {#if $profile?.user.moderates.length > 0} + i.community)} + /> +
+ {/if} + + i.community)} + /> {#if $profile.user.follows.length == 0} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 8b378482..a3b80d56 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -6,7 +6,7 @@ import 'nprogress/nprogress.css' import ToastContainer from '$lib/components/ui/toasts/ToastContainer.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' // @ts-ignore import { pwaInfo } from 'virtual:pwa-info'