SIdebar
This commit is contained in:
+1
-1
@@ -7,11 +7,11 @@ import {
|
|||||||
ResizablePanel,
|
ResizablePanel,
|
||||||
ResizablePanelGroup,
|
ResizablePanelGroup,
|
||||||
} from "./components/ui/resizable";
|
} from "./components/ui/resizable";
|
||||||
import Sidebar from "./components/view/Sidebar";
|
|
||||||
import { ThemeProvider } from "next-themes";
|
import { ThemeProvider } from "next-themes";
|
||||||
import Page from "./components/page/PageView";
|
import Page from "./components/page/PageView";
|
||||||
import { SettingsDialog } from "./components/settings/SettingsDialog";
|
import { SettingsDialog } from "./components/settings/SettingsDialog";
|
||||||
import { TooltipProvider } from "./components/ui/tooltip";
|
import { TooltipProvider } from "./components/ui/tooltip";
|
||||||
|
import Sidebar from "./components/sidebar/Sidebar";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const appRef = useRef<Enclave | null>(null);
|
const appRef = useRef<Enclave | null>(null);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export default class Enclave<P = Page> {
|
|||||||
public isSettingsOpen: boolean;
|
public isSettingsOpen: boolean;
|
||||||
public forceRender: () => void;
|
public forceRender: () => void;
|
||||||
public page?: P;
|
public page?: P;
|
||||||
|
public sidebarPageKind: "server" | "main";
|
||||||
public config?: Config;
|
public config?: Config;
|
||||||
public backendConfig: BackendConfig;
|
public backendConfig: BackendConfig;
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ export default class Enclave<P = Page> {
|
|||||||
isMuted: false,
|
isMuted: false,
|
||||||
isDeaf: false,
|
isDeaf: false,
|
||||||
};
|
};
|
||||||
|
this.sidebarPageKind = "main";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init() {
|
public async init() {
|
||||||
@@ -106,6 +108,8 @@ export default class Enclave<P = Page> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async connectToServer(hostname: string, isSecure: boolean) {
|
public async connectToServer(hostname: string, isSecure: boolean) {
|
||||||
|
this.sidebarPageKind = "server";
|
||||||
|
|
||||||
if (this.server) {
|
if (this.server) {
|
||||||
this.server.disconnect();
|
this.server.disconnect();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function AddServerDialog({ onAdd }: AddServerDialogProps) {
|
|||||||
render={() => (
|
render={() => (
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
className="aspect-square w-full h-auto rounded-full"
|
className="aspect-square w-full h-auto rounded-lg"
|
||||||
onClick={() => setOpen(true)}
|
onClick={() => setOpen(true)}
|
||||||
>
|
>
|
||||||
<PlusIcon />
|
<PlusIcon />
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import Enclave from "@/app/app";
|
||||||
|
|
||||||
|
export default function MainPageSidebar({
|
||||||
|
appRef,
|
||||||
|
}: {
|
||||||
|
appRef: React.RefObject<Enclave | null>;
|
||||||
|
}) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ import Enclave from "@/app/app";
|
|||||||
import { Channel, ChannelKind } from "@/lib/types";
|
import { Channel, ChannelKind } from "@/lib/types";
|
||||||
import { ChevronDown, ChevronUp, HashIcon, Volume2Icon } from "lucide-react";
|
import { ChevronDown, ChevronUp, HashIcon, Volume2Icon } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import StatusCard from "./StatusCard";
|
import StatusCard from "../view/StatusCard";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ export function RenderChannels({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Sidebar({
|
export default function ServerSidebar({
|
||||||
appRef,
|
appRef,
|
||||||
}: {
|
}: {
|
||||||
appRef: React.RefObject<Enclave | null>;
|
appRef: React.RefObject<Enclave | null>;
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import Enclave from "@/app/app";
|
||||||
|
import ServerSidebar from "./ServerSidebar";
|
||||||
|
import MainPageSidebar from "./MainPageSidebar";
|
||||||
|
|
||||||
|
export default function Sidebar({
|
||||||
|
appRef,
|
||||||
|
}: {
|
||||||
|
appRef: React.RefObject<Enclave | null>;
|
||||||
|
}) {
|
||||||
|
switch (appRef.current?.sidebarPageKind) {
|
||||||
|
case "main":
|
||||||
|
return <MainPageSidebar appRef={appRef} />;
|
||||||
|
case "server":
|
||||||
|
return <ServerSidebar appRef={appRef} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <MainPageSidebar appRef={appRef} />;
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ import Enclave from "@/app/app";
|
|||||||
import { getHTTPUrl, saveServerList } from "@/lib/serverList";
|
import { getHTTPUrl, saveServerList } from "@/lib/serverList";
|
||||||
import { AddServerDialog } from "../dialog/AddServerDialog";
|
import { AddServerDialog } from "../dialog/AddServerDialog";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Button } from "../ui/button";
|
||||||
|
import { CommandIcon } from "lucide-react";
|
||||||
|
|
||||||
export default function ServerList({
|
export default function ServerList({
|
||||||
appRef,
|
appRef,
|
||||||
@@ -12,6 +14,19 @@ export default function ServerList({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className="w-16 h-screen p-2 flex flex-col gap-2.5 border-r border-r-border shrink-0">
|
<aside className="w-16 h-screen p-2 flex flex-col gap-2.5 border-r border-r-border shrink-0">
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
className="aspect-square w-full h-auto rounded-full"
|
||||||
|
onClick={() => {
|
||||||
|
if (appRef.current) {
|
||||||
|
appRef.current.sidebarPageKind = "main";
|
||||||
|
appRef.current.page = undefined;
|
||||||
|
appRef.current.forceRender();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CommandIcon />
|
||||||
|
</Button>
|
||||||
{appRef.current.serverList.map((server) => {
|
{appRef.current.serverList.map((server) => {
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
@@ -34,7 +49,6 @@ export default function ServerList({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<AddServerDialog
|
<AddServerDialog
|
||||||
onAdd={(hostname, isSecure) => {
|
onAdd={(hostname, isSecure) => {
|
||||||
if (!appRef.current) {
|
if (!appRef.current) {
|
||||||
|
|||||||
Reference in New Issue
Block a user