Skip to content

Commit

Permalink
feat: nav to special setting tab
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Jun 26, 2024
1 parent a3a472e commit 43e7d12
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/renderer/src/modules/settings/modal/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MotionButtonBase } from "@renderer/components/ui/button"
import { useCurrentModal } from "@renderer/components/ui/modal"
import { ScrollArea } from "@renderer/components/ui/scroll-area"
import { SettingsTitle } from "@renderer/modules/settings/title"
import type { FC } from "react"

import { SettingTabProvider, useSettingTab } from "./context"
import { SettingModalLayout } from "./layout"
Expand All @@ -18,9 +19,13 @@ const pages = (() => {
}
return pages
})()
export const SettingModalContent = () => (
export const SettingModalContent: FC<{
initialTab?: string
}> = ({ initialTab }) => (
<SettingTabProvider>
<SettingModalLayout>
<SettingModalLayout
initialTab={initialTab ? initialTab in pages ? initialTab : undefined : undefined}
>
<ScrollArea.ScrollArea
scrollbarClassName="mt-12 mb-2"
rootClassName="h-full flex-1 shrink-0 overflow-auto pl-8 pr-7"
Expand Down
10 changes: 7 additions & 3 deletions src/renderer/src/modules/settings/modal/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { createElement, useCallback } from "react"

import { SettingModalContent } from "./content"

export const useSettingModal = () => {
export const useSettingModal = (

) => {
const { present } = useModalStack()

return useCallback(() => present({
return useCallback((initialTab?: string) => present({
title: "Setting",
id: "setting",
content: SettingModalContent,
content: () => createElement(SettingModalContent, {
initialTab,
}),
CustomModalComponent: (props) => createElement("div", {
className: "center h-full center",
}, props.children),
Expand Down
23 changes: 19 additions & 4 deletions src/renderer/src/modules/settings/modal/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ import { settings } from "../constants"
import { SettingsSidebarTitle } from "../title"
import { useSetSettingTab, useSettingTab } from "./context"

export function SettingModalLayout(props: PropsWithChildren) {
const { children } = props
export function SettingModalLayout(
props: PropsWithChildren<{
initialTab?: string
}>,
) {
const { children, initialTab } = props
const setTab = useSetSettingTab()
const tab = useSettingTab()

useEffect(() => {
if (!tab) setTab(settings[0].path)
if (!tab) {
if (initialTab) {
setTab(initialTab)
} else {
setTab(settings[0].path)
}
}
}, [])

const { draggable, overlay } = useUIStore(
Expand Down Expand Up @@ -57,7 +67,12 @@ export function SettingModalLayout(props: PropsWithChildren) {
cursor: "grabbing",
}}
>
{draggable && <div className="absolute inset-x-0 top-0 z-[1] h-8" onPointerDown={handleDrag} />}
{draggable && (
<div
className="absolute inset-x-0 top-0 z-[1] h-8"
onPointerDown={handleDrag}
/>
)}
<div className="flex h-0 flex-1 bg-theme-tooltip-background">
<div className="w-44 border-r px-2 py-6">
<div className="mb-4 flex h-8 items-center gap-2 px-4 font-bold">
Expand Down

0 comments on commit 43e7d12

Please sign in to comment.