Feat: theme switching

This commit is contained in:
MotorTruck1221 2025-05-03 19:26:33 -06:00
parent a2c497363e
commit f9f62e1e41
No known key found for this signature in database
GPG key ID: 08F417E2B8B61EA4
5 changed files with 88 additions and 46 deletions

View file

@ -4,13 +4,17 @@ import SettingsNav from "@components/SettingsNav.astro";
import type { SettingsProps as Props } from "@utils/types.ts"; import type { SettingsProps as Props } from "@utils/types.ts";
//I love prop drilling //I love prop drilling
const { active } = Astro.props; const { active, title } = Astro.props;
--- ---
<Layout> <Layout>
<div class="h-full w-full flex font-inter"> <div class="h-full w-full flex font-inter">
<div class="w-1/4 bg-(--background) flex mt-14"> <div class="w-1/4 bg-(--background) flex mt-14">
<SettingsNav active={active} /> <SettingsNav active={active} />
</div> </div>
<slot /> <div class="h-full mt-14 flex-grow px-12 py-8 flex flex-col">
<h1 class="text-4xl font-semibold"> {title} </h1>
<div class="border-b border-(--border) w-full mb-4"></div>
<slot />
</div>
</div> </div>
</Layout> </Layout>

View file

@ -1,5 +1,48 @@
--- ---
import { readdir } from "node:fs/promises";
import { join as pathJoin } from "node:path";
import SettingsLayout from "@layouts/SettingsLayout.astro"; import SettingsLayout from "@layouts/SettingsLayout.astro";
import Dropdown from "@components/ui/Dropdown.astro";
import { type DropdownOptions } from "@utils/types";
const Themes: DropdownOptions[] = [{ name: 'Default', value: 'default' }];
const files = await readdir(pathJoin(import.meta.dirname, '..', '..', 'styles', 'themes'), { encoding: 'utf-8' });
files.forEach((name) => {
Themes.push({
name: name.toLowerCase().charAt(0).toUpperCase() + name.slice(1).replace('.css', ''),
value: name.toLowerCase().replace('.css', '')
});
});
--- ---
<SettingsLayout active="appearance"> <SettingsLayout active="appearance" title="Appearance">
<div class="w-full flex-grow">
<div>
<p> Themes </p>
<Dropdown id="themeSwitcher" options={Themes} />
</div>
</div>
</SettingsLayout> </SettingsLayout>
<script>
import { Settings } from "@utils/settings";
import { StoreManager } from "@utils/storage";
const themes = async (settings: Settings, storage: StoreManager<"radius||settings">) => {
const dropdown = document.getElementById("dropdownBox-themeSwitcher") as HTMLSelectElement;
dropdown.value = storage.getVal('theme');
dropdown.addEventListener("change", async () => {
settings.theme(dropdown.value);
});
};
document.addEventListener("astro:page-load", async () => {
try {
const settings = await Settings.getInstance();
const storageManager = new StoreManager<"radius||settings">("radius||settings");
await themes(settings, storageManager);
} catch (err) {
console.log(err);
};
});
</script>

View file

@ -9,45 +9,41 @@ Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
{ name: k, value: SearchEngines[k] } { name: k, value: SearchEngines[k] }
)); ));
--- ---
<SettingsLayout active="proxy"> <SettingsLayout active="proxy" title="Proxy">
<div class="h-full mt-14 flex-grow px-12 py-8 flex flex-col"> <div class="w-full flex-grow">
<h1 class="text-4xl font-semibold"> Proxy </h1> <div>
<div class="border-b border-(--border) w-full mb-4"></div> <p> Proxy Switcher </p>
<div class="w-full flex-grow"> <Dropdown id="pSwitcher" options={
[
{ name: 'Ultraviolet', value: 'uv', default: true },
{ name: 'Scramjet', value: 'sj' }
]
} />
</div>
<div class="mt-2">
<p> Transport </p>
<Dropdown id="tSwitcher" options={
[
{ name: 'Libcurl', value: 'libcurl', default: true },
{ name: 'Epoxy', value: 'epoxy' }
]
} />
</div>
<div class="mt-2">
<p> Search Engine </p>
<Dropdown id="sSwitcher" options={SearchEngineOptions} />
</div>
<div class="mt-2 w-80">
<div> <div>
<p> Proxy Switcher </p> <p> Wisp Server </p>
<Dropdown id="pSwitcher" options={ <Input id="wispServerSwitcher" placeholder="Wisp server URL (EX: wss://radiusproxy.app/wisp/" />
[
{ name: 'Ultraviolet', value: 'uv', default: true },
{ name: 'Scramjet', value: 'sj' }
]
} />
</div> </div>
<div class="mt-2"> <div class="mt-2 mb-2 hidden" id="wispServerInfo">
<p> Transport </p> <p class="text-blue-500" id="wispServerInfo-inner"> Checking URL... </p>
<Dropdown id="tSwitcher" options={
[
{ name: 'Libcurl', value: 'libcurl', default: true },
{ name: 'Epoxy', value: 'epoxy' }
]
} />
</div> </div>
<div class="mt-2"> <div class="mt-2 flex flex-row gap-4">
<p> Search Engine </p> <Button id="wispServerSave" text="Save Changes" icon="lucide:save" />
<Dropdown id="sSwitcher" options={SearchEngineOptions} /> <Button id="wispServerReset" text="Reset" icon="lucide:rotate-ccw" />
</div>
<div class="mt-2 w-80">
<div>
<p> Wisp Server </p>
<Input id="wispServerSwitcher" placeholder="Wisp server URL (EX: wss://radiusproxy.app/wisp/" />
</div>
<div class="mt-2 mb-2 hidden" id="wispServerInfo">
<p class="text-blue-500" id="wispServerInfo-inner"> Checking URL... </p>
</div>
<div class="mt-2 flex flex-row gap-4">
<Button id="wispServerSave" text="Save Changes" icon="lucide:save" />
<Button id="wispServerReset" text="Reset" icon="lucide:rotate-ccw" />
</div>
</div> </div>
</div> </div>
</div> </div>
@ -56,11 +52,7 @@ Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
import { Settings } from "@utils/settings.ts"; import { Settings } from "@utils/settings.ts";
import { SW } from "@utils/proxy.ts"; import { SW } from "@utils/proxy.ts";
import { StoreManager } from "@utils/storage"; import { StoreManager } from "@utils/storage";
import { SearchEngines, type DropdownOptions } from "@utils/types"; import { SearchEngines } from "@utils/types";
const SearchEngineOptions: DropdownOptions[] = [];
Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
{ name: k, value: SearchEngines[k] }
));
type Options = { type Options = {
settings: Settings, settings: Settings,
@ -148,6 +140,8 @@ Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
await proxy({settings, sw, storageManager}); await proxy({settings, sw, storageManager});
await searchEngine({settings, sw, storageManager}); await searchEngine({settings, sw, storageManager});
await wispServer({settings, sw, storageManager}); await wispServer({settings, sw, storageManager});
} catch (err) { console.log(err) } } catch (err) {
//console.log(err);
}
}); });
</script> </script>

View file

@ -104,7 +104,7 @@ const randomSplash = genSplash();
await init(); await init();
} }
catch (err) { catch (err) {
console.log(err); //console.log(err);
} }
}) })
</script> </script>

View file

@ -2,6 +2,7 @@ import type { Props } from "astro";
interface SettingsProps extends Props { interface SettingsProps extends Props {
active: 'appearance' | 'credits' | 'links' | 'proxy'; active: 'appearance' | 'credits' | 'links' | 'proxy';
title: string;
} }
type DropdownOptions = { type DropdownOptions = {