1
- import { AnimatePresence } from "framer-motion"
1
+ import { useWheel } from "@use-gesture/react"
2
+ import { AnimatePresence , easeOut } from "framer-motion"
3
+ import { useRef } from "react"
4
+ import { useHotkeys } from "react-hotkeys-hook"
2
5
import { useParams } from "react-router-dom"
3
6
4
7
import { useUISettingKey } from "~/atoms/settings/ui"
5
8
import { useFeedColumnShow , useFeedColumnTempShow } from "~/atoms/sidebar"
6
9
import { m } from "~/components/common/Motion"
7
10
import { ActionButton } from "~/components/ui/button"
8
- import { ROUTE_ENTRY_PENDING , views } from "~/constants"
11
+ import { HotKeyScopeMap , ROUTE_ENTRY_PENDING , views } from "~/constants"
9
12
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
10
13
import { useRouteView } from "~/hooks/biz/useRouteParams"
11
14
import { cn } from "~/lib/utils"
@@ -19,22 +22,52 @@ export const Component = () => {
19
22
20
23
const settingWideMode = useUISettingKey ( "wideMode" )
21
24
const realEntryId = entryId === ROUTE_ENTRY_PENDING ? "" : entryId
22
- const disable = views [ view ] . wideMode || ( settingWideMode && ! realEntryId )
25
+ const inEntryContentWideMode = ! ( views [ view ] . wideMode || ( settingWideMode && ! realEntryId ) )
23
26
const wideMode = settingWideMode && realEntryId
24
27
const feedColumnTempShow = useFeedColumnTempShow ( )
25
28
const feedColumnShow = useFeedColumnShow ( )
26
29
const shouldHeaderPaddingLeft = feedColumnTempShow && ! feedColumnShow && settingWideMode
27
30
31
+ useHotkeys (
32
+ "Escape" ,
33
+ ( ) => {
34
+ if ( inEntryContentWideMode ) {
35
+ navigate ( { entryId : null } )
36
+ }
37
+ } ,
38
+ {
39
+ enabled : inEntryContentWideMode ,
40
+ scopes : HotKeyScopeMap . Home ,
41
+ preventDefault : true ,
42
+ } ,
43
+ )
44
+ const carouselRef = useRef < HTMLDivElement > ( null )
45
+
46
+ useWheel (
47
+ ( { delta : [ dex ] } ) => {
48
+ if ( dex < - 50 ) {
49
+ navigate ( { entryId : null } )
50
+ }
51
+ } ,
52
+ {
53
+ enabled : inEntryContentWideMode ,
54
+ target : carouselRef ,
55
+ eventOptions : { capture : true } ,
56
+ axis : "x" ,
57
+ } ,
58
+ )
59
+
28
60
return (
29
61
< AnimatePresence >
30
62
< AppLayoutGridContainerProvider >
31
63
< AnimatePresence >
32
- { ! disable && (
64
+ { inEntryContentWideMode && (
33
65
< m . div
66
+ ref = { carouselRef }
34
67
// slide up
35
68
initial = { { opacity : 0 , y : 100 } }
36
69
animate = { { opacity : 1 , y : 0 } }
37
- exit = { { opacity : 0 , y : 100 } }
70
+ exit = { { opacity : 0 , y : 100 , transition : { duration : 0.2 , ease : easeOut } } }
38
71
transition = { { duration : 0.2 , type : "spring" } }
39
72
className = { cn (
40
73
"flex min-w-0 flex-1 flex-col" ,
@@ -54,12 +87,13 @@ export const Component = () => {
54
87
< i className = "i-mgc-close-cute-re size-5" />
55
88
</ ActionButton >
56
89
) }
90
+
57
91
< EntryContent
58
92
entryId = { realEntryId }
59
93
classNames = { {
60
94
header : shouldHeaderPaddingLeft
61
- ? "ml-[calc(theme(width.feed-col)+theme(width.12 ))]"
62
- : "ml-12 " ,
95
+ ? "ml-[calc(theme(width.feed-col)+theme(width.8 ))]"
96
+ : "ml-8 " ,
63
97
} }
64
98
/>
65
99
</ m . div >
0 commit comments