import styled from "@emotion/styled"; import { useSearch } from "@tanstack/react-router"; import { Button } from "baseui/button"; import { Input } from "baseui/input"; import { PLACEMENT, ToasterContainer } from "baseui/toast"; import { LabelMedium } from "baseui/typography"; import { useAtomValue } from "jotai"; import { useEffect, useState } from "react"; import { profileAtom } from "../atoms/profile"; import ScrobblesAreaChart from "../components/ScrobblesAreaChart"; import StickyPlayer from "../components/StickyPlayer"; import { API_URL } from "../consts"; import useProfile from "../hooks/useProfile"; import CloudDrive from "./CloudDrive"; import ExternalLinks from "./ExternalLinks"; import Navbar from "./Navbar"; import Search from "./Search"; import SpotifyLogin from "./SpotifyLogin"; const Container = styled.div` display: flex; justify-content: center; height: 100vh; overflow-y: auto; flex-direction: row; `; const Flex = styled.div` display: flex; width: 770px; margin-top: 50px; flex-direction: column; margin-bottom: 200px; `; const RightPane = styled.div` @media (max-width: 1152px) { display: none; } `; const Link = styled.a` text-decoration: none; cursor: pointer; display: block; font-size: 13px; &:hover { text-decoration: underline; } `; export type MainProps = { children: React.ReactNode; withRightPane?: boolean; }; function Main(props: MainProps) { const { children } = props; const withRightPane = props.withRightPane ?? true; const [handle, setHandle] = useState(""); const jwt = localStorage.getItem("token"); const profile = useAtomValue(profileAtom); const [token, setToken] = useState(null); const { did, cli } = useSearch({ strict: false }); useEffect(() => { if (did && did !== "null") { localStorage.setItem("did", did); const fetchToken = async () => { try { const response = await fetch(`${API_URL}/token`, { method: "GET", headers: { "session-did": did, }, }); const data = await response.json(); localStorage.setItem("token", data.token); setToken(data.token); if (cli) { await fetch("http://localhost:6996/token", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ token: data.token }), }); } if (!jwt && data.token) { window.location.href = "/"; } } catch (e) { console.error(e); } }; fetchToken(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); useProfile(token || localStorage.getItem("token")); const onLogin = async () => { if (!handle.trim()) { return; } if (API_URL.includes("localhost")) { window.location.href = `${API_URL}/login?handle=${handle}`; return; } window.location.href = `https://rocksky.pages.dev/loading?handle=${handle}`; }; return (
{children}
{withRightPane && (
{jwt && profile && !profile.spotifyConnected && } {jwt && profile && } {!jwt && (
Bluesky handle
@
} placeholder=".bsky.social" value={handle} onChange={(e) => setHandle(e.target.value)} overrides={{ Root: { style: { backgroundColor: "var(--color-input-background)", borderColor: "var(--color-input-background)", }, }, StartEnhancer: { style: { backgroundColor: "var(--color-input-background)", }, }, InputContainer: { style: { backgroundColor: "var(--color-input-background)", }, }, Input: { style: { color: "var(--color-text)", caretColor: "var(--color-text)", }, }, }} />
Don't have an account?
Sign up for Bluesky {" "} to create one now!
)}
About FAQ API Docs Discord
)}
); } export default Main;