Skip to content

Commit

Permalink
update to deno 2, get theme selector working
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Oct 13, 2024
1 parent 91ca5e1 commit 6d61a44
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"nodeModulesDir": true
"nodeModulesDir": "auto"
}
12 changes: 9 additions & 3 deletions islands/theme-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { useSignal } from "@preact/signals";
import { signal } from "@preact/signals";

import { Button } from "../components/ui/Button.tsx";
import { Icons } from "../components/icons.tsx";

export function ThemeToggle() {
const theme = useSignal("light");
export const theme = signal("dark");

export function ThemeToggle() {
return (
<Button
variant="ghost"
size="sm"
onClick={() => {
theme.value = theme.value === "light" ? "dark" : "light";
if (theme.value === "light") {
document.documentElement.classList.remove("dark");
} else {
document.documentElement.classList.add("dark");
}

console.log(theme.value);
}}
>
Expand Down
4 changes: 3 additions & 1 deletion routes/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { siteConfig } from "../config/site.ts";
import MainNav from "../components/main-nav.tsx";
import SiteHeader from "../islands/site-header.tsx";

import { theme } from "../islands/theme-toggle.tsx";

export default function App({ Component, url }: PageProps) {
return (
<html class="dark">
<html className={theme.value}>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down
14 changes: 5 additions & 9 deletions util/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ export function cn(...inputs: ClassValue[]) {
}

export function getDomain(hostname: string) {
try {
const domainParts = hostname.split(".");
const domainParts = hostname.split(".");

const domain = `${domainParts[domainParts.length - 1]}
${domainParts[domainParts.length]}`;
const subdomain = hostname.split(domain)[0];
return { domain, subdomain };
} catch (e) {
throw new Error(e.message);
}
const domain = `${domainParts[domainParts.length - 1]}
${domainParts[domainParts.length]}`;
const subdomain = hostname.split(domain)[0];
return { domain, subdomain };
}

export const RESERVED = [
Expand Down

0 comments on commit 6d61a44

Please sign in to comment.