mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-26 03:11:28 +01:00
Floating sidebar refactor
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { HeaderSize, SidebarLayout } from '@yaakapp-internal/ui';
|
||||
import { HeaderSize, IconButton, SidebarLayout } from '@yaakapp-internal/ui';
|
||||
import classNames from 'classnames';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useState } from 'react';
|
||||
import { useLocalStorage } from 'react-use';
|
||||
import { useRpcQueryWithEvent } from '../hooks/useRpcQueryWithEvent';
|
||||
import { getOsType } from '../lib/tauri';
|
||||
@@ -12,8 +13,15 @@ export function ProxyLayout() {
|
||||
const os = getOsType();
|
||||
const exchanges = useAtomValue(filteredExchangesAtom);
|
||||
const [sidebarWidth, setSidebarWidth] = useLocalStorage('sidebar_width', 250);
|
||||
const [sidebarHidden, setSidebarHidden] = useLocalStorage('sidebar_hidden', false);
|
||||
const [floatingSidebarHidden, setFloatingSidebarHidden] = useLocalStorage(
|
||||
'floating_sidebar_hidden',
|
||||
true,
|
||||
);
|
||||
const [floating, setFloating] = useState(false);
|
||||
const { data: proxyState } = useRpcQueryWithEvent('get_proxy_state', {}, 'proxy_state_changed');
|
||||
const isRunning = proxyState?.state === 'running';
|
||||
const isHidden = floating ? (floatingSidebarHidden ?? true) : (sidebarHidden ?? false);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -30,7 +38,22 @@ export function ProxyLayout() {
|
||||
interfaceScale={1}
|
||||
className="x-theme-appHeader bg-surface"
|
||||
>
|
||||
<div className="grid grid-cols-[minmax(0,1fr)_auto]">
|
||||
<div className="grid grid-cols-[auto_minmax(0,1fr)_auto]">
|
||||
<div className="flex items-center pl-1">
|
||||
<IconButton
|
||||
size="sm"
|
||||
title="Toggle sidebar"
|
||||
icon={isHidden ? 'left_panel_hidden' : 'left_panel_visible'}
|
||||
iconColor="secondary"
|
||||
onClick={() => {
|
||||
if (floating) {
|
||||
setFloatingSidebarHidden(!floatingSidebarHidden);
|
||||
} else {
|
||||
setSidebarHidden(!sidebarHidden);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div data-tauri-drag-region className="flex items-center text-sm px-2">
|
||||
Yaak Proxy
|
||||
</div>
|
||||
@@ -61,7 +84,43 @@ export function ProxyLayout() {
|
||||
<SidebarLayout
|
||||
width={sidebarWidth ?? 250}
|
||||
onWidthChange={setSidebarWidth}
|
||||
sidebar={<Sidebar />}
|
||||
hidden={sidebarHidden ?? false}
|
||||
onHiddenChange={setSidebarHidden}
|
||||
floatingHidden={floatingSidebarHidden ?? true}
|
||||
onFloatingHiddenChange={setFloatingSidebarHidden}
|
||||
onFloatingChange={setFloating}
|
||||
sidebar={
|
||||
floating ? (
|
||||
<div
|
||||
className={classNames(
|
||||
'x-theme-sidebar',
|
||||
'h-full bg-surface border-r border-border-subtle',
|
||||
'grid grid-rows-[auto_1fr]',
|
||||
)}
|
||||
>
|
||||
<HeaderSize
|
||||
hideControls
|
||||
size="lg"
|
||||
className="border-transparent flex items-center pl-1"
|
||||
osType={os}
|
||||
hideWindowControls={false}
|
||||
useNativeTitlebar={false}
|
||||
interfaceScale={1}
|
||||
>
|
||||
<IconButton
|
||||
size="sm"
|
||||
title="Toggle sidebar"
|
||||
icon="left_panel_visible"
|
||||
iconColor="secondary"
|
||||
onClick={() => setFloatingSidebarHidden(true)}
|
||||
/>
|
||||
</HeaderSize>
|
||||
<Sidebar />
|
||||
</div>
|
||||
) : (
|
||||
<Sidebar />
|
||||
)
|
||||
}
|
||||
>
|
||||
<ExchangesTable exchanges={exchanges} className="overflow-auto h-full" />
|
||||
</SidebarLayout>
|
||||
|
||||
Reference in New Issue
Block a user