Skip to content

Commit

Permalink
feat: show theme data in admin data explorer.
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Jan 27, 2025
1 parent 24f780b commit 34fafbe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/lib/leaf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Tags,
WebLinks,
WeirdCustomDomain,
WeirdTheme,
WeirdWikiPage,
WeirdWikiRevisionAuthor
} from './profile';
Expand Down Expand Up @@ -80,6 +81,7 @@ export type KnownComponents = {
commonmark?: CommonMark['value'];
weirdWikiPage?: WeirdWikiPage['value'];
weirdWikiRevisionAuthor?: WeirdWikiRevisionAuthor['value'];
weirdTheme?: WeirdTheme['value'];
};

export async function loadKnownComponents(link: ExactLink): Promise<KnownComponents | undefined> {
Expand All @@ -92,10 +94,16 @@ export async function loadKnownComponents(link: ExactLink): Promise<KnownCompone
WeirdCustomDomain,
CommonMark,
WeirdWikiPage,
WeirdWikiRevisionAuthor
WeirdWikiRevisionAuthor,
WeirdTheme
);

if (ent) {
let weirdTheme = ent.get(WeirdTheme)?.value;
if (weirdTheme) {
// work around the fact that borsh deserializes Uint8Arrays as number[] 🙁
weirdTheme = { data: new Uint8Array(weirdTheme.data) };
}
return {
name: ent.get(Name)?.value,
description: ent.get(Description)?.value,
Expand All @@ -104,7 +112,8 @@ export async function loadKnownComponents(link: ExactLink): Promise<KnownCompone
weirdCustomDomain: ent.get(WeirdCustomDomain)?.value,
commonmark: ent.get(CommonMark)?.value,
weirdWikiPage: ent.get(WeirdWikiPage)?.value,
weirdWikiRevisionAuthor: ent.get(WeirdWikiRevisionAuthor)?.value
weirdWikiRevisionAuthor: ent.get(WeirdWikiRevisionAuthor)?.value,
weirdTheme
};
} else {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// @ts-nocheck
import { leafClient, type KnownComponents, loadKnownComponents } from '$lib/leaf';
import { base32Decode, base32Encode, type EntityPath, type ExactLink } from 'leaf-proto';
import { createThemeData } from "$lib/renderer"
import type { Actions, PageServerLoad } from './$types';
import { error, fail, redirect } from '@sveltejs/kit';
import {
Tags,
WebLinks,
WeirdCustomDomain,
WeirdWikiPage,
WeirdWikiRevisionAuthor
WeirdWikiRevisionAuthor,
WeirdTheme
} from '$lib/leaf/profile';
import { CommonMark, Description, Name } from 'leaf-proto/components';
import { getSession } from '$lib/rauthy/server';
Expand Down Expand Up @@ -96,14 +98,16 @@ export const actions = {

const formData = await request.formData();

// let username: string | undefined = formData.get('username')?.toString() || '';
// if (username == '') username = undefined;
// components.push(username ? new Username(username) : Username);

let name: string | undefined = formData.get('name')?.toString() || '';
if (name == '') name = undefined;
components.push(name ? new Name(name) : Name);

let profileTheme: string | undefined = formData.get('profileTheme')?.toString() || '';
if (profileTheme == '') name = undefined;
let pageTheme: string | undefined = formData.get('pageTheme')?.toString() || '';
if (pageTheme == '') name = undefined;
components.push(profileTheme && pageTheme ? new WeirdTheme(createThemeData(profileTheme, pageTheme)) : WeirdTheme);

let description: string | undefined = formData.get('description')?.toString() || '';
if (description == '') description = undefined;
components.push(description ? new Description(description) : Description);
Expand Down Expand Up @@ -147,6 +151,7 @@ export const actions = {

await leafClient.update_components(link, components);
} catch (e: any) {
console.error(e);
return fail(400, { error: JSON.stringify(e) });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { formatEntityPath } from 'leaf-proto';
import type { ActionData, PageData } from './$types';
import type { KnownComponents } from '$lib/leaf';
import { parseThemeData } from '$lib/renderer';
const { data, form }: { data: PageData; form: ActionData } = $props();
Expand Down Expand Up @@ -39,6 +40,9 @@
let knownComponents: KnownComponents = $derived(data.components || {});
let editingTagsState = $state('');
let editingWebLinksState = $state('');
let theme: { profile: string; page?: string } | undefined = $derived(
knownComponents.weirdTheme && parseThemeData(knownComponents.weirdTheme.data)
);
$effect(() => {
editingTagsState = data.components?.tags?.join(', ') || '';
Expand Down Expand Up @@ -165,8 +169,12 @@
<textarea class="input" name="webLinks" value={editingWebLinksState}></textarea>
</label>
<label>
Pubpage Theme
<input class="input" name="pubpageTheme" value={knownComponents.weirdPubpageTheme} />
Profile Theme
<textarea class="input" name="profileTheme" value={theme?.profile}></textarea>
</label>
<label>
Page Theme
<textarea class="input" name="pageTheme" value={theme?.page}></textarea>
</label>
<label>
Custom Domain
Expand Down

0 comments on commit 34fafbe

Please sign in to comment.