mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-19 07:26:59 +01:00
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import classnames from 'classnames';
|
|
import type { HTMLAttributes } from 'react';
|
|
import React from 'react';
|
|
import { Link } from 'react-router-dom';
|
|
import { useRequestCreate } from '../hooks/useRequest';
|
|
import useTheme from '../hooks/useTheme';
|
|
import type { HttpRequest } from '../lib/models';
|
|
import { Button } from './Button';
|
|
import { IconButton } from './IconButton';
|
|
import { HStack, VStack } from './Stacks';
|
|
import { WindowDragRegion } from './WindowDragRegion';
|
|
|
|
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
workspaceId: string;
|
|
requests: HttpRequest[];
|
|
activeRequestId?: string;
|
|
}
|
|
|
|
export function Sidebar({ className, activeRequestId, workspaceId, requests, ...props }: Props) {
|
|
const createRequest = useRequestCreate({ workspaceId, navigateAfter: true });
|
|
const { toggleTheme } = useTheme();
|
|
return (
|
|
<div
|
|
className={classnames(className, 'w-52 bg-gray-50/40 h-full border-gray-500/10')}
|
|
{...props}
|
|
>
|
|
<HStack as={WindowDragRegion} items="center" className="pr-1" justify="end">
|
|
<IconButton size="sm" icon="sun" onClick={toggleTheme} />
|
|
<IconButton
|
|
size="sm"
|
|
icon="plus-circled"
|
|
onClick={async () => {
|
|
await createRequest.mutate({ name: 'Test Request' });
|
|
}}
|
|
/>
|
|
</HStack>
|
|
<VStack as="ul" className="py-3" space={1}>
|
|
{requests.map((r) => (
|
|
<SidebarItem key={r.id} request={r} active={r.id === activeRequestId} />
|
|
))}
|
|
</VStack>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function SidebarItem({ request, active }: { request: HttpRequest; active: boolean }) {
|
|
return (
|
|
<li key={request.id} className="mx-3">
|
|
<Button
|
|
as={Link}
|
|
to={`/workspaces/${request.workspaceId}/requests/${request.id}`}
|
|
className={classnames('w-full', active && 'bg-gray-50')}
|
|
size="xs"
|
|
justify="start"
|
|
>
|
|
{request.name}
|
|
</Button>
|
|
</li>
|
|
);
|
|
}
|