import { Typewriter } from "./Typewriter"; import { useBars } from "~/context/bars"; import { onMount, createSignal, Show, For, onCleanup, createEffect } from "solid-js"; import { api } from "~/lib/api"; import { insertSoftHyphens } from "~/lib/client-utils"; import GitHub from "./icons/GitHub"; import LinkedIn from "./icons/LinkedIn"; import { RecentCommits } from "./RecentCommits"; import { ActivityHeatmap } from "./ActivityHeatmap"; import { DarkModeToggle } from "./DarkModeToggle"; import { SkeletonBox, SkeletonText } from "./SkeletonLoader"; import { env } from "~/env/client"; import { A, useNavigate, useLocation } from "@solidjs/router"; import { BREAKPOINTS } from "~/config"; function formatDomainName(url: string): string { const domain = url.split("://")[1]?.split(":")[0] ?? url; const withoutWww = domain.replace(/^www\./i, ""); return withoutWww.charAt(0).toUpperCase() + withoutWww.slice(1); } /** * Converts a banner photo URL to its thumbnail version * Replaces the filename with -small variant (e.g., image.jpg -> image-small.jpg) */ function getThumbnailUrl(bannerPhoto: string | null): string { if (!bannerPhoto) return "/blueprint.jpg"; // Check if URL contains a file extension const match = bannerPhoto.match(/^(.+)(\.[^.]+)$/); if (match) { return `${match[1]}-small${match[2]}`; } // Fallback to original if no extension found return bannerPhoto; } interface GitCommit { sha: string; message: string; author: string; date: string; repo: string; url: string; } interface ContributionDay { date: string; count: number; } export function RightBarContent() { const { setLeftBarVisible } = useBars(); const [githubCommits, setGithubCommits] = createSignal([]); const [giteaCommits, setGiteaCommits] = createSignal([]); const [githubActivity, setGithubActivity] = createSignal( [] ); const [giteaActivity, setGiteaActivity] = createSignal([]); const [loading, setLoading] = createSignal(true); const handleLinkClick = () => { if ( typeof window !== "undefined" && window.innerWidth < BREAKPOINTS.MOBILE ) { setLeftBarVisible(false); } }; onMount(() => { // Fetch all data client-side only to avoid hydration mismatch const fetchData = async () => { try { const [ghCommits, gtCommits, ghActivity, gtActivity] = await Promise.all([ api.gitActivity.getGitHubCommits .query({ limit: 3 }) .catch(() => []), api.gitActivity.getGiteaCommits.query({ limit: 3 }).catch(() => []), api.gitActivity.getGitHubActivity.query().catch(() => []), api.gitActivity.getGiteaActivity.query().catch(() => []) ]); setGithubCommits(ghCommits); setGiteaCommits(gtCommits); setGithubActivity(ghActivity); setGiteaActivity(gtActivity); } catch (error) { console.error("Failed to fetch git activity:", error); } finally { setLoading(false); } }; // Defer API calls to next tick to allow initial render to complete first setTimeout(() => { fetchData(); }, 0); }); return (
{/* Git Activity Section */}
); } export function LeftBar() { const { leftBarVisible, setLeftBarVisible } = useBars(); const location = useLocation(); let ref: HTMLDivElement | undefined; const [recentPosts, setRecentPosts] = createSignal( undefined ); const [userInfo, setUserInfo] = createSignal<{ email: string | null; isAuthenticated: boolean; } | null>(null); const [isMounted, setIsMounted] = createSignal(false); const [signOutLoading, setSignOutLoading] = createSignal(false); const [getLostText, setGetLostText] = createSignal("What's this?"); const [getLostVisible, setGetLostVisible] = createSignal(false); const handleLinkClick = () => { if ( typeof window !== "undefined" && window.innerWidth < BREAKPOINTS.MOBILE ) { setLeftBarVisible(false); } }; const handleSignOut = async () => { setSignOutLoading(true); try { await api.auth.signOut.mutate(); window.location.href = "/"; } catch (error) { console.error("Sign out failed:", error); setSignOutLoading(false); } }; const fetchUserInfo = async () => { try { const response = await fetch("/api/trpc/user.getProfile", { method: "GET" }); if (response.ok) { const result = await response.json(); if (result.result?.data) { setUserInfo({ email: result.result.data.email, isAuthenticated: true }); } else { setUserInfo({ email: null, isAuthenticated: false }); } } else { setUserInfo({ email: null, isAuthenticated: false }); } } catch (error) { console.error("Failed to fetch user info:", error); setUserInfo({ email: null, isAuthenticated: false }); } }; onMount(() => { setIsMounted(true); // Terminal-style appearance animation for "Get Lost" button const glitchChars = "!@#$%^&*()_+-=[]{}|;':\",./<>?~`"; const originalText = "What's this?"; let glitchInterval: NodeJS.Timeout; // Delay appearance to match terminal vibe setTimeout(() => { // Make visible immediately so typing animation is visible setGetLostVisible(true); // Type-in animation with random characters resolving let currentIndex = 0; const typeInterval = setInterval(() => { if (currentIndex <= originalText.length) { let displayText = originalText.substring(0, currentIndex); // Add random trailing characters if (currentIndex < originalText.length) { const remaining = originalText.length - currentIndex; for (let i = 0; i < remaining; i++) { displayText += glitchChars[Math.floor(Math.random() * glitchChars.length)]; } } setGetLostText(displayText); currentIndex++; } else { clearInterval(typeInterval); setGetLostText(originalText); // Start regular glitch effect after typing completes glitchInterval = setInterval(() => { if (Math.random() > 0.9) { // 10% chance to glitch let glitched = ""; for (let i = 0; i < originalText.length; i++) { if (Math.random() > 0.7) { // 30% chance each character glitches glitched += glitchChars[Math.floor(Math.random() * glitchChars.length)]; } else { glitched += originalText[i]; } } setGetLostText(glitched); setTimeout(() => { setGetLostText(originalText); }, 100); } }, 150); } }, 140); // Type speed (higher is slower) }, 500); // Initial delay before appearing if (ref) { // Focus trap for accessibility on mobile const handleKeyDown = (e: KeyboardEvent) => { const isMobile = window.innerWidth < BREAKPOINTS.MOBILE; if (!isMobile || !leftBarVisible()) return; if (e.key === "Tab") { const focusableElements = ref?.querySelectorAll( 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])' ); if (!focusableElements || focusableElements.length === 0) return; const firstElement = focusableElements[0] as HTMLElement; const lastElement = focusableElements[ focusableElements.length - 1 ] as HTMLElement; if (e.shiftKey) { // Shift+Tab - going backwards if (document.activeElement === firstElement) { e.preventDefault(); lastElement.focus(); } } else { // Tab - going forwards if (document.activeElement === lastElement) { e.preventDefault(); firstElement.focus(); } } } }; ref.addEventListener("keydown", handleKeyDown); onCleanup(() => { ref?.removeEventListener("keydown", handleKeyDown); clearInterval(glitchInterval); }); } else { onCleanup(() => { clearInterval(glitchInterval); }); } const fetchData = async () => { try { const posts = await api.blog.getRecentPosts.query(); setRecentPosts(posts as any[]); } catch (error) { console.error("Failed to fetch recent posts:", error); setRecentPosts([]); } await fetchUserInfo(); }; setTimeout(() => { fetchData(); }, 0); }); // Refetch user info whenever location changes createEffect(() => { // Track location changes location.pathname; // Only refetch if component is mounted if (isMounted()) { fetchUserInfo(); } }); const navigate = useNavigate(); return ( ); } export function RightBar() { const { rightBarVisible } = useBars(); let ref: HTMLDivElement | undefined; return ( ); }