feat: Panel Splitter

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-07-22 15:07:24 +08:00
parent bf9425e739
commit 215563d07e
8 changed files with 64 additions and 17 deletions
+7 -1
View File
@@ -74,9 +74,15 @@ const AppLayer = () => {
const AppSkeleton = () => {
const entryColWidth = useUISettingKey("entryColWidth")
const feedColWidth = useUISettingKey("feedColWidth")
return (
<div className="flex size-full">
<div className="h-full w-64 shrink-0" />
<div
className="h-full shrink-0"
style={{
width: `${feedColWidth}px`,
}}
/>
<div className="relative size-full grow bg-theme-background">
<div
className="absolute inset-y-0 w-px bg-border"
+2
View File
@@ -3,6 +3,8 @@ import { createSettingAtom } from "./helper"
const createDefaultSettings = () => ({
// Sidebar
entryColWidth: 340,
feedColWidth: 256,
opaqueSidebar: false,
sidebarShowUnreadCount: true,
@@ -0,0 +1,15 @@
import * as React from "react"
export const PanelSplitter = (
props: React.DetailedHTMLProps<
React.HTMLAttributes<HTMLDivElement>,
HTMLDivElement
>,
) => (
<div className="relative h-full w-0 shrink-0">
<div
{...props}
className="absolute inset-0 z-[9] w-[2px] -translate-x-1/2 cursor-ew-resize bg-transparent hover:bg-gray-400 hover:dark:bg-neutral-500"
/>
</div>
)
@@ -1 +1,2 @@
export * from "./Divider"
export * from "./PanelSpliter"
@@ -47,9 +47,6 @@ function EntryContentRender({ entryId }: { entryId: string }) {
const { error, data } = useAuthQuery(Queries.entries.byId(entryId), {
staleTime: 300_000,
meta: {
persist: true,
},
})
const entry = useEntry(entryId)
@@ -235,7 +235,7 @@ export function FeedColumn({ children }: PropsWithChildren) {
{views.map((item, index) => (
<section
key={item.name}
className="h-full w-64 shrink-0 snap-center pb-8"
className="h-full w-[var(--fo-feed-col-w)] shrink-0 snap-center pb-8"
>
{active === index && (
<FeedList
@@ -1,4 +1,5 @@
import { getUISettings, setUISetting } from "@renderer/atoms/settings/ui"
import { PanelSplitter } from "@renderer/components/ui/divider"
import { views } from "@renderer/constants"
import { useRouteParms } from "@renderer/hooks/biz/useRouteParams"
import { cn } from "@renderer/lib/utils"
@@ -38,16 +39,9 @@ export function Component() {
width: position,
}}
>
<EntryColumn
key={`${feedId}-${view}`}
/>
<EntryColumn key={`${feedId}-${view}`} />
</div>
{!inWideMode && (
<div
{...separatorProps}
className="h-full w-px shrink-0 cursor-ew-resize hover:bg-border"
/>
)}
{!inWideMode && <PanelSplitter {...separatorProps} />}
<Outlet />
</div>
)
+35 -3
View File
@@ -1,5 +1,7 @@
import { setMainContainerElement } from "@renderer/atoms/dom"
import { getUISettings, setUISetting } from "@renderer/atoms/settings/ui"
import { useLoginModalShow, useMe } from "@renderer/atoms/user"
import { PanelSplitter } from "@renderer/components/ui/divider"
import { DeclarativeModal } from "@renderer/components/ui/modal/stacked/declarative-modal"
import { NoopChildren } from "@renderer/components/ui/modal/stacked/utils"
import { RootPortal } from "@renderer/components/ui/portal"
@@ -10,15 +12,40 @@ import { LoginModalContent } from "@renderer/modules/auth/LoginModalContent"
import { FeedColumn } from "@renderer/modules/feed-column"
import { AutoUpdater } from "@renderer/modules/feed-column/auto-updater"
import { SearchCmdK } from "@renderer/modules/search/cmdk"
import { useRef } from "react"
import { useResizable } from "react-resizable-layout"
import { Outlet } from "react-router-dom"
export function Component() {
const isAuthFail = useLoginModalShow()
const user = useMe()
const containerRef = useRef<HTMLDivElement>(null)
const { position, separatorProps } = useResizable({
axis: "x",
min: 256,
max: 300,
initial: getUISettings().feedColWidth,
containerRef,
onResizeEnd({ position }) {
setUISetting("feedColWidth", position)
},
})
return (
<div className="flex h-full" onContextMenu={preventDefault}>
<div className="w-64 shrink-0 border-r">
<div
className="flex h-full"
ref={containerRef}
onContextMenu={preventDefault}
>
<div
className="shrink-0 border-r"
style={{
"width": `${position}px`,
// @ts-expect-error
"--fo-feed-col-w": `${position}px`,
}}
>
<FeedColumn>
{APP_VERSION?.[0] === "0" && (
<div className="pointer-events-none absolute bottom-3 w-full text-center text-xs opacity-20">
@@ -36,6 +63,8 @@ export function Component() {
</FeedColumn>
</div>
{/* NOTE: tabIndex for main element can get by `document.activeElement` */}
<PanelSplitter {...separatorProps} />
<main
ref={setMainContainerElement}
className="flex min-w-0 flex-1 bg-theme-background !outline-none"
@@ -55,7 +84,10 @@ export function Component() {
canClose={false}
clickOutsideToDismiss={false}
>
<LoginModalContent canClose={false} runtime={window.electron ? "app" : "browser"} />
<LoginModalContent
canClose={false}
runtime={window.electron ? "app" : "browser"}
/>
</DeclarativeModal>
</RootPortal>
)}