fix(entry-content): escape key to back to entry list in zen mode
- Refactored featureConfigMap to utilize TypeScript's `satisfies` operator for improved type safety. - Added a focusable reference in EntryContent to manage focus behavior during animations. - Integrated hotkey handling in EntryScrollingAndNavigationHandler to improve navigation experience based on AI feature status and Zen mode. These changes collectively enhance the code structure and user interaction within the entry content components, providing a more responsive and intuitive experience. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -3,10 +3,9 @@ import type { FC } from "react"
|
||||
|
||||
import { useFeature } from "~/hooks/biz/useFeature"
|
||||
|
||||
export const featureConfigMap: Record<string, keyof ExtractResponseData<GetStatusConfigsResponse>> =
|
||||
{
|
||||
ai: "AI_CHAT_ENABLED",
|
||||
}
|
||||
export const featureConfigMap = {
|
||||
ai: "AI_CHAT_ENABLED",
|
||||
} satisfies Record<string, keyof ExtractResponseData<GetStatusConfigsResponse>>
|
||||
|
||||
export const withFeature =
|
||||
(feature: keyof typeof featureConfigMap) =>
|
||||
|
||||
+3
@@ -97,9 +97,11 @@ const EntryContentImpl: Component<EntryContentProps> = ({
|
||||
}, [addOrUpdateBlock, entryId, removeBlock])
|
||||
const animationController = useAnimationControls()
|
||||
|
||||
const focusableRef = useRef<HTMLDivElement>(null)
|
||||
useEffect(() => {
|
||||
animationController.set(contentVariants.exit)
|
||||
animationController.start(contentVariants.animate)
|
||||
focusableRef.current?.focus()
|
||||
return () => {
|
||||
animationController.stop()
|
||||
}
|
||||
@@ -116,6 +118,7 @@ const EntryContentImpl: Component<EntryContentProps> = ({
|
||||
<div className="w-full" ref={setPanelPortalElement} />
|
||||
|
||||
<Focusable
|
||||
ref={focusableRef}
|
||||
scope={HotkeyScope.EntryRender}
|
||||
className="@container relative flex min-h-0 w-full flex-1 flex-col overflow-hidden print:size-auto print:overflow-visible"
|
||||
>
|
||||
|
||||
+20
-1
@@ -11,9 +11,13 @@ import type { JSAnimation } from "motion/react"
|
||||
import { AnimatePresence, m } from "motion/react"
|
||||
import * as React from "react"
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
import { useHotkeys } from "react-hotkeys-hook"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
import { useIsZenMode } from "~/atoms/settings/ui"
|
||||
import { FocusablePresets } from "~/components/common/Focusable"
|
||||
import { useFeature } from "~/hooks/biz/useFeature"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { COMMAND_ID } from "~/modules/command/commands/id"
|
||||
import { useCommandBinding } from "~/modules/command/hooks/use-command-binding"
|
||||
import { useCommandHotkey } from "~/modules/command/hooks/use-register-hotkey"
|
||||
@@ -50,12 +54,27 @@ export const EntryScrollingAndNavigationHandler = ({
|
||||
when,
|
||||
})
|
||||
|
||||
const isZenMode = useIsZenMode()
|
||||
// TODO: Here, do not rely on the AI switch, but should be deps on the new layout.
|
||||
const isAiEnabled = useFeature("ai")
|
||||
|
||||
const useBackHandler = isZenMode || isAiEnabled
|
||||
|
||||
useCommandHotkey({
|
||||
commandId: COMMAND_ID.layout.focusToTimeline,
|
||||
when,
|
||||
when: when && !useBackHandler,
|
||||
shortcut: "Backspace, Escape",
|
||||
})
|
||||
|
||||
const navigateToTimeline = useNavigateEntry()
|
||||
useHotkeys(
|
||||
"Escape",
|
||||
() => {
|
||||
navigateToTimeline({ entryId: null })
|
||||
},
|
||||
{ enabled: when && useBackHandler },
|
||||
)
|
||||
|
||||
const { highlightBoundary } = useFocusActions()
|
||||
const smoothScrollTo = useSmoothScroll()
|
||||
const navigateToNext = useEventCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user