From 5636abbd5ba7fa7af12a8d9a45c09abff819d077 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Fri, 25 Aug 2023 15:05:13 -0700 Subject: [PATCH] feat: add debug info --- .../lemmy/moderation/ModerationMenu.svelte | 8 +++--- .../components/lemmy/post/PostActions.svelte | 27 +++++++++++++------ .../components/util/debug/DebugObject.svelte | 12 +++++++++ .../components/util/debug/DebugTree.svelte | 24 +++++++++++++++++ src/lib/settings.ts | 2 ++ .../post/[instance]/[id=integer]/+page.svelte | 1 + src/routes/settings/+page.svelte | 10 +++++++ 7 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 src/lib/components/util/debug/DebugObject.svelte create mode 100644 src/lib/components/util/debug/DebugTree.svelte diff --git a/src/lib/components/lemmy/moderation/ModerationMenu.svelte b/src/lib/components/lemmy/moderation/ModerationMenu.svelte index 58ee1795..2109a1a0 100644 --- a/src/lib/components/lemmy/moderation/ModerationMenu.svelte +++ b/src/lib/components/lemmy/moderation/ModerationMenu.svelte @@ -89,10 +89,10 @@ {#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))} - Moderation {#if (!item.community.local) } (Instance Only) {/if} + Moderation {#if !item.community.local} (Instance Only) {/if} {#if $profile?.user && $profile.user.local_user_view.person.id != item.creator.id} - User {#if (!item.community.local) } (Instance Only) {/if} + User {#if !item.community.local} (Instance Only) {/if} import type { PostView } from 'lemmy-js-client' import PostVote from './PostVote.svelte' - import { getClient, getInstance } from '$lib/lemmy.js' + import { getInstance } from '$lib/lemmy.js' import { ArrowTopRightOnSquare, Bookmark, BookmarkSlash, + BugAnt, ChatBubbleOvalLeftEllipsis, EllipsisHorizontal, Eye, @@ -22,8 +23,6 @@ import Menu from '$lib/components/ui/menu/Menu.svelte' import Button from '$lib/components/input/Button.svelte' import MenuButton from '$lib/components/ui/menu/MenuButton.svelte' - import { page } from '$app/stores' - import { toast } from '$lib/components/ui/toasts/toasts.js' import { createEventDispatcher } from 'svelte' import Modal from '$lib/components/ui/modal/Modal.svelte' import { @@ -37,12 +36,14 @@ import { deleteItem, markAsRead, save } from '$lib/lemmy/contentview.js' import { setSessionStorage } from '$lib/session.js' import { goto } from '$app/navigation' + import { userSettings } from '$lib/settings.js' export let post: PostView const dispatcher = createEventDispatcher<{ edit: PostView }>() let editing = false + export let debug: boolean = false {#if editing} @@ -71,7 +72,7 @@ {/if} -
+
+ + {#if $userSettings.debugInfo} + {#if debug} + {#await import('$lib/components/util/debug/DebugObject.svelte') then { default: DebugObject }} + + {/await} + {/if} + + {/if} {#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))} {/if} @@ -106,8 +117,8 @@ slot="button" aria-label="Post actions" on:click={toggleOpen} - class="!p-1.5 dark:text-zinc-400 text-slate-500 hover:text-inherit h-full" - color="secondary" + class="hover:text-inherit" + size="square-md" > diff --git a/src/lib/components/util/debug/DebugObject.svelte b/src/lib/components/util/debug/DebugObject.svelte new file mode 100644 index 00000000..219002db --- /dev/null +++ b/src/lib/components/util/debug/DebugObject.svelte @@ -0,0 +1,12 @@ + + + + Debug + + diff --git a/src/lib/components/util/debug/DebugTree.svelte b/src/lib/components/util/debug/DebugTree.svelte new file mode 100644 index 00000000..a07d9c52 --- /dev/null +++ b/src/lib/components/util/debug/DebugTree.svelte @@ -0,0 +1,24 @@ + + +
    + {#each Object.keys(object) as key} +
    + + {key} + + {#if typeof object[key] === 'object'} + + {:else} +
    {object[key]}
    + {/if} +
    + {/each} +
+ + diff --git a/src/lib/settings.ts b/src/lib/settings.ts index bb2b5ecc..707f34b5 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -50,6 +50,7 @@ interface Settings { newVote: boolean randomPlaceholders: boolean modlogCardView: boolean | undefined + debugInfo: boolean } export const defaultSettings: Settings = { @@ -87,6 +88,7 @@ export const defaultSettings: Settings = { newVote: toBool(env.PUBLIC_NEW_VOTE_BUTTONS) ?? false, randomPlaceholders: toBool(env.PUBLIC_RANDOM_PLACEHOLDERS) ?? true, modlogCardView: toBool(env.PUBLIC_MODLOG_CARD_VIEW) ?? undefined, + debugInfo: false, } export const userSettings = writable(defaultSettings) diff --git a/src/routes/post/[instance]/[id=integer]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte index a2867ff2..37c87bdb 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.svelte +++ b/src/routes/post/[instance]/[id=integer]/+page.svelte @@ -23,6 +23,7 @@ import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte' import Link from '$lib/components/input/Link.svelte' import SectionTitle from '$lib/components/ui/SectionTitle.svelte' + import { userSettings } from '$lib/settings.js' export let data diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte index 8a5dab74..d1025c0b 100644 --- a/src/routes/settings/+page.svelte +++ b/src/routes/settings/+page.svelte @@ -199,4 +199,14 @@ })} /> + + Other + + + Debug Info + + + Show an option to show debug information. (in posts and such) + +