import type { ColumnKind } from "$/lib/api/types/columns";
import type { SearchMode } from "$/lib/api/types/search";
import { createEffect, createSignal, For, Match, onCleanup, Show, splitProps, Switch } from "solid-js";
import { Portal } from "solid-js/web";
import { Motion, Presence } from "solid-motionone";
import { Icon } from "../shared/Icon";
import { DiagnosticsPicker, ExplorerPicker, FeedPicker, MessagesPicker } from "./ColumnPicker";
import { ProfilePicker } from "./ColumnPicker/ProfileColumnPicker";
import { SearchPicker } from "./ColumnPicker/SearchPicker";
import type { FeedPickerSelection, ProfileSelection } from "./types";
type AddColumnPanelProps = { onAdd: (kind: ColumnKind, config: string) => void; onClose: () => void; open: boolean };
type PanelTab = ColumnKind;
type PanelSubmissionHandlers = {
onDiagnosticsSubmit: (did: string) => void;
onExplorerSubmit: (uri: string) => void;
onFeedSelect: (selection: FeedPickerSelection) => void;
onMessagesSubmit: () => void;
onProfileSubmit: (selection: ProfileSelection) => void;
onSearchSubmit: (query: string, mode: SearchMode) => void;
};
function PanelContent(props: { handlers: PanelSubmissionHandlers; tab: PanelTab }) {
return (
);
}
function AddColumnPanelHeader(props: { onClose: () => void }) {
return (
);
}
type AddColumnPanelTabsProps = {
activeTab: PanelTab;
onTabChange: (tab: PanelTab) => void;
tabs: Array<{ icon: string; id: PanelTab; label: string }>;
};
function AddColumnPanelTabs(props: AddColumnPanelTabsProps) {
return (
{(tab) => (
)}
);
}
type AddColumnPanelFrame = {
activeTab: PanelTab;
onClose: () => void;
onTabChange: (tab: PanelTab) => void;
tabs: Array<{ icon: string; id: PanelTab; label: string }>;
};
type AddColumnPanelBodyProps = { frame: AddColumnPanelFrame; handlers: PanelSubmissionHandlers };
function AddColumnPanelBody(props: AddColumnPanelBodyProps) {
const [frameProps, contentProps] = splitProps(props, ["frame"], ["handlers"]);
return (
);
}
export function AddColumnPanel(props: AddColumnPanelProps) {
const [panelState, panelActions] = splitProps(props, ["open"], ["onAdd", "onClose"]);
const [activeTab, setActiveTab] = createSignal("feed");
function handleFeedSelect(selection: FeedPickerSelection) {
const config = JSON.stringify({
feedType: selection.feed.type,
feedUri: selection.feed.value,
title: selection.title,
});
panelActions.onAdd("feed", config);
}
function handleExplorerSubmit(uri: string) {
const config = JSON.stringify({ targetUri: uri });
panelActions.onAdd("explorer", config);
}
function handleDiagnosticsSubmit(did: string) {
const config = JSON.stringify({ did });
panelActions.onAdd("diagnostics", config);
}
function handleMessagesSubmit() {
panelActions.onAdd("messages", JSON.stringify({}));
}
function handleSearchSubmit(query: string, mode: SearchMode) {
panelActions.onAdd("search", JSON.stringify({ mode, query }));
}
function handleProfileSubmit(selection: ProfileSelection) {
panelActions.onAdd("profile", JSON.stringify(selection));
}
// TODO: use IconKind for Icon
const tabs: Array<{ icon: string; id: PanelTab; label: string }> = [
{ icon: "i-ri-rss-line", id: "feed", label: "Feed" },
{ icon: "i-ri-compass-discover-line", id: "explorer", label: "Explorer" },
{ icon: "i-ri-stethoscope-line", id: "diagnostics", label: "Diagnostics" },
{ icon: "i-ri-message-3-line", id: "messages", label: "DMs" },
{ icon: "i-ri-search-line", id: "search", label: "Search" },
{ icon: "i-ri-user-3-line", id: "profile", label: "Profile" },
];
function handleKeyDown(event: KeyboardEvent) {
if (event.key === "Escape") {
panelActions.onClose();
}
}
createEffect(() => {
if (!panelState.open) {
setActiveTab("feed");
return;
}
globalThis.addEventListener("keydown", handleKeyDown);
onCleanup(() => globalThis.removeEventListener("keydown", handleKeyDown));
});
return (
panelActions.onClose()} />
);
}